Nonexistent labels in BY-clauses shouldn't propagate to result.

This fixes bug 2. of https://github.com/prometheus/prometheus/issues/374

Change-Id: Ia4a13153616bafce5bf10597966b071434422d09
This commit is contained in:
Julius Volz 2014-01-24 16:05:30 +01:00
parent c342ad33a0
commit 0378c2ca1f
3 changed files with 13 additions and 2 deletions

View file

@ -41,7 +41,7 @@ var (
BucketBuilder: prometheus.AccumulatingBucketBuilder(prometheus.EvictAndReplaceWith(10, prometheus.AverageReducer), 100),
ReportablePercentiles: []float64{0.01, 0.05, 0.5, 0.90, 0.99}})
targetOperations = prometheus.NewCounter()
targetOperations = prometheus.NewCounter()
dnsSDLookupsCount = prometheus.NewCounter()
)

View file

@ -398,7 +398,9 @@ func (node *VectorAggregation) Eval(timestamp clientmodel.Timestamp, view *viewA
} else {
m[clientmodel.MetricNameLabel] = sample.Metric[clientmodel.MetricNameLabel]
for _, l := range node.groupBy {
m[l] = sample.Metric[l]
if v, ok := sample.Metric[l]; ok {
m[l] = v
}
}
}
result[groupingKey] = &groupedAggregation{

View file

@ -139,6 +139,15 @@ func TestExpressions(t *testing.T) {
},
fullRanges: 0,
intervalRanges: 8,
}, {
// Non-existent labels mentioned in BY-clauses shouldn't propagate to output.
expr: `SUM(http_requests) BY (job, nonexistent)`,
output: []string{
`http_requests{job="api-server"} => 1000 @[%v]`,
`http_requests{job="app-server"} => 2600 @[%v]`,
},
fullRanges: 0,
intervalRanges: 8,
}, {
expr: `
// Test comment.