MCPcopy Create free account
hub / github.com/cortexproject/cortex / LimitsPerLabelSetsForSeries

Function LimitsPerLabelSetsForSeries

pkg/util/validation/limits.go:1242–1274  ·  view source on GitHub ↗

LimitsPerLabelSetsForSeries checks matching labelset limits for the given series.

(limitsPerLabelSets []LimitsPerLabelSet, metric labels.Labels)

Source from the content-addressed store, hash-verified

1240
1241// LimitsPerLabelSetsForSeries checks matching labelset limits for the given series.
1242func LimitsPerLabelSetsForSeries(limitsPerLabelSets []LimitsPerLabelSet, metric labels.Labels) []LimitsPerLabelSet {
1243 // returning early to not have any overhead
1244 if len(limitsPerLabelSets) == 0 {
1245 return nil
1246 }
1247 r := make([]LimitsPerLabelSet, 0, len(limitsPerLabelSets))
1248 defaultPartitionIndex := -1
1249outer:
1250 for i, lbls := range limitsPerLabelSets {
1251 // Default partition exists.
1252 if lbls.LabelSet.Len() == 0 {
1253 defaultPartitionIndex = i
1254 continue
1255 }
1256 found := true
1257 lbls.LabelSet.Range(func(l labels.Label) {
1258 // We did not find some of the labels on the set
1259 if v := metric.Get(l.Name); v != l.Value {
1260 found = false
1261 }
1262 })
1263
1264 if !found {
1265 continue outer
1266 }
1267 r = append(r, lbls)
1268 }
1269 // Use default partition limiter if it is configured and no other matching partitions.
1270 if defaultPartitionIndex != -1 && len(r) == 0 {
1271 r = append(r, limitsPerLabelSets[defaultPartitionIndex])
1272 }
1273 return r
1274}

Calls 2

GetMethod · 0.65
LenMethod · 0.45

Tested by 1