Skip to content

Commit e74c604

Browse files
authored
Collect store gateway postings touched count and bytes in querier stats (#5892)
* update stats Signed-off-by: Ben Ye <[email protected]> * update stats Signed-off-by: Ben Ye <[email protected]> * collect store gateway postings touched count and bytes in querier stats Signed-off-by: Ben Ye <[email protected]> * changelog Signed-off-by: Ben Ye <[email protected]> --------- Signed-off-by: Ben Ye <[email protected]>
1 parent e2b8851 commit e74c604

File tree

8 files changed

+230
-33
lines changed

8 files changed

+230
-33
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
## master / unreleased
44
* [CHANGE] Ruler: Remove `experimental.ruler.api-enable-rules-backup` flag and use `ruler.ring.replication-factor` to check if rules backup is enabled
55

6+
* [ENHANCEMENT] Query Frontend/Querier: Added store gateway postings touched count and touched size in Querier stats and log in Query Frontend. #5892
7+
68
## 1.17.0 in progress
79

810
* [CHANGE] Azure Storage: Upgraded objstore dependency and support Azure Workload Identity Authentication. Added `connection_string` to support authenticating via SAS token. Marked `msi_resource` config as deprecating. #5645

pkg/frontend/transport/handler.go

+7
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,8 @@ func (f *Handler) reportQueryStats(r *http.Request, userID string, queryString u
296296
numSamples := stats.LoadFetchedSamples()
297297
numChunkBytes := stats.LoadFetchedChunkBytes()
298298
numDataBytes := stats.LoadFetchedDataBytes()
299+
numStoreGatewayTouchedPostings := stats.LoadStoreGatewayTouchedPostings()
300+
numStoreGatewayTouchedPostingBytes := stats.LoadStoreGatewayTouchedPostingBytes()
299301
splitQueries := stats.LoadSplitQueries()
300302
dataSelectMaxTime := stats.LoadDataSelectMaxTime()
301303
dataSelectMinTime := stats.LoadDataSelectMinTime()
@@ -334,6 +336,11 @@ func (f *Handler) reportQueryStats(r *http.Request, userID string, queryString u
334336
"response_size", contentLength,
335337
}, stats.LoadExtraFields()...)
336338

339+
if numStoreGatewayTouchedPostings > 0 {
340+
logMessage = append(logMessage, "store_gateway_touched_postings_count", numStoreGatewayTouchedPostings)
341+
logMessage = append(logMessage, "store_gateway_touched_posting_bytes", numStoreGatewayTouchedPostingBytes)
342+
}
343+
337344
grafanaFields := formatGrafanaStatsFields(r)
338345
if len(grafanaFields) > 0 {
339346
logMessage = append(logMessage, grafanaFields...)

pkg/frontend/transport/handler_test.go

+17
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,23 @@ func TestReportQueryStatsFormat(t *testing.T) {
471471
},
472472
expectedLog: `level=info msg="query stats" component=query-frontend method=GET path=/prometheus/api/v1/query response_time=1s query_wall_time_seconds=0 fetched_series_count=0 fetched_chunks_count=0 fetched_samples_count=0 fetched_chunks_bytes=0 fetched_data_bytes=0 split_queries=0 status_code=200 response_size=1000 data_select_max_time=1704153600 data_select_min_time=1704067200 query_length=2 param_query=up`,
473473
},
474+
"should include query stats with store gateway stats": {
475+
queryStats: &querier_stats.QueryStats{
476+
Stats: querier_stats.Stats{
477+
WallTime: 3 * time.Second,
478+
QueryStorageWallTime: 100 * time.Minute,
479+
FetchedSeriesCount: 100,
480+
FetchedChunksCount: 200,
481+
FetchedSamplesCount: 300,
482+
FetchedChunkBytes: 1024,
483+
FetchedDataBytes: 2048,
484+
SplitQueries: 10,
485+
StoreGatewayTouchedPostingsCount: 20,
486+
StoreGatewayTouchedPostingBytes: 200,
487+
},
488+
},
489+
expectedLog: `level=info msg="query stats" component=query-frontend method=GET path=/prometheus/api/v1/query response_time=1s query_wall_time_seconds=3 fetched_series_count=100 fetched_chunks_count=200 fetched_samples_count=300 fetched_chunks_bytes=1024 fetched_data_bytes=2048 split_queries=10 status_code=200 response_size=1000 store_gateway_touched_postings_count=20 store_gateway_touched_posting_bytes=200 query_storage_wall_time_seconds=6000`,
490+
},
474491
}
475492

476493
for testName, testData := range tests {

pkg/querier/blocks_store_queryable.go

+2
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,8 @@ func (q *blocksStoreQuerier) fetchSeriesFromStores(
756756
reqStats.AddFetchedSamples(numSamples)
757757
reqStats.AddFetchedChunkBytes(uint64(chunkBytes))
758758
reqStats.AddFetchedDataBytes(uint64(dataBytes))
759+
reqStats.AddStoreGatewayTouchedPostings(uint64(seriesQueryStats.PostingsTouched))
760+
reqStats.AddStoreGatewayTouchedPostingBytes(uint64(seriesQueryStats.PostingsTouchedSizeSum))
759761

760762
level.Debug(spanLog).Log("msg", "received series from store-gateway",
761763
"instance", c.RemoteAddress(),

pkg/querier/stats/stats.go

+34
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,38 @@ func (s *QueryStats) LoadDataSelectMinTime() int64 {
270270
return atomic.LoadInt64(&s.DataSelectMinTime)
271271
}
272272

273+
func (s *QueryStats) AddStoreGatewayTouchedPostings(count uint64) {
274+
if s == nil {
275+
return
276+
}
277+
278+
atomic.AddUint64(&s.StoreGatewayTouchedPostingsCount, count)
279+
}
280+
281+
func (s *QueryStats) LoadStoreGatewayTouchedPostings() uint64 {
282+
if s == nil {
283+
return 0
284+
}
285+
286+
return atomic.LoadUint64(&s.StoreGatewayTouchedPostingsCount)
287+
}
288+
289+
func (s *QueryStats) AddStoreGatewayTouchedPostingBytes(bytes uint64) {
290+
if s == nil {
291+
return
292+
}
293+
294+
atomic.AddUint64(&s.StoreGatewayTouchedPostingBytes, bytes)
295+
}
296+
297+
func (s *QueryStats) LoadStoreGatewayTouchedPostingBytes() uint64 {
298+
if s == nil {
299+
return 0
300+
}
301+
302+
return atomic.LoadUint64(&s.StoreGatewayTouchedPostingBytes)
303+
}
304+
273305
// Merge the provided Stats into this one.
274306
func (s *QueryStats) Merge(other *QueryStats) {
275307
if s == nil || other == nil {
@@ -283,6 +315,8 @@ func (s *QueryStats) Merge(other *QueryStats) {
283315
s.AddFetchedDataBytes(other.LoadFetchedDataBytes())
284316
s.AddFetchedSamples(other.LoadFetchedSamples())
285317
s.AddFetchedChunks(other.LoadFetchedChunks())
318+
s.AddStoreGatewayTouchedPostings(other.LoadStoreGatewayTouchedPostings())
319+
s.AddStoreGatewayTouchedPostingBytes(other.LoadStoreGatewayTouchedPostingBytes())
286320
s.AddExtraFields(other.LoadExtraFields()...)
287321
}
288322

pkg/querier/stats/stats.pb.go

+120-33
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/querier/stats/stats.proto

+6
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,10 @@ message Stats {
3333
uint64 split_queries = 9;
3434
// The sum of wall time spent in the querier to fetch and merge data from storage.
3535
google.protobuf.Duration query_storage_wall_time = 10 [(gogoproto.stdduration) = true, (gogoproto.nullable) = false];
36+
// The total number of postings touched in store gateway for a specific query.
37+
// Only successful requests from querier to store gateway are included.
38+
uint64 store_gateway_touched_postings_count = 11;
39+
// The total size of postings touched in store gateway for a specific query, in bytes.
40+
// Only successful requests from querier to store gateway are included.
41+
uint64 store_gateway_touched_posting_bytes = 12;
3642
}

0 commit comments

Comments
 (0)