Skip to content

Commit

Permalink
allocate label set counter only if there are matching limtis for the …
Browse files Browse the repository at this point in the history
…series

Signed-off-by: Ben Ye <[email protected]>
  • Loading branch information
yeya24 committed Dec 19, 2024
1 parent 0cdf9e4 commit a51c643
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pkg/distributor/distributor.go
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,7 @@ func (d *Distributor) prepareSeriesKeys(ctx context.Context, req *cortexpb.Write
validatedExemplars := 0
limitsPerLabelSet := d.limits.LimitsPerLabelSet(userID)

labelSetCounters := make(map[uint64]*samplesLabelSetEntry)
var labelSetCounters map[uint64]*samplesLabelSetEntry
var firstPartialErr error

latestSampleTimestampMs := int64(0)
Expand Down Expand Up @@ -1043,7 +1043,11 @@ func (d *Distributor) prepareSeriesKeys(ctx context.Context, req *cortexpb.Write
continue
}

for _, l := range validation.LimitsPerLabelSetsForSeries(limitsPerLabelSet, cortexpb.FromLabelAdaptersToLabels(validatedSeries.Labels)) {
matchedLabelSetLimits := validation.LimitsPerLabelSetsForSeries(limitsPerLabelSet, cortexpb.FromLabelAdaptersToLabels(validatedSeries.Labels))
if len(matchedLabelSetLimits) > 0 {
labelSetCounters = make(map[uint64]*samplesLabelSetEntry, len(matchedLabelSetLimits))
}
for _, l := range matchedLabelSetLimits {
if c, exists := labelSetCounters[l.Hash]; exists {
c.floatSamples += int64(len(ts.Samples))
c.histogramSamples += int64(len(ts.Histograms))
Expand Down

0 comments on commit a51c643

Please sign in to comment.