Skip to content

Commit

Permalink
function: add support for timestamp() (#145)
Browse files Browse the repository at this point in the history
Signed-off-by: Ziqi Zhao <[email protected]>

Signed-off-by: Ziqi Zhao <[email protected]>
  • Loading branch information
fatsheep9146 authored Jan 9, 2023
1 parent a831c7b commit 3773ec3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions engine/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,13 @@ func TestQueriesAgainstOldEngine(t *testing.T) {
http_requests_total{pod="nginx-2"} 1`,
query: "atanh(http_requests_total)",
},
{
name: "timestamp",
load: `load 30s
http_requests_total{pod="nginx-1"} 0
http_requests_total{pod="nginx-2"} 1`,
query: "timestamp(http_requests_total)",
},
{
name: "rad",
load: `load 30s
Expand Down
8 changes: 8 additions & 0 deletions execution/function/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ var Funcs = map[string]FunctionCall{
"deg": simpleFunc(func(v float64) float64 {
return v * 180 / math.Pi
}),
"timestamp": func(f FunctionArgs) promql.Sample {
return promql.Sample{
Point: promql.Point{
T: f.StepTime,
V: float64(f.Points[0].T) / 1000,
},
}
},
"pi": func(f FunctionArgs) promql.Sample {
return promql.Sample{
Point: promql.Point{
Expand Down

0 comments on commit 3773ec3

Please sign in to comment.