forked from grafana/tempo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
receivers_test.go
152 lines (134 loc) · 4.36 KB
/
receivers_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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
package e2e
import (
"context"
crand "crypto/rand"
"testing"
"github.com/grafana/dskit/user"
"github.com/grafana/e2e"
"github.com/grafana/tempo/integration/util"
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/zipkinexporter"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/config/configgrpc"
"go.opentelemetry.io/collector/config/confighttp"
"go.opentelemetry.io/collector/config/configtls"
"go.opentelemetry.io/collector/exporter"
"go.opentelemetry.io/collector/exporter/otlpexporter"
"go.opentelemetry.io/collector/pdata/ptrace"
metricnoop "go.opentelemetry.io/otel/metric/noop"
tracenoop "go.opentelemetry.io/otel/trace/noop"
"go.uber.org/zap"
"github.com/grafana/tempo/pkg/httpclient"
tempoUtil "github.com/grafana/tempo/pkg/util"
"github.com/grafana/tempo/pkg/util/test"
)
const (
configAllInOneLocal = "deployments/config-all-in-one-local.yaml"
)
func TestReceivers(t *testing.T) {
s, err := e2e.NewScenario("tempo_e2e")
require.NoError(t, err)
defer s.Close()
require.NoError(t, util.CopyFileToSharedDir(s, configAllInOneLocal, "config.yaml"))
tempo := util.NewTempoAllInOne()
require.NoError(t, s.StartAndWaitReady(tempo))
testReceivers := []struct {
name string
factory exporter.Factory
config func(exporter.Factory, string) component.Config
endpoint string
}{
{
"otlp gRPC",
otlpexporter.NewFactory(),
func(factory exporter.Factory, endpoint string) component.Config {
exporterCfg := factory.CreateDefaultConfig()
otlpCfg := exporterCfg.(*otlpexporter.Config)
otlpCfg.ClientConfig = configgrpc.ClientConfig{
Endpoint: endpoint,
TLSSetting: configtls.ClientConfig{
Insecure: true,
},
}
return otlpCfg
},
tempo.Endpoint(4317),
},
{
"zipkin",
zipkinexporter.NewFactory(),
func(factory exporter.Factory, endpoint string) component.Config {
exporterCfg := factory.CreateDefaultConfig()
zipkinCfg := exporterCfg.(*zipkinexporter.Config)
zipkinCfg.ClientConfig = confighttp.ClientConfig{
Endpoint: endpoint,
TLSSetting: configtls.ClientConfig{
Insecure: true,
},
}
zipkinCfg.Format = "json"
return zipkinCfg
},
"http://" + tempo.Endpoint(9411),
},
}
for _, tc := range testReceivers {
t.Run(tc.name, func(t *testing.T) {
// create exporter
logger, _ := zap.NewDevelopment()
exporter, err := tc.factory.CreateTracesExporter(
context.Background(),
exporter.CreateSettings{
TelemetrySettings: component.TelemetrySettings{
Logger: logger,
TracerProvider: tracenoop.NewTracerProvider(),
MeterProvider: metricnoop.NewMeterProvider(),
},
BuildInfo: component.NewDefaultBuildInfo(),
},
tc.config(tc.factory, tc.endpoint),
)
require.NoError(t, err)
err = exporter.Start(context.Background(), componenttest.NewNopHost())
require.NoError(t, err)
// make request
traceID := make([]byte, 16)
_, err = crand.Read(traceID)
require.NoError(t, err)
req := test.MakeTrace(20, traceID)
// zipkin doesn't support events and will 400 if you attempt to push one. just strip
// all events from the trace here
if tc.name == "zipkin" {
for _, b := range req.ResourceSpans {
for _, ss := range b.ScopeSpans {
for _, s := range ss.Spans {
s.Events = nil
}
}
}
}
b, err := req.Marshal()
require.NoError(t, err)
// unmarshal into otlp proto
traces, err := (&ptrace.ProtoUnmarshaler{}).UnmarshalTraces(b)
require.NoError(t, err)
require.NotNil(t, traces)
ctx := user.InjectOrgID(context.Background(), tempoUtil.FakeTenantID)
ctx, err = user.InjectIntoGRPCRequest(ctx)
require.NoError(t, err)
// send traces to tempo
err = exporter.ConsumeTraces(ctx, traces)
require.NoError(t, err)
// shutdown to ensure traces are flushed
require.NoError(t, exporter.Shutdown(context.Background()))
// query for the trace
client := httpclient.New("http://"+tempo.Endpoint(3200), tempoUtil.FakeTenantID)
trace, err := client.QueryTrace(tempoUtil.TraceIDToHexString(traceID))
require.NoError(t, err)
// just compare spanCount because otel flattens all ILS into one
assert.Equal(t, util.SpanCount(req), util.SpanCount(trace))
})
}
}