Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

Vandit1604
Copy link
Contributor

Fixes #15443

Copy link
Member

@beorn7 beorn7 left a 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:

  1. I guess we should also add a warning if the result is truncated.
  2. The documentation needs an update.
  3. 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]>
@Vandit1604 Vandit1604 force-pushed the limit-param-to-query-and-query_range branch from e6949ae to e8afb9c Compare December 12, 2024 18:57
@beorn7
Copy link
Member

beorn7 commented Dec 18, 2024

Is there a reason why we are not covering testing matrix/vector for Query API and queryRange API? Is it because that's not possible in the test suite?

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:

label_replace(vector(42), "foo", "bar", "", "") or label_replace(vector(3.1415), "dings", "bums", "", "")

This returns a vector with two elements, so you could try out limit=1 to see if only one is returned. (And same for a range query.)

@beorn7
Copy link
Member

beorn7 commented Dec 18, 2024

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.)

Vandit1604 and others added 2 commits December 18, 2024 21:58
Co-authored-by: Björn Rabenstein <[email protected]>
Signed-off-by: Vandit Singh <[email protected]>
Signed-off-by: Vandit Singh <[email protected]>
@Vandit1604 Vandit1604 force-pushed the limit-param-to-query-and-query_range branch from ba600a0 to 2136065 Compare December 18, 2024 18:54
@Vandit1604
Copy link
Contributor Author

There are ways to create a fully fledged vector with multiple elements. Not sure what's the best, but here is my spontaneous attempt:

label_replace(vector(42), "foo", "bar", "", "") or label_replace(vector(3.1415), "dings", "bums", "", "")

This returns a vector with two elements, so you could try out limit=1 to see if only one is returned. (And same for a range query.)

I couldn't find where I could fill the TSDB with testing data. Added some tests for query and query_range checking warningCount.

@beorn7
Copy link
Member

beorn7 commented Dec 19, 2024

My point was that with a test query like label_replace(vector(42), "foo", "bar", "", "") or label_replace(vector(3.1415), "dings", "bums", "", "") you can create a vector with multiple elements without the need to fill the test TSDB with data.

@Vandit1604
Copy link
Contributor Author

Vandit1604 commented Dec 22, 2024

The test case for the query:

label_replace(vector(42), "foo", "bar", "", "") or label_replace(vector(3.1415), "dings", "bums", "", "")

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

@Vandit1604
Copy link
Contributor Author

I've pushed the changes with tests (in 587c690) that simulate a vector using label_replace. The values match as expected, but the timestamps are different causing the tests to fail.
Should we ignore the timestamp differences, or is there a way to make them match in code?

Copy link
Member

@beorn7 beorn7 left a 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]>
beorn7
beorn7 previously approved these changes Jan 9, 2025
Copy link
Member

@beorn7 beorn7 left a 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.

@beorn7 beorn7 dismissed their stale review January 9, 2025 15:49

Test still failing

@beorn7
Copy link
Member

beorn7 commented Jan 9, 2025

Sorry, tests are still failing. Seems like a simple fix.

Signed-off-by: Vandit Singh <[email protected]>
@Vandit1604
Copy link
Contributor Author

Sorry, tests are still failing. Seems like a simple fix.

Fixed.

@beorn7 beorn7 merged commit 6339989 into prometheus:main Jan 9, 2025
26 checks passed
@beorn7
Copy link
Member

beorn7 commented Jan 9, 2025

🎉 thank you very much.

Vandit1604 added a commit to Vandit1604/prometheus that referenced this pull request Jan 16, 2025
…#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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a limit parameter to /query and /query_range

2 participants