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
1 changed files with 11 additions and 8 deletions

View File

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