Skip to content

Commit

Permalink
Query Frontend: Update Server-Timing format (#9985)
Browse files Browse the repository at this point in the history
* Update Server-Timing format

* Update CHANGELOG.md

* Update CHANGELOG.md

* Update CHANGELOG.md

* Update CHANGELOG.md

* Update CHANGELOG.md

* Update CHANGELOG.md

Co-authored-by: Dimitar Dimitrov <[email protected]>

---------

Co-authored-by: Dimitar Dimitrov <[email protected]>
  • Loading branch information
tinitiuset and dimitarvdimitrov authored Nov 25, 2024
1 parent ec953e7 commit 2edcccd
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
* [FEATURE] Ruler: Add experimental support for caching the contents of rule groups. This is disabled by default and can be enabled by setting `-ruler-storage.cache.rule-group-enabled`. #9595
* [FEATURE] PromQL: Add experimental `info` function. Experimental functions are disabled by default, but can be enabled setting `-querier.promql-experimental-functions-enabled=true` in the query-frontend and querier. #9879
* [FEATURE] Distributor: Support promotion of OTel resource attributes to labels. #8271
* [ENHANCEMENT] Query Frontend: Return server-side `bytes_processed` statistics following Server-Timing format. #9645 #9985
* [ENHANCEMENT] mimirtool: Adds bearer token support for mimirtool's analyze ruler/prometheus commands. #9587
* [ENHANCEMENT] Ruler: Support `exclude_alerts` parameter in `<prometheus-http-prefix>/api/v1/rules` endpoint. #9300
* [ENHANCEMENT] Distributor: add a metric to track tenants who are sending newlines in their label values called `cortex_distributor_label_values_with_newlines_total`. #9400
Expand All @@ -53,7 +54,6 @@
* `-memberlist.max-concurrent-writes`
* `-memberlist.acquire-writer-timeout`
* [ENHANCEMENT] memberlist: Notifications can now be processed once per interval specified by `-memberlist.notify-interval` to reduce notify storm CPU activity in large clusters. #9594
* [ENHANCEMENT] Return server-side total bytes processed statistics as a header through query frontend. #9645
* [ENHANCEMENT] Query-scheduler: Remove the experimental `query-scheduler.prioritize-query-components` flag. Request queues always prioritize query component dequeuing above tenant fairness. #9703
* [ENHANCEMENT] Ingester: Emit traces for block syncing, to join up block-upload traces. #9656
* [ENHANCEMENT] Querier: Enable the optional querying of additional storage queryables. #9712
Expand Down
2 changes: 1 addition & 1 deletion integration/query_frontend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ func runQueryFrontendTest(t *testing.T, cfg queryFrontendTestConfig) {
if userID == 0 && cfg.queryStatsEnabled {
res, _, err := c.QueryRaw("{instance=~\"hello.*\"}")
require.NoError(t, err)
require.Regexp(t, "querier_wall_time;dur=[0-9.]*, response_time;dur=[0-9.]*, bytes_processed=[0-9.]*$", res.Header.Values("Server-Timing")[0])
require.Regexp(t, "querier_wall_time;dur=[0-9.]*, response_time;dur=[0-9.]*, bytes_processed;val=[0-9.]*$", res.Header.Values("Server-Timing")[0])
}

// Beyond the range of -querier.query-ingesters-within should return nothing. No need to repeat it for each user.
Expand Down
19 changes: 11 additions & 8 deletions pkg/frontend/transport/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,18 +484,21 @@ func writeServiceTimingHeader(queryResponseTime time.Duration, headers http.Head
parts := make([]string, 0)
parts = append(parts, statsValue("querier_wall_time", stats.LoadWallTime()))
parts = append(parts, statsValue("response_time", queryResponseTime))
parts = append(parts, statsBytesProcessedValue("bytes_processed", stats.LoadFetchedChunkBytes()+stats.LoadFetchedIndexBytes()))
parts = append(parts, statsValue("bytes_processed", stats.LoadFetchedChunkBytes()+stats.LoadFetchedIndexBytes()))
headers.Set(ServiceTimingHeaderName, strings.Join(parts, ", "))
}
}

func statsValue(name string, d time.Duration) string {
durationInMs := strconv.FormatFloat(float64(d)/float64(time.Millisecond), 'f', -1, 64)
return name + ";dur=" + durationInMs
}

func statsBytesProcessedValue(name string, value uint64) string {
return name + "=" + strconv.FormatUint(value, 10)
func statsValue(name string, val interface{}) string {
switch v := val.(type) {
case time.Duration:
durationInMs := strconv.FormatFloat(float64(v)/float64(time.Millisecond), 'f', -1, 64)
return name + ";dur=" + durationInMs
case uint64:
return name + ";val=" + strconv.FormatUint(v, 10)
default:
return name + ";val=" + fmt.Sprintf("%v", v)
}
}

func httpRequestActivity(request *http.Request, userAgent string, requestParams url.Values) string {
Expand Down
2 changes: 1 addition & 1 deletion pkg/frontend/transport/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ func TestHandler_ServeHTTP(t *testing.T) {
expectedActivity: "user:12345 UA: req:POST /api/v1/query query=some_metric&time=42",
expectedReadConsistency: "",
assertHeaders: func(t *testing.T, headers http.Header) {
assert.Contains(t, headers.Get(ServiceTimingHeaderName), "bytes_processed=0")
assert.Contains(t, headers.Get(ServiceTimingHeaderName), "bytes_processed;val=0")
},
},
} {
Expand Down

0 comments on commit 2edcccd

Please sign in to comment.