Fix time() behavior.

time() should return the timestamp for which the query is executed, not
the actual current time.

Change-Id: I430a45cabad7785cd58f95b1028a71dff4c87710
This commit is contained in:
Julius Volz 2014-07-28 18:10:11 +02:00
parent 527831ec6e
commit 54eb21b22a
2 changed files with 7 additions and 1 deletions

View file

@ -75,7 +75,7 @@ func (function *Function) CheckArgTypes(args []Node) error {
// === time() clientmodel.SampleValue === // === time() clientmodel.SampleValue ===
func timeImpl(timestamp clientmodel.Timestamp, view *viewAdapter, args []Node) interface{} { 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 === // === delta(matrix MatrixNode, isCounter ScalarNode) Vector ===

View file

@ -496,6 +496,12 @@ func TestExpressions(t *testing.T) {
fullRanges: 2, fullRanges: 2,
intervalRanges: 0, intervalRanges: 0,
}, },
{
expr: `time()`,
output: []string{`scalar: 3000 @[%v]`},
fullRanges: 0,
intervalRanges: 0,
},
} }
tieredStorage, closer := newTestStorage(t) tieredStorage, closer := newTestStorage(t)