forked from grafana/tempo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompression_test.go
81 lines (61 loc) · 2.53 KB
/
compression_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package e2e
import (
"compress/gzip"
"net/http"
"testing"
"time"
"github.com/gogo/protobuf/jsonpb"
"github.com/stretchr/testify/require"
"github.com/grafana/e2e"
util "github.com/grafana/tempo/integration"
"github.com/grafana/tempo/pkg/tempopb"
tempoUtil "github.com/grafana/tempo/pkg/util"
)
const (
configCompression = "config-all-in-one-local.yaml"
)
func TestCompression(t *testing.T) {
s, err := e2e.NewScenario("tempo_e2e")
require.NoError(t, err)
defer s.Close()
require.NoError(t, util.CopyFileToSharedDir(s, configCompression, "config.yaml"))
tempo := util.NewTempoAllInOne()
require.NoError(t, s.StartAndWaitReady(tempo))
// Get port for the Jaeger gRPC receiver endpoint
c, err := util.NewJaegerGRPCClient(tempo.Endpoint(14250))
require.NoError(t, err)
require.NotNil(t, c)
info := tempoUtil.NewTraceInfo(time.Now(), "")
require.NoError(t, info.EmitAllBatches(c))
apiClient := tempoUtil.NewClient("http://"+tempo.Endpoint(3200), "")
apiClientWithCompression := tempoUtil.NewClientWithCompression("http://"+tempo.Endpoint(3200), "")
queryAndAssertTrace(t, apiClient, info)
queryAndAssertTraceCompression(t, apiClientWithCompression, info)
}
func queryAndAssertTraceCompression(t *testing.T, client *tempoUtil.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)
require.True(t, equalTraces(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+tempoUtil.QueryTraceEndpoint+"/"+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.Trace{}
unmarshaller := &jsonpb.Unmarshaler{}
err = unmarshaller.Unmarshal(gzipReader, m)
require.NoError(t, err)
require.True(t, equalTraces(expected, m))
}