-
Notifications
You must be signed in to change notification settings - Fork 825
Add test to verify query response compression (#6849) #6877
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
Merged
yeya24
merged 2 commits into
cortexproject:master
from
siddarth2810:query-response-compression-test
Jul 23, 2025
+89
−0
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
//go:build requires_docker | ||
// +build requires_docker | ||
|
||
package integration | ||
|
||
import ( | ||
"compress/gzip" | ||
"fmt" | ||
"net/http" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/cortexproject/cortex/integration/e2e" | ||
e2edb "github.com/cortexproject/cortex/integration/e2e/db" | ||
"github.com/cortexproject/cortex/integration/e2ecortex" | ||
) | ||
|
||
func TestQueryResponseCompression(t *testing.T) { | ||
s, err := e2e.NewScenario(networkName) | ||
require.NoError(t, err) | ||
defer s.Close() | ||
|
||
// Start dependencies. | ||
consul := e2edb.NewConsul() | ||
minio := e2edb.NewMinio(9000, bucketName) | ||
require.NoError(t, s.StartAndWaitReady(consul, minio)) | ||
|
||
flags := mergeFlags(BlocksStorageFlags(), map[string]string{ | ||
"-api.response-compression-enabled": "true", | ||
}) | ||
|
||
distributor := e2ecortex.NewDistributor("distributor", e2ecortex.RingStoreConsul, consul.NetworkHTTPEndpoint(), flags, "") | ||
ingester := e2ecortex.NewIngester("ingester", e2ecortex.RingStoreConsul, consul.NetworkHTTPEndpoint(), flags, "") | ||
require.NoError(t, s.StartAndWaitReady(distributor, ingester)) | ||
|
||
// Wait until the distributor has updated the ring. | ||
require.NoError(t, distributor.WaitSumMetrics(e2e.Equals(512), "cortex_ring_tokens_total")) | ||
|
||
// Push series to Cortex. | ||
now := time.Now() | ||
c, err := e2ecortex.NewClient(distributor.HTTPEndpoint(), "", "", "", "user-1") | ||
require.NoError(t, err) | ||
|
||
series, _ := generateSeries("series_1", now) | ||
res, err := c.Push(series) | ||
require.NoError(t, err) | ||
require.Equal(t, 200, res.StatusCode) | ||
|
||
querier := e2ecortex.NewQuerier("querier", e2ecortex.RingStoreConsul, consul.NetworkHTTPEndpoint(), flags, "") | ||
require.NoError(t, s.StartAndWaitReady(querier)) | ||
|
||
// Wait until the querier has updated the ring. | ||
require.NoError(t, querier.WaitSumMetrics(e2e.Equals(512), "cortex_ring_tokens_total")) | ||
|
||
endpoint := fmt.Sprintf("http://%s/api/prom/api/v1/query?query=series_1", querier.HTTPEndpoint()) | ||
|
||
t.Run("Compressed", func(t *testing.T) { | ||
req, err := http.NewRequest("GET", endpoint, nil) | ||
require.NoError(t, err) | ||
req.Header.Set("X-Scope-OrgID", "user-1") | ||
req.Header.Set("Accept-Encoding", "gzip") | ||
|
||
resp, err := http.DefaultClient.Do(req) | ||
require.NoError(t, err) | ||
defer resp.Body.Close() | ||
|
||
require.Equal(t, http.StatusOK, resp.StatusCode) | ||
require.Equal(t, "gzip", resp.Header.Get("Content-Encoding")) | ||
|
||
gzipReader, err := gzip.NewReader(resp.Body) | ||
require.NoError(t, err) | ||
defer gzipReader.Close() | ||
}) | ||
|
||
t.Run("Uncompressed", func(t *testing.T) { | ||
req, err := http.NewRequest("GET", endpoint, nil) | ||
require.NoError(t, err) | ||
req.Header.Set("X-Scope-OrgID", "user-1") | ||
|
||
resp, err := http.DefaultClient.Do(req) | ||
require.NoError(t, err) | ||
defer resp.Body.Close() | ||
|
||
require.Equal(t, http.StatusOK, resp.StatusCode) | ||
require.Empty(t, resp.Header.Get("Content-Encoding")) | ||
}) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The current tests are good. But I'd like to see we have test cases covering queries against query frontend as well. Not just querier
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.
Oh alright, I'l add a new endpoint with query frontend and update the tests. Thanks a lot for the review !
Uh oh!
There was an error while loading. Please reload this page.
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.
Hey @yeya24 , after tweaking around with query frontend for a while, I realized that testing both query frontend and querier cannot be done with same instance of cortex. So I divided the code into two isolated functions.
Is this what you had in mind ?
TestQuerierDirectResponseCompression
- tests compression directly using querier endpointTestQueryFrontendResponseCompression
- tests compression via query frontend endpointThe query frontend test is failing because the response is not being compressed
Been stuck on this for a while, Is this expected or am I totally mistaken ? Would be really really thankful for any inputs, thanks !!
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.
Can you elaborate more why we cannot reuse the same test?
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.
I'm using the same test, I just moved the compression logic to
runQueryResponseTest
function. And yes I am able to test both endpoints using the same cortex instance. Apologies for the confusion.so when using query frontend endpoint the existing compression test is failing. I logged the response headers and I dont see
Content-Encoding
header. I could not figure out whyThere 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.
Apologies for the late reply. Let's do querier for now in this PR then. I think there is an issue for query frontend response compression and we can take more time to fix it.
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.
Right, I could not figure out why compression headers were not being added. I only removed the Store Gateway and updated the PR. Thank you so much !
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.
@afhassan investigated it #6909