From 1cff4f3d912d86e5f17cadd2405754b0f5849c05 Mon Sep 17 00:00:00 2001 From: Julius Volz Date: Mon, 15 Apr 2013 14:39:05 +0200 Subject: [PATCH] Fix rate() per-second adjustment. This got broken during the depointerization of the Vector type. --- rules/ast/functions.go | 4 ++-- rules/rules_test.go | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/rules/ast/functions.go b/rules/ast/functions.go index 7f90d17c04..6276f44296 100644 --- a/rules/ast/functions.go +++ b/rules/ast/functions.go @@ -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 } diff --git a/rules/rules_test.go b/rules/rules_test.go index 5caeaf47b1..78431cbc72 100644 --- a/rules/rules_test.go +++ b/rules/rules_test.go @@ -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: "",