Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose store gateway query stats in series response hints #6352

Merged
merged 8 commits into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re
- [#6273](https://github.com/thanos-io/thanos/pull/6273) Mixin: Allow specifying an instance name filter in dashboards
- [#6163](https://github.com/thanos-io/thanos/pull/6163) Receiver: Add hidden flag `--receive-forward-max-backoff` to configure the max backoff for forwarding requests.
- [#5777](https://github.com/thanos-io/thanos/pull/5777) Receive: Allow specifying tenant-specific external labels in Router Ingestor.
- [#6352](https://github.com/thanos-io/thanos/pull/6352) Store: Expose store gateway query stats in series response hints.

### Fixed

Expand Down
30 changes: 30 additions & 0 deletions pkg/store/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -1224,13 +1224,16 @@ func (s *BucketStore) Series(req *storepb.SeriesRequest, srv storepb.Store_Serie
reqBlockMatchers []*labels.Matcher
chunksLimiter = s.chunksLimiterFactory(s.metrics.queriesDropped.WithLabelValues("chunks"))
seriesLimiter = s.seriesLimiterFactory(s.metrics.queriesDropped.WithLabelValues("series"))

queryStatsEnabled = false
)

if req.Hints != nil {
reqHints := &hintspb.SeriesRequestHints{}
if err := types.UnmarshalAny(req.Hints, reqHints); err != nil {
return status.Error(codes.InvalidArgument, errors.Wrap(err, "unmarshal series request hints").Error())
}
queryStatsEnabled = reqHints.EnableQueryStats

reqBlockMatchers, err = storepb.MatchersToPromMatchers(reqHints.BlockMatchers...)
if err != nil {
Expand Down Expand Up @@ -1421,6 +1424,9 @@ func (s *BucketStore) Series(req *storepb.SeriesRequest, srv storepb.Store_Serie
if s.enableSeriesResponseHints {
var anyHints *types.Any

if queryStatsEnabled {
resHints.QueryStats = stats.toHints()
}
if anyHints, err = types.MarshalAny(resHints); err != nil {
err = status.Error(codes.Unknown, errors.Wrap(err, "marshal series response hints").Error())
return
Expand Down Expand Up @@ -3181,6 +3187,30 @@ func (s queryStats) merge(o *queryStats) *queryStats {
return &s
}

func (s queryStats) toHints() *hintspb.QueryStats {
return &hintspb.QueryStats{
BlocksQueried: int64(s.blocksQueried),
PostingsTouched: int64(s.postingsTouched),
PostingsTouchedSizeSum: int64(s.PostingsTouchedSizeSum),
PostingsToFetch: int64(s.postingsToFetch),
PostingsFetched: int64(s.postingsFetched),
PostingsFetchedSizeSum: int64(s.PostingsFetchedSizeSum),
PostingsFetchCount: int64(s.postingsFetchCount),
SeriesTouched: int64(s.seriesTouched),
SeriesTouchedSizeSum: int64(s.SeriesTouchedSizeSum),
SeriesFetched: int64(s.seriesFetched),
SeriesFetchedSizeSum: int64(s.SeriesFetchedSizeSum),
SeriesFetchCount: int64(s.seriesFetchCount),
ChunksTouched: int64(s.chunksTouched),
ChunksTouchedSizeSum: int64(s.ChunksTouchedSizeSum),
ChunksFetched: int64(s.chunksFetched),
ChunksFetchedSizeSum: int64(s.ChunksFetchedSizeSum),
ChunksFetchCount: int64(s.chunksFetchCount),
MergedSeriesCount: int64(s.mergedSeriesCount),
MergedChunksCount: int64(s.mergedChunksCount),
}
}

// NewDefaultChunkBytesPool returns a chunk bytes pool with default settings.
func NewDefaultChunkBytesPool(maxChunkPoolBytes uint64) (pool.Bytes, error) {
return pool.NewBucketedBytes(chunkBytesPoolMinSize, chunkBytesPoolMaxSize, 2, maxChunkPoolBytes)
Expand Down
53 changes: 51 additions & 2 deletions pkg/store/bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1672,7 +1672,8 @@ func TestSeries_RequestAndResponseHints(t *testing.T) {
},
},
},
}, {
},
{
Name: "querying a range containing multiple blocks should return multiple blocks in the response hints",
Req: &storepb.SeriesRequest{
MinTime: 0,
Expand All @@ -1690,7 +1691,8 @@ func TestSeries_RequestAndResponseHints(t *testing.T) {
},
},
},
}, {
},
{
Name: "querying a range containing multiple blocks but filtering a specific block should query only the requested block",
Req: &storepb.SeriesRequest{
MinTime: 0,
Expand All @@ -1713,6 +1715,53 @@ func TestSeries_RequestAndResponseHints(t *testing.T) {
},
},
},
{
Name: "Query Stats Enabled",
Req: &storepb.SeriesRequest{
MinTime: 0,
MaxTime: 3,
Matchers: []storepb.LabelMatcher{
{Type: storepb.LabelMatcher_EQ, Name: "foo", Value: "bar"},
},
Hints: mustMarshalAny(&hintspb.SeriesRequestHints{
BlockMatchers: []storepb.LabelMatcher{
{Type: storepb.LabelMatcher_EQ, Name: block.BlockIDLabel, Value: block1.String()},
},
EnableQueryStats: true,
}),
},
ExpectedSeries: seriesSet1,
ExpectedHints: []hintspb.SeriesResponseHints{
{
QueriedBlocks: []hintspb.Block{
{Id: block1.String()},
},
QueryStats: &hintspb.QueryStats{
BlocksQueried: 1,
PostingsTouched: 1,
PostingsFetched: 1,
SeriesTouched: 2,
SeriesFetched: 2,
ChunksTouched: 2,
ChunksFetched: 2,
MergedSeriesCount: 2,
MergedChunksCount: 2,
},
},
},
HintsCompareFunc: func(t testutil.TB, expected, actual hintspb.SeriesResponseHints) {
testutil.Equals(t, expected.QueriedBlocks, actual.QueriedBlocks)
testutil.Equals(t, expected.QueryStats.BlocksQueried, actual.QueryStats.BlocksQueried)
testutil.Equals(t, expected.QueryStats.PostingsTouched, actual.QueryStats.PostingsTouched)
testutil.Equals(t, expected.QueryStats.PostingsFetched, actual.QueryStats.PostingsFetched)
testutil.Equals(t, expected.QueryStats.SeriesTouched, actual.QueryStats.SeriesTouched)
testutil.Equals(t, expected.QueryStats.SeriesFetched, actual.QueryStats.SeriesFetched)
testutil.Equals(t, expected.QueryStats.ChunksTouched, actual.QueryStats.ChunksTouched)
testutil.Equals(t, expected.QueryStats.ChunksFetched, actual.QueryStats.ChunksFetched)
testutil.Equals(t, expected.QueryStats.MergedSeriesCount, actual.QueryStats.MergedSeriesCount)
testutil.Equals(t, expected.QueryStats.MergedChunksCount, actual.QueryStats.MergedChunksCount)
},
},
}

storetestutil.TestServerSeries(tb, store, testCases...)
Expand Down
25 changes: 25 additions & 0 deletions pkg/store/hintspb/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,28 @@ func (m *LabelValuesResponseHints) AddQueriedBlock(id ulid.ULID) {
Id: id.String(),
})
}

func (m *QueryStats) Merge(other *QueryStats) {
m.BlocksQueried += other.BlocksQueried
m.MergedSeriesCount += other.MergedSeriesCount
m.MergedChunksCount += other.MergedChunksCount

m.PostingsFetched += other.PostingsFetched
m.PostingsToFetch += other.PostingsToFetch
m.PostingsFetchCount += other.PostingsFetchCount
m.PostingsFetchedSizeSum += other.PostingsFetchedSizeSum
m.PostingsTouched += other.PostingsTouched
m.PostingsTouchedSizeSum += other.PostingsTouchedSizeSum

m.SeriesFetched += other.SeriesFetched
m.SeriesFetchCount += other.SeriesFetchCount
m.SeriesFetchedSizeSum += m.SeriesFetchedSizeSum
m.SeriesTouched += other.SeriesTouched
m.SeriesTouchedSizeSum += other.SeriesTouchedSizeSum

m.ChunksFetched += other.ChunksFetched
m.ChunksFetchCount += other.ChunksFetchCount
m.ChunksFetchedSizeSum += other.ChunksFetchedSizeSum
m.ChunksTouched += other.ChunksTouched
m.ChunksTouchedSizeSum += other.ChunksTouchedSizeSum
}
Loading