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

querier,ingester: support for limit parameter in the finding series endpoint #10620

Merged
merged 7 commits into from
Feb 12, 2025
Merged
Changes from 1 commit
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
Prev Previous commit
distributor: apply requested limit while deduplicating metrics
Signed-off-by: Vladimir Varankin <vladimir.varankin@grafana.com>
  • Loading branch information
narqo committed Feb 12, 2025
commit 9a952b1036ed79c01e1a15d05ca8be0e9252baf2
17 changes: 9 additions & 8 deletions pkg/distributor/distributor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2761,25 +2761,26 @@ func (d *Distributor) MetricsForLabelMatchers(ctx context.Context, from, through
return nil, err
}

metricsLimit := math.MaxInt
if hints != nil && hints.Limit > 0 {
metricsLimit = hints.Limit
}
metrics := map[uint64]labels.Labels{}
respsLoop:
for _, resp := range resps {
ms := ingester_client.FromMetricsForLabelMatchersResponse(resp)
for _, m := range ms {
if len(metrics) >= metricsLimit {
break respsLoop
}
metrics[labels.StableHash(m)] = m
}
}

queryLimiter := mimir_limiter.QueryLimiterFromContextWithFallback(ctx)

resultCap := len(metrics)
if hints != nil && hints.Limit > 0 {
resultCap = min(resultCap, hints.Limit)
}
result := make([]labels.Labels, 0, resultCap)
result := make([]labels.Labels, 0, len(metrics))
for _, m := range metrics {
if len(result) >= resultCap {
break
}
if err := queryLimiter.AddSeries(m); err != nil {
return nil, err
}
Expand Down