-
Notifications
You must be signed in to change notification settings - Fork 9.9k
web/api: Add a limit parameter to /query and /query_range #15552
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
web/api: Add a limit parameter to /query and /query_range #15552
Conversation
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.
Thank you very much.
Three general things:
- I guess we should also add a warning if the result is truncated.
- The documentation needs an update.
- Adding a test would be good.
#13396 could serve as a template how to address all three points.
@machine424 @bboreham could you check if this makes sense overall? I'm not very familiar with this whole decision of limiting API endpoints, and you were involved with the previous related PRs.
Signed-off-by: Vandit Singh <[email protected]>
Signed-off-by: Vandit Singh <[email protected]>
Signed-off-by: Vandit Singh <[email protected]>
e6949ae
to
e8afb9c
Compare
I think the reason is that we do not fill the TSDB with any data for these simple tests. Therefore, all the queries are just using PromQL that still returns something with an empty TSDB. There are ways to create a fully fledged vector with multiple elements. Not sure what's the best, but here is my spontaneous attempt:
This returns a vector with two elements, so you could try out |
In different news: I'll be off for my Xmas vacations. Back 2025-01-07. In the meantime, it would be cool if @machine424 and @bboreham could say if this is doing the right thing. (I think it does, modulo the warnings handling, see above. So we only need the tests beyond that.) |
Co-authored-by: Björn Rabenstein <[email protected]> Signed-off-by: Vandit Singh <[email protected]>
Signed-off-by: Vandit Singh <[email protected]>
ba600a0
to
2136065
Compare
Signed-off-by: Vandit Singh <[email protected]>
I couldn't find where I could fill the TSDB with testing data. Added some tests for |
My point was that with a test query like |
The test case for the query:
Failed due to a mismatch in the timestamps. The test expected a hardcoded timestamp of 0, but during testing we assign the current timestamp (in Unix epoch format) to generated values by default during execution. Prometheus does not allow you to control or ignore timestamps directly in queries. The test comparison failed because the timestamps in the actual response did not match the expected value. + {
+ endpoint: api.query,
+ query: url.Values{
+ "query": []string{
+ `label_replace(vector(42), "foo", "bar", "", "") or label_replace(vector(3.1415), "dings", "bums", "", "")`,
+ },
+ },
+ responseAsJSON: `{
+ "resultType": "vector",
+ "result": [
+ {
+ "metric": {
+ "foo": "bar"
+ },
+ "value": [0, "42"]
+ },
+ {
+ "metric": {
+ "dings": "bums"
+ },
+ "value": [0, "3.1415"]
+ }
+ ]
+ }`,
+ }, Can we ignore the timestamps in this test case? Here is the error❯ go test ./web/api/v1
--- FAIL: TestEndpoints (0.08s)
--- FAIL: TestEndpoints/local (0.03s)
--- FAIL: TestEndpoints/local/run_7_query_"query=label_replace%28vector%2842%29%2C+%22foo%22%2C+%22bar%22%2C+%22%22%2C+%22%22%29+or+label_replace%28vector%283.1415%29%2C+%22dings%22%2C+%22bums%22%2C+%22%22%2C+%22%22%29" (0.00s)
--- FAIL: TestEndpoints/local/run_7_query_"query=label_replace%28vector%2842%29%2C+%22foo%22%2C+%22bar%22%2C+%22%22%2C+%22%22%29+or+label_replace%28vector%283.1415%29%2C+%22dings%22%2C+%22bums%22%2C+%22%22%2C+%22%22%29"/GET (0.00s)
api_test.go:3676:
Error Trace: /home/vandit/Github-Forks/prometheus/web/api/v1/api_test.go:3676
Error: Not equal:
expected: map[string]interface {}{"result":[]interface {}{map[string]interface {}{"metric":map[string]interface {}{"foo":"bar"}, "value":[]interface {}{0, "42"}}, map[string]interface {}{"metric":map[string]interface {}{"dings":"bums"}, "value":[]interface {}{0, "3.1415"}}}, "resultType":"vector"}
actual : map[string]interface {}{"result":[]interface {}{map[string]interface {}{"metric":map[string]interface {}{"foo":"bar"}, "value":[]interface {}{1.734882542759e+09, "42"}}, map[string]interface {}{"metric":map[string]interface {}{"dings":"bums"}, "value":[]interface {}{1.734882542759e+09, "3.1415"}}}, "resultType":"vector"}
Diff:
--- Expected
+++ Actual
@@ -7,3 +7,3 @@
(string) (len=5) "value": ([]interface {}) (len=2) {
- (float64) 0,
+ (float64) 1.734882542759e+09,
(string) (len=2) "42"
@@ -16,3 +16,3 @@
(string) (len=5) "value": ([]interface {}) (len=2) {
- (float64) 0,
+ (float64) 1.734882542759e+09,
(string) (len=6) "3.1415"
Test: TestEndpoints/local/run_7_query_"query=label_replace%28vector%2842%29%2C+%22foo%22%2C+%22bar%22%2C+%22%22%2C+%22%22%29+or+label_replace%28vector%283.1415%29%2C+%22dings%22%2C+%22bums%22%2C+%22%22%2C+%22%22%29"/GET |
Signed-off-by: Vandit Singh <[email protected]>
I've pushed the changes with tests (in 587c690) that simulate a vector using |
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.
Does this solve your problem?
Signed-off-by: Vandit Singh <[email protected]>
Signed-off-by: Vandit Singh <[email protected]>
Signed-off-by: Vandit Singh <[email protected]>
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.
Looks great now. Thank you very much.
Sorry, tests are still failing. Seems like a simple fix. |
Signed-off-by: Vandit Singh <[email protected]>
Fixed. |
🎉 thank you very much. |
…#15552) add limit param to query and rangeQuery --------- Signed-off-by: Vandit Singh <[email protected]> Signed-off-by: Vandit Singh <[email protected]> Co-authored-by: Björn Rabenstein <[email protected]>
Fixes #15443