MCPcopy
hub / github.com/etcd-io/etcd / testRPCTracing

Function testRPCTracing

tests/integration/tracing_test.go:82–156  ·  view source on GitHub ↗

testRPCTracing is a common test function for both Unary and Stream RPC tracing

(t *testing.T, testName string, filterFunc func(*traceservice.ExportTraceServiceRequest) bool, clientAction func(*clientv3.Client) error)

Source from the content-addressed store, hash-verified

80
81// testRPCTracing is a common test function for both Unary and Stream RPC tracing
82func testRPCTracing(t *testing.T, testName string, filterFunc func(*traceservice.ExportTraceServiceRequest) bool, clientAction func(*clientv3.Client) error) {
83 // set up trace collector
84 listener, err := net.Listen("tcp", "localhost:")
85 require.NoError(t, err)
86
87 traceFound := make(chan struct{})
88 defer close(traceFound)
89
90 srv := grpc.NewServer()
91 traceservice.RegisterTraceServiceServer(srv, &traceServer{
92 traceFound: traceFound,
93 filterFunc: filterFunc,
94 })
95
96 go srv.Serve(listener)
97 defer srv.Stop()
98
99 cfg := integration.NewEmbedConfig(t, "default")
100
101 cfg.EnableDistributedTracing = true
102 cfg.DistributedTracingAddress = listener.Addr().String()
103 cfg.DistributedTracingServiceName = "integration-test-tracing"
104 cfg.DistributedTracingSamplingRatePerMillion = 100
105
106 // start an etcd instance with tracing enabled
107 etcdSrv, err := embed.StartEtcd(cfg)
108 require.NoError(t, err)
109 defer etcdSrv.Close()
110
111 select {
112 case <-etcdSrv.Server.ReadyNotify():
113 case <-time.After(5 * time.Second):
114 // default randomized election timeout is 1 to 2s, single node will fast-forward 900ms
115 // change the timeout from 1 to 5 seconds to ensure de-flaking this test
116 t.Fatalf("failed to start embed.Etcd for test")
117 }
118
119 // create a client that has tracing enabled
120 tracer := sdktrace.NewTracerProvider(sdktrace.WithSampler(sdktrace.AlwaysSample()))
121 defer tracer.Shutdown(context.TODO())
122 tp := trace.TracerProvider(tracer)
123
124 tracingOpts := []otelgrpc.Option{
125 otelgrpc.WithTracerProvider(tp),
126 otelgrpc.WithPropagators(
127 propagation.NewCompositeTextMapPropagator(
128 propagation.TraceContext{},
129 propagation.Baggage{},
130 )),
131 }
132
133 dialOptions := []grpc.DialOption{
134 grpc.WithStatsHandler(otelgrpc.NewClientHandler(tracingOpts...)),
135 }
136 ccfg := clientv3.Config{DialOptions: dialOptions, Endpoints: []string{cfg.AdvertiseClientUrls[0].String()}}
137 cli, err := integration.NewClient(t, ccfg)
138 if err != nil {
139 etcdSrv.Close()

Callers 1

TestTracingFunction · 0.85

Calls 9

CloseMethod · 0.95
AddrMethod · 0.80
StopMethod · 0.65
StringMethod · 0.65
CloseMethod · 0.65
FatalfMethod · 0.65
FatalMethod · 0.65
LogfMethod · 0.65
ReadyNotifyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…