-
Notifications
You must be signed in to change notification settings - Fork 2k
/
tracing_test.go
116 lines (99 loc) · 3.48 KB
/
tracing_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
// Copyright (c) The Thanos Authors.
// Licensed under the Apache License 2.0.
package e2e_test
import (
"context"
"fmt"
"io"
"net/http"
"strings"
"testing"
"time"
"github.com/pkg/errors"
"github.com/prometheus/common/model"
"github.com/thanos-io/thanos/pkg/promclient"
"github.com/thanos-io/thanos/pkg/runutil"
"github.com/thanos-io/thanos/pkg/tracing/client"
"github.com/thanos-io/thanos/pkg/tracing/jaeger"
"github.com/thanos-io/thanos/test/e2e/e2ethanos"
"github.com/efficientgo/e2e"
e2emon "github.com/efficientgo/e2e/monitoring"
"github.com/efficientgo/tools/core/pkg/testutil"
"gopkg.in/yaml.v2"
)
// Test to check if the trace provider works as expected.
func TestJaegerTracing(t *testing.T) {
env, err := e2e.NewDockerEnvironment("e2e-tracing-test")
testutil.Ok(t, err)
t.Cleanup(env.Close)
name := "testing"
newJaegerRunnable := env.Runnable(fmt.Sprintf("jaeger-%s", name)).
WithPorts(
map[string]int{
"http": 16686,
"http.admin": 14269,
"jaeger.thrift-model.proto": 14250,
"jaeger.thrift": 14268,
}).
Init(e2e.StartOptions{
Image: "jaegertracing/all-in-one:1.33",
Readiness: e2e.NewHTTPReadinessProbe("http.admin", "/", 200, 200),
})
newJaeger := e2emon.AsInstrumented(newJaegerRunnable, "http.admin")
testutil.Ok(t, e2e.StartAndWaitReady(newJaeger))
jaegerConfig, err := yaml.Marshal(client.TracingConfig{
Type: client.Jaeger,
Config: jaeger.Config{
ServiceName: "thanos-sidecar",
SamplerType: "const",
SamplerParam: 1,
Endpoint: "http://" + newJaeger.InternalEndpoint("jaeger.thrift") + "/api/traces",
},
})
testutil.Ok(t, err)
prom1, sidecar1 := e2ethanos.NewPrometheusWithJaegerTracingSidecarCustomImage(env, "alone", e2ethanos.DefaultPromConfig("prom-alone", 0, "", "", e2ethanos.LocalPrometheusTarget), "",
e2ethanos.DefaultPrometheusImage(), "", e2ethanos.DefaultImage(), string(jaegerConfig), "")
testutil.Ok(t, e2e.StartAndWaitReady(prom1, sidecar1))
qb := e2ethanos.NewQuerierBuilder(env, "1", sidecar1.InternalEndpoint("grpc"))
q := qb.WithTracingConfig(fmt.Sprintf(`type: JAEGER
config:
sampler_type: const
sampler_param: 1
service_name: thanos-query
endpoint: %s`, "http://"+newJaeger.InternalEndpoint("jaeger.thrift")+"/api/traces")).Init()
testutil.Ok(t, e2e.StartAndWaitReady(q))
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute)
t.Cleanup(cancel)
queryAndAssertSeries(t, ctx, q.Endpoint("http"), e2ethanos.QueryUpWithoutInstance, time.Now, promclient.QueryOptions{
Deduplicate: false,
}, []model.Metric{
{
"job": "myself",
"prometheus": "prom-alone",
"replica": "0",
},
})
url := "http://" + strings.TrimSpace(newJaeger.Endpoint("http")+"/api/traces?service=thanos-query&operation=proxy.series")
request, err := http.NewRequest("GET", url, nil)
testutil.Ok(t, err)
client := &http.Client{}
testutil.Ok(t, runutil.Retry(5*time.Second, ctx.Done(), func() error {
response, err := client.Do(request)
if err != nil {
return err
}
if response.StatusCode != http.StatusOK {
return errors.New("status code not OK")
}
defer response.Body.Close()
body, err := io.ReadAll(response.Body)
testutil.Ok(t, err)
resp := string(body)
if strings.Contains(resp, `"data":[]`) {
return errors.New("no data returned")
}
testutil.Assert(t, strings.Contains(resp, `"serviceName":"thanos-query"`))
testutil.Assert(t, strings.Contains(resp, `"serviceName":"thanos-sidecar"`))
return nil
}))
}