Skip to content

Commit

Permalink
Include route name in query stats log lines emitted by query-frontends (
Browse files Browse the repository at this point in the history
#8191)

* Include route name in query stats log lines emitted by query-frontends

* Add changelog entry
  • Loading branch information
charleskorn committed May 28, 2024
1 parent 6cc3c53 commit dc2aedb
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
* [ENHANCEMENT] Distributor: Introduce `-distributor.max-request-pool-buffer-size` to allow configuring the maximum size of the request pool buffers. #8082
* [ENHANCEMENT] Store-gateway: improve performance when streaming chunks to queriers is enabled (`-querier.prefer-streaming-chunks-from-store-gateways=true`) and the query selects fewer than `-blocks-storage.bucket-store.batch-series-size` series (defaults to 5000 series). #8039
* [ENHANCEMENT] Ingester: active series are now updated along with owned series. They decrease when series change ownership between ingesters. This helps provide a more accurate total of active series when ingesters are added. This is only enabled when `-ingester.track-ingester-owned-series` or `-ingester.use-ingester-owned-series-for-limits` are enabled. #8084
* [ENHANCEMENT] Query-frontend: include route name in query stats log lines. #8191
* [BUGFIX] Rules: improve error handling when querier is local to the ruler. #7567
* [BUGFIX] Querier, store-gateway: Protect against panics raised during snappy encoding. #7520
* [BUGFIX] Ingester: Prevent timely compaction of empty blocks. #7624
Expand Down
2 changes: 2 additions & 0 deletions pkg/frontend/transport/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/grafana/dskit/cancellation"
"github.com/grafana/dskit/flagext"
"github.com/grafana/dskit/httpgrpc"
"github.com/grafana/dskit/middleware"
"github.com/grafana/dskit/tenant"
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
Expand Down Expand Up @@ -306,6 +307,7 @@ func (f *Handler) reportQueryStats(
"component", "query-frontend",
"method", r.Method,
"path", r.URL.Path,
"route_name", middleware.ExtractRouteName(r.Context()),
"user_agent", r.UserAgent(),
"status_code", queryResponseStatusCode,
"response_time", queryResponseTime,
Expand Down
5 changes: 5 additions & 0 deletions pkg/frontend/transport/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/go-kit/log/level"
"github.com/grafana/dskit/concurrency"
"github.com/grafana/dskit/httpgrpc"
"github.com/grafana/dskit/middleware"
"github.com/grafana/dskit/test"
"github.com/grafana/dskit/user"
"github.com/pkg/errors"
Expand Down Expand Up @@ -61,6 +62,8 @@ func TestWriteError(t *testing.T) {
}

func TestHandler_ServeHTTP(t *testing.T) {
const testRouteName = "the_test_route"

for _, tt := range []struct {
name string
cfg HandlerConfig
Expand Down Expand Up @@ -182,6 +185,7 @@ func TestHandler_ServeHTTP(t *testing.T) {

req := tt.request()
req = req.WithContext(user.InjectOrgID(req.Context(), "12345"))
req = middleware.WithRouteName(req, testRouteName)
resp := httptest.NewRecorder()

handler.ServeHTTP(resp, req)
Expand Down Expand Up @@ -215,6 +219,7 @@ func TestHandler_ServeHTTP(t *testing.T) {
require.Equal(t, "12345", msg["user"])
require.Equal(t, req.Method, msg["method"])
require.Equal(t, req.URL.Path, msg["path"])
require.Equal(t, testRouteName, msg["route_name"])
require.Equal(t, req.UserAgent(), msg["user_agent"])
require.Contains(t, msg, "response_time")
require.Equal(t, int64(len(responseData)), msg["response_size_bytes"])
Expand Down

0 comments on commit dc2aedb

Please sign in to comment.