From 54eb21b22abb325b91177c53bfd13621e5ab39e0 Mon Sep 17 00:00:00 2001 From: Julius Volz Date: Mon, 28 Jul 2014 18:10:11 +0200 Subject: [PATCH] Fix time() behavior. time() should return the timestamp for which the query is executed, not the actual current time. Change-Id: I430a45cabad7785cd58f95b1028a71dff4c87710 --- rules/ast/functions.go | 2 +- rules/rules_test.go | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/rules/ast/functions.go b/rules/ast/functions.go index a27bc87ce..6a2c3ca5b 100644 --- a/rules/ast/functions.go +++ b/rules/ast/functions.go @@ -75,7 +75,7 @@ func (function *Function) CheckArgTypes(args []Node) error { // === time() clientmodel.SampleValue === func timeImpl(timestamp clientmodel.Timestamp, view *viewAdapter, args []Node) interface{} { - return clientmodel.SampleValue(time.Now().Unix()) + return clientmodel.SampleValue(timestamp.Unix()) } // === delta(matrix MatrixNode, isCounter ScalarNode) Vector === diff --git a/rules/rules_test.go b/rules/rules_test.go index d29a463af..8681499eb 100644 --- a/rules/rules_test.go +++ b/rules/rules_test.go @@ -496,6 +496,12 @@ func TestExpressions(t *testing.T) { fullRanges: 2, intervalRanges: 0, }, + { + expr: `time()`, + output: []string{`scalar: 3000 @[%v]`}, + fullRanges: 0, + intervalRanges: 0, + }, } tieredStorage, closer := newTestStorage(t)