Skip to content

Commit

Permalink
Addressed review feedback
Browse files Browse the repository at this point in the history
Signed-off-by: Marco Pracucci <[email protected]>
  • Loading branch information
pracucci committed Apr 28, 2021
1 parent 6307206 commit a7e3cc8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
10 changes: 5 additions & 5 deletions pkg/distributor/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ func (d *Distributor) queryIngesters(ctx context.Context, replicationSet ring.Re
// queryIngesterStream queries the ingesters using the new streaming API.
func (d *Distributor) queryIngesterStream(ctx context.Context, userID string, replicationSet ring.ReplicationSet, req *ingester_client.QueryRequest) (*ingester_client.QueryStreamResponse, error) {
var (
maxChunksLimit = d.limits.MaxChunksPerQueryFromIngesters(userID)
totChunksCount = atomic.Int32{}
chunksLimit = d.limits.MaxChunksPerQueryFromIngesters(userID)
chunksCount = atomic.Int32{}
)

// Fetch samples from multiple ingesters
Expand Down Expand Up @@ -221,13 +221,13 @@ func (d *Distributor) queryIngesterStream(ctx context.Context, userID string, re
}

// Enforce the max chunks limits.
if maxChunksLimit > 0 {
if totChunks := int(totChunksCount.Add(int32(resp.ChunksCount()))); totChunks > maxChunksLimit {
if chunksLimit > 0 {
if count := int(chunksCount.Add(int32(resp.ChunksCount()))); count > chunksLimit {
// We expect to be always able to convert the label matchers back to Prometheus ones.
// In case we fail (unexpected) the error will not include the matchers, but the core
// logic doesn't break.
matchers, _ := ingester_client.FromLabelMatchers(req.Matchers)
return nil, validation.LimitError(fmt.Sprintf(errMaxChunksPerQueryLimit, util.LabelMatchersToString(matchers), maxChunksLimit))
return nil, validation.LimitError(fmt.Sprintf(errMaxChunksPerQueryLimit, util.LabelMatchersToString(matchers), chunksLimit))
}
}

Expand Down
6 changes: 6 additions & 0 deletions pkg/util/labels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ func TestLabelMatchersToString(t *testing.T) {
labels.MustNewMatcher(labels.MatchNotEqual, "who", "boh"),
},
expected: `{foo="bar",who!="boh"}`,
}, {
input: []*labels.Matcher{
labels.MustNewMatcher(labels.MatchEqual, labels.MetricName, "metric"),
labels.MustNewMatcher(labels.MatchNotEqual, "who", "boh"),
},
expected: `{__name__="metric",who!="boh"}`,
},
}

Expand Down

0 comments on commit a7e3cc8

Please sign in to comment.