mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-09 23:24:05 -08:00
Merge pull request #8436 from codesome/timestamp-at-mod-fix
Fix timestamp() function for @ modifier
This commit is contained in:
commit
67edfc6054
|
@ -1125,6 +1125,11 @@ func (ev *evaluator) eval(expr parser.Expr) (parser.Value, storage.Warnings) {
|
|||
vs, ok := arg.(*parser.VectorSelector)
|
||||
if ok {
|
||||
return ev.rangeEval(func(v []parser.Value, enh *EvalNodeHelper) (Vector, storage.Warnings) {
|
||||
if vs.Timestamp != nil {
|
||||
// This is a special case only for "timestamp" since the offset
|
||||
// needs to be adjusted for every point.
|
||||
vs.Offset = time.Duration(enh.Ts-*vs.Timestamp) * time.Millisecond
|
||||
}
|
||||
val, ws := ev.vectorSelector(vs, enh.Ts)
|
||||
return call([]parser.Value{val}, e.Args, enh), ws
|
||||
})
|
||||
|
|
|
@ -907,6 +907,11 @@ load 1ms
|
|||
for ts := int64(-1000000 + 1000); ts <= 0; ts += 1000 {
|
||||
require.NoError(t, app.AddFast(ref, ts, -float64(ts/1000)+1))
|
||||
}
|
||||
|
||||
// To test the fix for https://github.com/prometheus/prometheus/issues/8433.
|
||||
_, err = app.Add(labels.FromStrings("__name__", "metric_timestamp"), 3600*1000, 1000)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.NoError(t, app.Commit())
|
||||
|
||||
cases := []struct {
|
||||
|
@ -1033,6 +1038,26 @@ load 1ms
|
|||
Metric: lblstopk2,
|
||||
},
|
||||
},
|
||||
}, {
|
||||
// Tests for https://github.com/prometheus/prometheus/issues/8433.
|
||||
// The trick here is that the query range should be > lookback delta.
|
||||
query: `timestamp(metric_timestamp @ 3600)`,
|
||||
start: 0, end: 7 * 60, interval: 60,
|
||||
result: Matrix{
|
||||
Series{
|
||||
Points: []Point{
|
||||
{V: 3600, T: 0},
|
||||
{V: 3600, T: 60 * 1000},
|
||||
{V: 3600, T: 2 * 60 * 1000},
|
||||
{V: 3600, T: 3 * 60 * 1000},
|
||||
{V: 3600, T: 4 * 60 * 1000},
|
||||
{V: 3600, T: 5 * 60 * 1000},
|
||||
{V: 3600, T: 6 * 60 * 1000},
|
||||
{V: 3600, T: 7 * 60 * 1000},
|
||||
},
|
||||
Metric: labels.Labels{},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -1061,6 +1086,7 @@ load 1ms
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestRecoverEvaluatorRuntime(t *testing.T) {
|
||||
ev := &evaluator{logger: log.NewNopLogger()}
|
||||
|
||||
|
@ -2124,3 +2150,8 @@ func TestEngineOptsValidation(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestFuncTimestampWithAtModifier tests for https://github.com/prometheus/prometheus/issues/8433.
|
||||
func TestFuncTimestampWithAtModifier(t *testing.T) {
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue