-
Notifications
You must be signed in to change notification settings - Fork 51
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
add absent function #172
add absent function #172
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1500,6 +1500,24 @@ func TestQueriesAgainstOldEngine(t *testing.T) { | |
end: time.Unix(3000, 0), | ||
step: 2 * time.Second, | ||
}, | ||
{ | ||
name: "absent with present series", | ||
load: `load 30s | ||
absent{pod="nginx-1", series="1"} 0 | ||
absent{pod="nginx-2", series="1"} 0`, | ||
query: "absent(metric)", | ||
start: time.Unix(0, 0), | ||
end: time.Unix(3000, 0), | ||
step: 10 * time.Second, | ||
}, | ||
{ | ||
name: "absent with non-present series", | ||
load: "", | ||
query: "absent(non_existent_metric)", | ||
start: time.Unix(0, 0), | ||
end: time.Unix(3000, 0), | ||
step: 10 * time.Second, | ||
}, | ||
} | ||
|
||
disableOptimizerOpts := []bool{true, false} | ||
|
@@ -2431,6 +2449,22 @@ func TestInstantQuery(t *testing.T) { | |
http_requests_total{pod="nginx-2", series="1"} -10+1x50`, | ||
query: "sgn(http_requests_total)", | ||
}, | ||
{ | ||
name: "absent with present series", | ||
load: `load 30s | ||
absent{pod="nginx-1", series="1"} 0 | ||
absent{pod="nginx-2", series="1"} 0`, | ||
query: "absent(metric)", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
queryTime: time.Now(), | ||
sortByLabels: true, | ||
}, | ||
{ | ||
name: "absent with non-present series", | ||
load: "", | ||
query: "absent(non_existent_metric)", | ||
queryTime: time.Now(), | ||
sortByLabels: false, | ||
}, | ||
} | ||
|
||
disableOptimizerOpts := []bool{true, false} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,8 +7,8 @@ import ( | |
"fmt" | ||
"math" | ||
"time" | ||
|
||
"github.com/efficientgo/core/errors" | ||
"github.com/efficientgo/core/errors" | ||
"github.com/prometheus/prometheus/model/histogram" | ||
"github.com/prometheus/prometheus/model/labels" | ||
"github.com/prometheus/prometheus/promql" | ||
|
@@ -434,6 +434,22 @@ var Funcs = map[string]FunctionCall{ | |
return float64(t.Year()) | ||
}) | ||
}, | ||
"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{}, | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this is the correct. Probably a dedicated There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @yeya24 Thank you for the guidance. I will go through @MichaHoffmann implementation to understand it. |
||
}, | ||
} | ||
|
||
func NewFunctionCall(f *parser.Function) (FunctionCall, error) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test case seems wrong itself. Your metric name is
absent
but you are callingabsent
formetric
.metric
is not present in your test data.