Skip to content

Commit

Permalink
remove snappy compression tests
Browse files Browse the repository at this point in the history
Signed-off-by: Ahmed Hassan <[email protected]>
  • Loading branch information
afhassan committed Sep 18, 2024
1 parent 2f1b315 commit 6a457e7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 107 deletions.
52 changes: 8 additions & 44 deletions pkg/querier/tripperware/instantquery/instant_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"time"

"github.com/gogo/protobuf/proto"
"github.com/golang/snappy"
"github.com/weaveworks/common/httpgrpc"

"github.com/prometheus/common/model"
Expand Down Expand Up @@ -129,40 +128,17 @@ func TestCompressedResponse(t *testing.T) {
},
status: 200,
},
{
compression: "snappy",
promBody: &tripperware.PrometheusResponse{
Status: "success",
Data: tripperware.PrometheusData{
ResultType: model.ValString.String(),
Result: tripperware.PrometheusQueryResult{Result: &tripperware.PrometheusQueryResult_RawBytes{[]byte(`{"resultType":"string","result":[1,"foo"]}`)}},
},
Headers: []*tripperware.PrometheusResponseHeader{},
},
status: 200,
},
{
compression: `gzip`,
jsonBody: `error generic 400`,
status: 400,
err: httpgrpc.Errorf(400, `error generic 400`),
},
{
compression: `snappy`,
jsonBody: `error generic 400`,
status: 400,
err: httpgrpc.Errorf(400, `error generic 400`),
},
{
compression: `gzip`,
status: 400,
err: httpgrpc.Errorf(400, ""),
},
{
compression: `snappy`,
status: 400,
err: httpgrpc.Errorf(400, ""),
},
} {
t.Run(strconv.Itoa(i), func(t *testing.T) {
t.Parallel()
Expand All @@ -181,27 +157,15 @@ func TestCompressedResponse(t *testing.T) {
responseBody := bytes.NewBuffer(b)

var buf bytes.Buffer
if tc.compression == "gzip" {
h.Set("Content-Encoding", "gzip")
if tc.promBody != nil {
tc.promBody.Headers = append(tc.promBody.Headers, &tripperware.PrometheusResponseHeader{Name: "Content-Encoding", Values: []string{"gzip"}})
}
w := gzip.NewWriter(&buf)
_, err := w.Write(b)
require.NoError(t, err)
w.Close()
responseBody = &buf
} else if tc.compression == "snappy" {
h.Set("Content-Encoding", "snappy")
if tc.promBody != nil {
tc.promBody.Headers = append(tc.promBody.Headers, &tripperware.PrometheusResponseHeader{Name: "Content-Encoding", Values: []string{"snappy"}})
}
w := snappy.NewBufferedWriter(&buf)
_, err := w.Write(b)
require.NoError(t, err)
w.Close()
responseBody = &buf
h.Set("Content-Encoding", tc.compression)
if tc.promBody != nil {
tc.promBody.Headers = append(tc.promBody.Headers, &tripperware.PrometheusResponseHeader{Name: "Content-Encoding", Values: []string{"gzip"}})
}
w := gzip.NewWriter(&buf)
_, err := w.Write(b)
require.NoError(t, err)
w.Close()
responseBody = &buf

response := &http.Response{
StatusCode: tc.status,
Expand Down
70 changes: 7 additions & 63 deletions pkg/querier/tripperware/queryrange/query_range_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"compress/gzip"
"context"
"github.com/gogo/protobuf/proto"
"github.com/golang/snappy"
"io"
"net/http"
"strconv"
Expand Down Expand Up @@ -1217,62 +1216,17 @@ func TestCompressedResponse(t *testing.T) {
jsonBody:`{"status":"success","data":{"resultType":"matrix","result":[{"metric":{"a":"b","c":"d"},"values":[[2,"2"],[3,"3"]]}],"stats":{"samples":{"totalQueryableSamples":20,"totalQueryableSamplesPerStep":[[2,2],[3,3]],"peakSamples":10}}}}`,
status: 200,
},
{
compression: `snappy`,
promBody: &tripperware.PrometheusResponse{
Status: StatusSuccess,
Data: tripperware.PrometheusData{
ResultType: matrix,
Result: tripperware.PrometheusQueryResult{
Result: &tripperware.PrometheusQueryResult_Matrix{
Matrix: &tripperware.Matrix{
SampleStreams: []tripperware.SampleStream{
{
Labels: []cortexpb.LabelAdapter{{Name: "a", Value: "b"}, {Name: "c", Value: "d"}},
Samples: []cortexpb.Sample{
{Value: 2, TimestampMs: 2000},
{Value: 3, TimestampMs: 3000},
},
},
},
},
},
},
Stats: &tripperware.PrometheusResponseStats{Samples: &tripperware.PrometheusResponseSamplesStats{
TotalQueryableSamples: 20,
TotalQueryableSamplesPerStep: []*tripperware.PrometheusResponseQueryableSamplesStatsPerStep{
{Value: 2, TimestampMs: 2000},
{Value: 3, TimestampMs: 3000},
},
}},
},
Headers: []*tripperware.PrometheusResponseHeader{},
},
jsonBody:`{"status":"success","data":{"resultType":"matrix","result":[{"metric":{"a":"b","c":"d"},"values":[[2,"2"],[3,"3"]]}],"stats":{"samples":{"totalQueryableSamples":20,"totalQueryableSamplesPerStep":[[2,2],[3,3]]}}}}`,
status: 200,
},
{
compression: `gzip`,
jsonBody: `error generic 400`,
status: 400,
err: httpgrpc.Errorf(400, `error generic 400`),
},
{
compression: `snappy`,
jsonBody: `error generic 400`,
status: 400,
err: httpgrpc.Errorf(400, `error generic 400`),
},
{
compression: `gzip`,
status: 400,
err: httpgrpc.Errorf(400, ""),
},
{
compression: `snappy`,
status: 400,
err: httpgrpc.Errorf(400, ""),
},
} {
t.Run(strconv.Itoa(i), func(t *testing.T) {
t.Parallel()
Expand All @@ -1293,23 +1247,13 @@ func TestCompressedResponse(t *testing.T) {
responseBody := bytes.NewBuffer(b)

var buf bytes.Buffer
if tc.compression == "gzip" {
h.Set("Content-Encoding", "gzip")
if tc.promBody != nil {tc.promBody.Headers = append(tc.promBody.Headers, &tripperware.PrometheusResponseHeader{Name: "Content-Encoding", Values: []string{"gzip"}})}
w := gzip.NewWriter(&buf)
_, err := w.Write(b)
require.NoError(t, err)
w.Close()
responseBody = &buf
} else if tc.compression == "snappy" {
h.Set("Content-Encoding", "snappy")
if tc.promBody != nil {tc.promBody.Headers = append(tc.promBody.Headers, &tripperware.PrometheusResponseHeader{Name: "Content-Encoding", Values: []string{"snappy"}})}
w := snappy.NewBufferedWriter(&buf)
_, err := w.Write(b)
require.NoError(t, err)
w.Close()
responseBody = &buf
}
h.Set("Content-Encoding", tc.compression)
if tc.promBody != nil {tc.promBody.Headers = append(tc.promBody.Headers, &tripperware.PrometheusResponseHeader{Name: "Content-Encoding", Values: []string{"gzip"}})}
w := gzip.NewWriter(&buf)
_, err := w.Write(b)
require.NoError(t, err)
w.Close()
responseBody = &buf

response := &http.Response{
StatusCode: tc.status,
Expand Down

0 comments on commit 6a457e7

Please sign in to comment.