| 258 | } |
| 259 | |
| 260 | func FromLabelMatchers(cache storecache.MatchersCache, matchers []*LabelMatcher) ([]*labels.Matcher, error) { |
| 261 | result := make([]*labels.Matcher, 0, len(matchers)) |
| 262 | for _, matcher := range matchers { |
| 263 | m, err := cache.GetOrSet(matcher, func() (*labels.Matcher, error) { |
| 264 | var mtype labels.MatchType |
| 265 | switch matcher.Type { |
| 266 | case EQUAL: |
| 267 | mtype = labels.MatchEqual |
| 268 | case NOT_EQUAL: |
| 269 | mtype = labels.MatchNotEqual |
| 270 | case REGEX_MATCH: |
| 271 | mtype = labels.MatchRegexp |
| 272 | case REGEX_NO_MATCH: |
| 273 | mtype = labels.MatchNotRegexp |
| 274 | default: |
| 275 | return nil, fmt.Errorf("invalid matcher type") |
| 276 | } |
| 277 | return labels.NewMatcher(mtype, matcher.GetName(), matcher.GetValue()) |
| 278 | }) |
| 279 | |
| 280 | if err != nil { |
| 281 | return nil, err |
| 282 | } |
| 283 | |
| 284 | result = append(result, m) |
| 285 | } |
| 286 | return result, nil |
| 287 | } |
| 288 | |
| 289 | // FastFingerprint runs the same algorithm as Prometheus labelSetToFastFingerprint() |
| 290 | func FastFingerprint(ls []cortexpb.LabelAdapter) model.Fingerprint { |