Merge pull request #145 from prometheus/julius-fix-per-second-rate

Fix rate() per-second adjustment.
This commit is contained in:
juliusv 2013-04-15 06:49:40 -07:00
commit 888b64c781
2 changed files with 8 additions and 2 deletions

View file

@ -137,8 +137,8 @@ func rateImpl(timestamp time.Time, view *viewAdapter, args []Node) interface{} {
// MatrixLiteral exists). Find a better way of getting the duration of a
// matrix, such as looking at the samples themselves.
interval := args[0].(*MatrixLiteral).interval
for _, sample := range vector {
sample.Value /= model.SampleValue(interval / time.Second)
for i, _ := range vector {
vector[i].Value /= model.SampleValue(interval / time.Second)
}
return vector
}

View file

@ -232,6 +232,12 @@ var expressionTests = []struct {
output: []string{"http_requests{group='canary',instance='1',job='app-server'} => 288 @[%v]"},
fullRanges: 1,
intervalRanges: 0,
}, {
// Rates should transform per-interval deltas to per-second rates.
expr: "rate(http_requests{group='canary',instance='1',job='app-server'}[10m])",
output: []string{"http_requests{group='canary',instance='1',job='app-server'} => 0.26666668 @[%v]"},
fullRanges: 1,
intervalRanges: 0,
}, {
// Empty expressions shouldn't parse.
expr: "",