Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

function: add support for absent() #152

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions engine/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,18 @@ func TestQueriesAgainstOldEngine(t *testing.T) {
http_requests_total{pod="nginx-2"} 1+2x18`,
query: "count_over_time(http_requests_total[30s])",
},
{
name: "absent",
load: `load 30s
http_requests_total{pod="nginx-1"} 0
http_requests_total{pod="nginx-2"} 1`,
query: "absent(http_requests_total[30s])",
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add another test case where there is no data matching the queried series at all?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i will try

{
name: "absent",
load: `load 30s`,
query: "absent(http_requests_total[30s])",
},
{
name: "average",
load: `load 30s
Expand Down
15 changes: 15 additions & 0 deletions execution/function/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,21 @@ var Funcs = map[string]FunctionCall{
"asinh": simpleFunc(math.Asinh),
"acosh": simpleFunc(math.Acosh),
"atanh": simpleFunc(math.Atanh),
"absent": func(f FunctionArgs) promql.Sample {
if len(f.Points) == 0 {
return promql.Sample{
Metric: f.Labels,
Point: promql.Point{
T: f.StepTime,
V: 1,
},
}
}
return promql.Sample{
Metric: f.Labels,
Point: promql.Point{},
}
},
"rad": simpleFunc(func(v float64) float64 {
return v * math.Pi / 180
}),
Expand Down