github.com/thanos-io/thanos@v0.32.5/test/e2e/tracing_test.go (about) 1 // Copyright (c) The Thanos Authors. 2 // Licensed under the Apache License 2.0. 3 4 package e2e_test 5 6 import ( 7 "context" 8 "fmt" 9 "io" 10 "net/http" 11 "strings" 12 "testing" 13 "time" 14 15 "github.com/pkg/errors" 16 "github.com/prometheus/common/model" 17 "github.com/thanos-io/thanos/pkg/promclient" 18 "github.com/thanos-io/thanos/pkg/runutil" 19 "github.com/thanos-io/thanos/pkg/tracing/client" 20 "github.com/thanos-io/thanos/pkg/tracing/jaeger" 21 "github.com/thanos-io/thanos/test/e2e/e2ethanos" 22 23 "github.com/efficientgo/core/testutil" 24 "github.com/efficientgo/e2e" 25 e2emon "github.com/efficientgo/e2e/monitoring" 26 "gopkg.in/yaml.v2" 27 ) 28 29 // Test to check if the trace provider works as expected. 30 func TestJaegerTracing(t *testing.T) { 31 env, err := e2e.NewDockerEnvironment("e2e-tracing-test") 32 testutil.Ok(t, err) 33 t.Cleanup(env.Close) 34 name := "testing" 35 newJaegerRunnable := env.Runnable(fmt.Sprintf("jaeger-%s", name)). 36 WithPorts( 37 map[string]int{ 38 "http": 16686, 39 "http.admin": 14269, 40 "jaeger.thrift-model.proto": 14250, 41 "jaeger.thrift": 14268, 42 }). 43 Init(e2e.StartOptions{ 44 Image: "jaegertracing/all-in-one:1.33", 45 Readiness: e2e.NewHTTPReadinessProbe("http.admin", "/", 200, 200), 46 }) 47 newJaeger := e2emon.AsInstrumented(newJaegerRunnable, "http.admin") 48 testutil.Ok(t, e2e.StartAndWaitReady(newJaeger)) 49 50 jaegerConfig, err := yaml.Marshal(client.TracingConfig{ 51 Type: client.Jaeger, 52 Config: jaeger.Config{ 53 ServiceName: "thanos-sidecar", 54 SamplerType: "const", 55 SamplerParam: 1, 56 Endpoint: "http://" + newJaeger.InternalEndpoint("jaeger.thrift") + "/api/traces", 57 }, 58 }) 59 testutil.Ok(t, err) 60 61 prom1, sidecar1 := e2ethanos.NewPrometheusWithJaegerTracingSidecarCustomImage(env, "alone", e2ethanos.DefaultPromConfig("prom-alone", 0, "", "", e2ethanos.LocalPrometheusTarget), "", 62 e2ethanos.DefaultPrometheusImage(), "", e2ethanos.DefaultImage(), string(jaegerConfig), "") 63 testutil.Ok(t, e2e.StartAndWaitReady(prom1, sidecar1)) 64 65 qb := e2ethanos.NewQuerierBuilder(env, "1", sidecar1.InternalEndpoint("grpc")) 66 q := qb.WithTracingConfig(fmt.Sprintf(`type: JAEGER 67 config: 68 sampler_type: const 69 sampler_param: 1 70 service_name: thanos-query 71 endpoint: %s`, "http://"+newJaeger.InternalEndpoint("jaeger.thrift")+"/api/traces")).Init() 72 testutil.Ok(t, e2e.StartAndWaitReady(q)) 73 74 ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute) 75 t.Cleanup(cancel) 76 77 queryAndAssertSeries(t, ctx, q.Endpoint("http"), e2ethanos.QueryUpWithoutInstance, time.Now, promclient.QueryOptions{ 78 Deduplicate: false, 79 }, []model.Metric{ 80 { 81 "job": "myself", 82 "prometheus": "prom-alone", 83 "replica": "0", 84 }, 85 }) 86 87 url := "http://" + strings.TrimSpace(newJaeger.Endpoint("http")+"/api/traces?service=thanos-query&operation=proxy.series") 88 request, err := http.NewRequest("GET", url, nil) 89 testutil.Ok(t, err) 90 client := &http.Client{} 91 92 testutil.Ok(t, runutil.Retry(5*time.Second, ctx.Done(), func() error { 93 response, err := client.Do(request) 94 if err != nil { 95 return err 96 } 97 98 if response.StatusCode != http.StatusOK { 99 return errors.New("status code not OK") 100 } 101 102 defer response.Body.Close() 103 104 body, err := io.ReadAll(response.Body) 105 testutil.Ok(t, err) 106 107 resp := string(body) 108 if strings.Contains(resp, `"data":[]`) { 109 return errors.New("no data returned") 110 } 111 112 testutil.Assert(t, strings.Contains(resp, `"serviceName":"thanos-query"`)) 113 testutil.Assert(t, strings.Contains(resp, `"serviceName":"thanos-sidecar"`)) 114 return nil 115 })) 116 }