Skip to content

Commit

Permalink
Add querier metrics for requests executed (#3524)
Browse files Browse the repository at this point in the history
* Add metrics for concurrency and querier requests executed

* update changelog

* turn metric into log line

* update
  • Loading branch information
electron0zero authored Mar 27, 2024
1 parent 56eb0cb commit 6cafca9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## main / unreleased

* [ENHANCEMENT] Add querier metrics for requests executed [#3524](https://github.com/grafana/tempo/pull/3524) (@electron0zero)
* [FEATURE] Added gRPC streaming endpoints for all tag queries. [#3460](https://github.com/grafana/tempo/pull/3460) (@joe-elliott)
* [CHANGE] Align metrics query time ranges to the step parameter [#3490](https://github.com/grafana/tempo/pull/3490) (@mdisibio)
* [ENHANCEMENT] Add string interning to TraceQL queries [#3411](https://github.com/grafana/tempo/pull/3411) (@mapno)
Expand Down
10 changes: 10 additions & 0 deletions modules/querier/worker/frontend_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
"github.com/grafana/dskit/httpgrpc"
"github.com/grafana/tempo/pkg/util/httpgrpcutil"
"github.com/opentracing/opentracing-go"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
Expand All @@ -27,6 +29,12 @@ var processorBackoffConfig = backoff.Config{
MaxBackoff: 1 * time.Second,
}

var metricWorkerRequests = promauto.NewCounter(prometheus.CounterOpts{
Namespace: "tempo",
Name: "querier_worker_request_executed_total",
Help: "The total number of requests executed by the querier worker.",
})

func newFrontendProcessor(cfg Config, handler RequestHandler, log log.Logger) processor {
return &frontendProcessor{
log: log,
Expand Down Expand Up @@ -185,6 +193,8 @@ func (fp *frontendProcessor) runRequest(ctx context.Context, request *httpgrpc.H
level.Error(fp.log).Log("msg", "error processing query", "err", errMsg)
}

metricWorkerRequests.Inc()

return response
}

Expand Down
7 changes: 7 additions & 0 deletions modules/querier/worker/frontend_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/go-kit/log"
"github.com/grafana/dskit/grpcclient"
"github.com/grafana/dskit/httpgrpc"
dto "github.com/prometheus/client_model/go"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -46,6 +47,12 @@ func TestRunRequests(t *testing.T) {
for i, resp := range resps {
require.Equal(t, []byte{byte(i)}, resp.Body)
}

// check that counter metric is working
m := &dto.Metric{}
err := metricWorkerRequests.Write(m)
require.NoError(t, err)
require.Equal(t, float64(totalRequests), m.Counter.GetValue())
}

func TestHandleSendError(t *testing.T) {
Expand Down
2 changes: 2 additions & 0 deletions modules/querier/worker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ func (w *querierWorker) resetConcurrency() {
if totalConcurrency > w.cfg.MaxConcurrentRequests {
level.Warn(w.log).Log("msg", "total worker concurrency is greater than promql max concurrency. Queries may be queued in the querier which reduces QOS")
}

level.Info(w.log).Log("msg", "total worker concurrency updated", "totalConcurrency", totalConcurrency)
}

func (w *querierWorker) connect(ctx context.Context, address string) (*grpc.ClientConn, error) {
Expand Down

0 comments on commit 6cafca9

Please sign in to comment.