Skip to content

Commit

Permalink
remove request duration metrics (#430)
Browse files Browse the repository at this point in the history
  • Loading branch information
p0mvn authored Aug 3, 2024
1 parent 6f3c44b commit 3124134
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 47 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

## Unreleased

- Remove sqs_requests_total and sqs_request_duration_seconds metrics
- Numia Pools APR fetcher, associated configs and wiring
- Timeseries pool fees fetcher, associated configs and wiring

Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,10 @@ test-prices-mainnet:

# Run E2E tests in verbose mode (-s) -n 4 concurrent workers
e2e-run-stage:
SQS_ENVIRONMENTS=stage pytest -s -n 4 --ignore=tests/test_syntheic_geo.py
SQS_ENVIRONMENTS=stage pytest -s -n 4 --ignore=tests/test_synthetic_geo.py

e2e-run-local:
SQS_ENVIRONMENTS=local pytest -s -n 4 --ignore=tests/test_syntheic_geo.py
SQS_ENVIRONMENTS=local pytest -s -n 4 --ignore=tests/test_synthetic_geo.py

#### E2E Python Setup

Expand All @@ -209,7 +209,7 @@ e2e-update-requirements:

# Set DATADOG_API_KEY in the environment
datadog-agent-start:
export DATADOG_API_KEY=your-key; \
export DATADOG_API_KEY=095a7a8c6007d0fa325c3e0b2ee898d4; \
docker run --cgroupns host \
--pid host \
-v /var/run/docker.sock:/var/run/docker.sock:ro \
Expand Down
45 changes: 1 addition & 44 deletions middleware/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package middleware

import (
"bytes"
"context"
"fmt"
"os"
"sync"
Expand All @@ -15,7 +14,6 @@ import (
"github.com/labstack/echo/v4"
"github.com/osmosis-labs/sqs/domain"
"github.com/osmosis-labs/sqs/log"
"github.com/prometheus/client_golang/prometheus"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
)
Expand All @@ -28,34 +26,11 @@ type GoMiddleware struct {
}

var (
// total number of requests counter
requestsTotal = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "sqs_requests_total",
Help: "Total number of requests.",
},
[]string{"method", "endpoint"},
)

// request latency histogram
requestLatency = prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Name: "sqs_request_duration_seconds",
Help: "Histogram of request latencies.",
Buckets: prometheus.DefBuckets,
},
[]string{"method", "endpoint"},
)

// flight recorder
recordFlightOnce sync.Once
)

func init() {
prometheus.MustRegister(requestsTotal)
prometheus.MustRegister(requestLatency)
}

// CORS will handle the CORS middleware
func (m *GoMiddleware) CORS(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
Expand Down Expand Up @@ -90,28 +65,10 @@ func (m *GoMiddleware) InstrumentMiddleware(next echo.HandlerFunc) echo.HandlerF
return func(c echo.Context) error {
start := time.Now()

requestMethod := c.Request().Method
requestPath, err := domain.ParseURLPath(c)
if err != nil {
return err
}

// Increment the request counter
requestsTotal.WithLabelValues(requestMethod, requestPath).Inc()

// Insert the request path into the context
ctx := c.Request().Context()
ctx = context.WithValue(ctx, domain.RequestPathCtxKey, requestPath)
request := c.Request().WithContext(ctx)
c.SetRequest(request)

err = next(c)
err := next(c)

duration := time.Since(start)

// Observe the duration with the histogram
requestLatency.WithLabelValues(requestMethod, requestPath).Observe(duration.Seconds())

// Record outliers to the flight recorder for further analysis
if m.flightRecordConfig.Enabled && duration > time.Duration(m.flightRecordConfig.TraceThresholdMS)*time.Millisecond {
recordFlightOnce.Do(func() {
Expand Down

0 comments on commit 3124134

Please sign in to comment.