Files
Joe ElliottandGitHub 5ee93d3cf8 Tempo 3.0: Integration Tests Rewrite (#6088)
* First pass test harness

Signed-off-by: Joe Elliott <[email protected]>

* limits - passed

Signed-off-by: Joe Elliott <[email protected]>

* metrics generator - passed

Signed-off-by: Joe Elliott <[email protected]>

* harness cleanup/fix target info test

Signed-off-by: Joe Elliott <[email protected]>

* deployments - passed

Signed-off-by: Joe Elliott <[email protected]>

* receivers - passed

Signed-off-by: Joe Elliott <[email protected]>

* harness cleanup

Signed-off-by: Joe Elliott <[email protected]>

* storage - passed

Signed-off-by: Joe Elliott <[email protected]>

* api - passing

Signed-off-by: Joe Elliott <[email protected]>

* cleanup and CI

Signed-off-by: Joe Elliott <[email protected]>

* Additional tests

Signed-off-by: Joe Elliott <[email protected]>

* it's me and you linter. how many times are you going to do this to me?

Signed-off-by: Joe Elliott <[email protected]>

* lint and tests

Signed-off-by: Joe Elliott <[email protected]>

* restored live store partition tests

Signed-off-by: Joe Elliott <[email protected]>

* massive lint

Signed-off-by: Joe Elliott <[email protected]>

* cleanup

Signed-off-by: Joe Elliott <[email protected]>

* lint >.<

Signed-off-by: Joe Elliott <[email protected]>

* wups

Signed-off-by: Joe Elliott <[email protected]>

* cleanup and stabilizing

Signed-off-by: Joe Elliott <[email protected]>

* cleanup

Signed-off-by: Joe Elliott <[email protected]>

* omg

Signed-off-by: Joe Elliott <[email protected]>

* added config file. removed empty file. deleted some debug code

Signed-off-by: Joe Elliott <[email protected]>

* even more fixes

Signed-off-by: Joe Elliott <[email protected]>

* maybe this works? maybe it was all local networking issues

Signed-off-by: Joe Elliott <[email protected]>

* review

Signed-off-by: Joe Elliott <[email protected]>

* backed off huge write timeout. added missing config file

Signed-off-by: Joe Elliott <[email protected]>

* restore disable parallelism setting. restore beefy write timeout

Signed-off-by: Joe Elliott <[email protected]>

* apparently another test relied on the http receiver

Signed-off-by: Joe Elliott <[email protected]>

* livestore avail zone!

Signed-off-by: Joe Elliott <[email protected]>

* add support for v1 traces and tags endpoints

Signed-off-by: Joe Elliott <[email protected]>

* review

Signed-off-by: Joe Elliott <[email protected]>

* changed the location of the changelog entry to avoid conflicts

Signed-off-by: Joe Elliott <[email protected]>

---------

Signed-off-by: Joe Elliott <[email protected]>
2026-01-07 08:31:11 -05:00

79 lines
2.4 KiB
Go

package deployments
import (
"bytes"
"compress/gzip"
"io"
"net/http"
"testing"
"time"
"github.com/gogo/protobuf/jsonpb"
"github.com/grafana/tempo/integration/util"
"github.com/klauspost/compress/gzhttp"
"github.com/stretchr/testify/require"
"github.com/grafana/tempo/pkg/httpclient"
"github.com/grafana/tempo/pkg/tempopb"
tempoUtil "github.com/grafana/tempo/pkg/util"
)
func TestCompression(t *testing.T) {
util.RunIntegrationTests(t, util.TestHarnessConfig{
DeploymentMode: util.DeploymentModeSingleBinary,
}, func(h *util.TempoHarness) {
h.WaitTracesWritable(t)
// Send a trace
info := tempoUtil.NewTraceInfo(time.Now(), "")
require.NoError(t, h.WriteTraceInfo(info, ""))
h.WaitTracesQueryable(t, 1)
// Create client with compression
apiClient := h.APIClientHTTP("")
util.QueryAndAssertTrace(t, apiClient, info)
// Query and assert trace with compression
apiClient.WithTransport(gzhttp.Transport(http.DefaultTransport))
queryAndAssertTraceCompression(t, apiClient, info)
})
}
func queryAndAssertTraceCompression(t *testing.T, client *httpclient.Client, info *tempoUtil.TraceInfo) {
// The received client will strip the header before we have a chance to inspect it, so just validate that the compressed client works as expected.
result, err := client.QueryTrace(info.HexID())
require.NoError(t, err)
require.NotNil(t, result)
expected, err := info.ConstructTraceFromEpoch()
require.NoError(t, err)
util.AssertEqualTrace(t, result, expected)
// Go's http.Client transparently requests gzip compression and automatically decompresses the
// response, to disable this behaviour you have to explicitly set the Accept-Encoding header.
// Make the call directly so we have a chance to inspect the response header and manually un-gzip it ourselves to confirm the content.
request, err := http.NewRequest("GET", client.BaseURL+httpclient.QueryTraceV2Endpoint+"/"+info.HexID(), nil)
require.NoError(t, err)
request.Header.Add("Accept-Encoding", "gzip")
res, err := client.Do(request)
require.NoError(t, err)
defer res.Body.Close()
require.Equal(t, "gzip", res.Header.Get("Content-Encoding"))
gzipReader, err := gzip.NewReader(res.Body)
require.NoError(t, err)
defer gzipReader.Close()
m := &tempopb.TraceByIDResponse{}
bodyBytes, _ := io.ReadAll(gzipReader)
err = jsonpb.Unmarshal(bytes.NewReader(bodyBytes), m)
require.NoError(t, err)
util.AssertEqualTrace(t, expected, m.Trace)
}