LimitsPerLabelSetsForSeries checks matching labelset limits for the given series.
(limitsPerLabelSets []LimitsPerLabelSet, metric labels.Labels)
| 1240 | |
| 1241 | // LimitsPerLabelSetsForSeries checks matching labelset limits for the given series. |
| 1242 | func 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 |
| 1249 | outer: |
| 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 | } |