MCPcopy
hub / github.com/grafana/tempo / queryAndAssertTraceCompression

Function queryAndAssertTraceCompression

integration/operations/compression_test.go:43–78  ·  view source on GitHub ↗
(t *testing.T, client *httpclient.Client, info *tempoUtil.TraceInfo)

Source from the content-addressed store, hash-verified

41}
42
43func queryAndAssertTraceCompression(t *testing.T, client *httpclient.Client, info *tempoUtil.TraceInfo) {
44 // 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.
45 result, err := client.QueryTrace(info.HexID())
46 require.NoError(t, err)
47 require.NotNil(t, result)
48
49 expected, err := info.ConstructTraceFromEpoch()
50 require.NoError(t, err)
51 util.AssertEqualTrace(t, result, expected)
52
53 // Go's http.Client transparently requests gzip compression and automatically decompresses the
54 // response, to disable this behaviour you have to explicitly set the Accept-Encoding header.
55
56 // Make the call directly so we have a chance to inspect the response header and manually un-gzip it ourselves to confirm the content.
57 request, err := http.NewRequest("GET", client.BaseURL+httpclient.QueryTraceV2Endpoint+"/"+info.HexID(), nil)
58 require.NoError(t, err)
59 request.Header.Add("Accept-Encoding", "gzip")
60
61 res, err := client.Do(request)
62 require.NoError(t, err)
63 defer res.Body.Close()
64
65 require.Equal(t, "gzip", res.Header.Get("Content-Encoding"))
66
67 gzipReader, err := gzip.NewReader(res.Body)
68 require.NoError(t, err)
69 defer gzipReader.Close()
70
71 m := &tempopb.TraceByIDResponse{}
72
73 bodyBytes, _ := io.ReadAll(gzipReader)
74 err = jsonpb.Unmarshal(bytes.NewReader(bodyBytes), m)
75 require.NoError(t, err)
76
77 util.AssertEqualTrace(t, expected, m.Trace)
78}

Callers 1

TestCompressionFunction · 0.85

Calls 10

HexIDMethod · 0.80
QueryTraceMethod · 0.65
AddMethod · 0.65
DoMethod · 0.65
CloseMethod · 0.65
GetMethod · 0.65
ReadAllMethod · 0.65
UnmarshalMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected