Skip to content

Conversation

siddarth2810
Copy link
Contributor

@siddarth2810 siddarth2810 commented Jul 19, 2025

What this PR does:
The PR enables /api/v1/format_query API endpoint for formatting queries on Query Frontend and Querier

Which issue(s) this PR fixes:
Fixes #6670

Checklist

  • [NA] Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

Signed-off-by: Siddarth Gundu <[email protected]>
@SungJin1212
Copy link
Member

SungJin1212 commented Jul 20, 2025

Thanks for the contribution. Do we have to require the auth?

@siddarth2810
Copy link
Contributor Author

Thanks for the contribution. Do we have to require the auth?

I ran a simple curl command and it only worked when I added the Auth Header and in documentation I noticed most the API endpoints for query frontend needed authentication so I concluded that, this endpoint too must need authentication.

screenshot-20250720-181938Z-selected

Let me know if I should be doing some additional checks, would really appreciate it. Thank you so much

@SungJin1212
Copy link
Member

This API is for PromQL pretty-formatting, I'm just wondering if the authentication is necessary for it.
@friedrich-at-adobe can you take a look?

@siddarth2810
Copy link
Contributor Author

This API is for PromQL pretty-formatting, I'm just wondering if the authentication is necessary for it. @friedrich-at-adobe can you take a look?

I see, I went through some documentation and based on Prometheus security what I understand is that a standalone prometheus server dosent need any auth because its presumed that untrusted users have access to the Prometheus HTTP endpoint

but when cortex acts as a prometheus web server it would still look for tenant ID on each request, as mentioned in Cortex Auth, so in the end we need auth ?

Apologies for any confusion I caused

Copy link
Member

@friedrichg friedrichg left a comment

Choose a reason for hiding this comment

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

@siddarth2810 This looks good, but needs an integration test. Can you add it?

@friedrichg
Copy link
Member

friedrichg commented Jul 21, 2025

Thanks for the contribution. Do we have to require the auth?

I believe auth is handled already. The integration test will prove it.

@pull-request-size pull-request-size bot added size/L and removed size/S labels Jul 21, 2025
@siddarth2810
Copy link
Contributor Author

siddarth2810 commented Jul 21, 2025

@siddarth2810 This looks good, but needs an integration test. Can you add it?

Thanks a lot for the review. I have added the test, when testing for both querier and query Frontend is it required to use separate endpoints or testing is done for both when we just add query frontend ? Let me know if querierDirect needs to be removed, and if the test needs more changes.

In my other integration test, I got different results with and without using query frontend so I added both cases in this PR

Really appreaciate for any inputs, thanks ! Btw when -auth.enabled is false the tests work fine

@SungJin1212
Copy link
Member

@friedrichg @siddarth2810
I mean, do we need to require the X-Scope-OrgID header to the user? In my understanding, this API is for the pretty-formatting of the promQL query. Both ways I'm fine.

@friedrichg
Copy link
Member

I mean, do we need to require the X-Scope-OrgID header to the user? In my understanding, this API is for the pretty-formatting of the promQL query. Both ways I'm fine.

I think I prefer the way it is now. Typically things that do not required the header are things that can be queried by cortex operators, not cortex users. This API path doesn't use any resources, but suppose we impose query limits to this request type, per tenant, or a different format type in the future. We want to do this on a per tenant basis, thus we need the authority header.

it's similar to /api/v1/status/buildinfo.

@friedrichg
Copy link
Member

@siddarth2810 Thanks for implementing the test. There is a lint error still:

integration/format_query_api_test.go:106:1: File is not properly formatted (gofmt)
            req.Header.Set("X-Scope-OrgID", "user-1")

Signed-off-by: Siddarth Gundu <[email protected]>
@siddarth2810
Copy link
Contributor Author

@siddarth2810 Thanks for implementing the test. There is a lint error still:

integration/format_query_api_test.go:106:1: File is not properly formatted (gofmt)
            req.Header.Set("X-Scope-OrgID", "user-1")

My bad. Fixed it !

@SungJin1212
Copy link
Member

Thanks

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Jul 23, 2025
Copy link
Member

@friedrichg friedrichg left a comment

Choose a reason for hiding this comment

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

Great work! Thanks

@friedrichg friedrichg enabled auto-merge (squash) July 23, 2025 17:16
@friedrichg friedrichg merged commit 328bc3b into cortexproject:master Jul 23, 2025
44 of 47 checks passed
rubywtl pushed a commit to rubywtl/cortex that referenced this pull request Jul 23, 2025
* Add support for /api/v1/format_query API

Signed-off-by: Siddarth Gundu <[email protected]>

* update changelog

Signed-off-by: Siddarth Gundu <[email protected]>

* Integration: Add test for format query API

Signed-off-by: Siddarth Gundu <[email protected]>

* fix lint error

Signed-off-by: Siddarth Gundu <[email protected]>

---------

Signed-off-by: Siddarth Gundu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support /api/v1/format_query API

3 participants