Add metrics to result after checking all matchers

Should be marginally faster and somewhat more GC friendly
This commit is contained in:
Maxim Ivanov 2016-09-18 11:03:00 +01:00
parent bedc0eda1f
commit c048a0cde8

View file

@ -631,19 +631,22 @@ func (s *MemorySeriesStorage) metricsForLabelMatchers(
} }
result := map[model.Fingerprint]metric.Metric{} result := map[model.Fingerprint]metric.Metric{}
FP_LOOP:
for fp := range remainingFPs { for fp := range remainingFPs {
s.fpLocker.Lock(fp) s.fpLocker.Lock(fp)
if met, _, ok := s.metricForRange(fp, from, through); ok { met, _, ok := s.metricForRange(fp, from, through)
result[fp] = metric.Metric{Metric: met}
}
s.fpLocker.Unlock(fp) s.fpLocker.Unlock(fp)
}
for _, m := range matchers[matcherIdx:] { if !ok {
for fp, met := range result { continue FP_LOOP
if !m.Match(met.Metric[m.Name]) { }
delete(result, fp)
for _, m := range matchers[matcherIdx:] {
if !m.Match(met[m.Name]) {
continue FP_LOOP
} }
} }
result[fp] = metric.Metric{Metric: met}
} }
return result, nil return result, nil
} }