Skip to content

Commit 9e47eb0

Browse files
committed
Add support for OTEL tracing
`crictl` now features 3 new CLI parameters: - `--enable-tracing`: Enable OpenTelemetry tracing. (default: false) - `--tracing-endpoint`: Address to which the gRPC tracing collector will send spans to. (default: "0.0.0.0:4317") - `--tracing-sampling-rate-per-million`: Number of samples to collect per million OpenTelemetry spans. Set to 1000000 or -1 to always sample. (default: -1) The tracer provider will be created on startup and the `Shutdown()` invocation will ensure that all spans are processed before exiting the binary. The `hack/tracing` directory contains scripts for local testing: ``` > ./hack/tracing/start … Everything is ready, open http://localhost:16686 to access jaeger ``` When now running `crictl` with `--enable-tracing`: ``` > sudo ./build/bin/linux/amd64/crictl --enable-tracing ps ``` Then jaeger should show collected traces and spans for the 3 RPCs `ListContainers`, `ImageFsInfo` as well as `Version`. Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
1 parent a6e0a5a commit 9e47eb0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+1215
-383
lines changed

cmd/crictl/main.go

Lines changed: 64 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package main
1818

1919
import (
20+
"context"
2021
"fmt"
2122
"os"
2223
"runtime"
@@ -25,11 +26,15 @@ import (
2526

2627
"github.com/sirupsen/logrus"
2728
"github.com/urfave/cli/v2"
29+
sdktrace "go.opentelemetry.io/otel/sdk/trace"
30+
"go.opentelemetry.io/otel/trace"
31+
"go.opentelemetry.io/otel/trace/noop"
2832

2933
internalapi "k8s.io/cri-api/pkg/apis"
3034
"k8s.io/kubernetes/pkg/kubelet/cri/remote"
3135

3236
"github.com/kubernetes-sigs/cri-tools/pkg/common"
37+
"github.com/kubernetes-sigs/cri-tools/pkg/tracing"
3338
"github.com/kubernetes-sigs/cri-tools/pkg/version"
3439
)
3540

@@ -53,9 +58,11 @@ var (
5358
PullImageOnCreate bool
5459
// DisablePullOnRun disable pulling image on run requests
5560
DisablePullOnRun bool
61+
// tracerProvider is the global OpenTelemetry tracing instance.
62+
tracerProvider *sdktrace.TracerProvider
5663
)
5764

58-
func getRuntimeService(context *cli.Context, timeout time.Duration) (res internalapi.RuntimeService, err error) {
65+
func getRuntimeService(_ *cli.Context, timeout time.Duration) (res internalapi.RuntimeService, err error) {
5966
if RuntimeEndpointIsSet && RuntimeEndpoint == "" {
6067
return nil, fmt.Errorf("--runtime-endpoint is not set")
6168
}
@@ -67,6 +74,13 @@ func getRuntimeService(context *cli.Context, timeout time.Duration) (res interna
6774
t = timeout
6875
}
6976

77+
// Use the noop tracer provider and not tracerProvider directly, otherwise
78+
// we'll panic in the unary call interceptor
79+
var tp trace.TracerProvider = noop.NewTracerProvider()
80+
if tracerProvider != nil {
81+
tp = tracerProvider
82+
}
83+
7084
// If no EP set then use the default endpoint types
7185
if !RuntimeEndpointIsSet {
7286
logrus.Warningf("runtime connect using default endpoints: %v. "+
@@ -79,7 +93,7 @@ func getRuntimeService(context *cli.Context, timeout time.Duration) (res interna
7993
for _, endPoint := range defaultRuntimeEndpoints {
8094
logrus.Debugf("Connect using endpoint %q with %q timeout", endPoint, t)
8195

82-
res, err = remote.NewRemoteRuntimeService(endPoint, t, nil)
96+
res, err = remote.NewRemoteRuntimeService(endPoint, t, tp)
8397
if err != nil {
8498
logrus.Error(err)
8599
continue
@@ -90,10 +104,10 @@ func getRuntimeService(context *cli.Context, timeout time.Duration) (res interna
90104
}
91105
return res, err
92106
}
93-
return remote.NewRemoteRuntimeService(RuntimeEndpoint, t, nil)
107+
return remote.NewRemoteRuntimeService(RuntimeEndpoint, t, tp)
94108
}
95109

96-
func getImageService(context *cli.Context) (res internalapi.ImageManagerService, err error) {
110+
func getImageService(*cli.Context) (res internalapi.ImageManagerService, err error) {
97111
if ImageEndpoint == "" {
98112
if RuntimeEndpointIsSet && RuntimeEndpoint == "" {
99113
return nil, fmt.Errorf("--image-endpoint is not set")
@@ -103,6 +117,14 @@ func getImageService(context *cli.Context) (res internalapi.ImageManagerService,
103117
}
104118

105119
logrus.Debugf("get image connection")
120+
121+
// Use the noop tracer provider and not tracerProvider directly, otherwise
122+
// we'll panic in the unary call interceptor
123+
var tp trace.TracerProvider = noop.NewTracerProvider()
124+
if tracerProvider != nil {
125+
tp = tracerProvider
126+
}
127+
106128
// If no EP set then use the default endpoint types
107129
if !ImageEndpointIsSet {
108130
logrus.Warningf("image connect using default endpoints: %v. "+
@@ -115,7 +137,7 @@ func getImageService(context *cli.Context) (res internalapi.ImageManagerService,
115137
for _, endPoint := range defaultRuntimeEndpoints {
116138
logrus.Debugf("Connect using endpoint %q with %q timeout", endPoint, Timeout)
117139

118-
res, err = remote.NewRemoteImageService(endPoint, Timeout, nil)
140+
res, err = remote.NewRemoteImageService(endPoint, Timeout, tp)
119141
if err != nil {
120142
logrus.Error(err)
121143
continue
@@ -126,7 +148,7 @@ func getImageService(context *cli.Context) (res internalapi.ImageManagerService,
126148
}
127149
return res, err
128150
}
129-
return remote.NewRemoteImageService(ImageEndpoint, Timeout, nil)
151+
return remote.NewRemoteImageService(ImageEndpoint, Timeout, tp)
130152
}
131153

132154
func getTimeout(timeDuration time.Duration) time.Duration {
@@ -220,6 +242,20 @@ func main() {
220242
Aliases: []string{"D"},
221243
Usage: "Enable debug mode",
222244
},
245+
&cli.BoolFlag{
246+
Name: "enable-tracing",
247+
Usage: "Enable OpenTelemetry tracing.",
248+
},
249+
&cli.IntFlag{
250+
Name: "tracing-sampling-rate-per-million",
251+
Usage: "Number of samples to collect per million OpenTelemetry spans. Set to 1000000 or -1 to always sample.",
252+
Value: -1,
253+
},
254+
&cli.StringFlag{
255+
Name: "tracing-endpoint",
256+
Usage: "Address to which the gRPC tracing collector will send spans to.",
257+
Value: "0.0.0.0:4317",
258+
},
223259
}
224260

225261
app.Before = func(context *cli.Context) (err error) {
@@ -290,6 +326,19 @@ func main() {
290326
if Debug {
291327
logrus.SetLevel(logrus.DebugLevel)
292328
}
329+
330+
// Configure tracing if enabled
331+
if context.IsSet("enable-tracing") {
332+
tracerProvider, err = tracing.Init(
333+
context.Context,
334+
context.String("tracing-endpoint"),
335+
context.Int("tracing-sampling-rate-per-million"),
336+
)
337+
if err != nil {
338+
return fmt.Errorf("init tracing: %w", err)
339+
}
340+
}
341+
293342
return nil
294343
}
295344
// sort all flags
@@ -301,4 +350,13 @@ func main() {
301350
if err := app.Run(os.Args); err != nil {
302351
logrus.Fatal(err)
303352
}
353+
354+
// Ensure that all spans are processed.
355+
if tracerProvider != nil {
356+
ctx, cancel := context.WithTimeout(context.Background(), Timeout)
357+
defer cancel()
358+
if err := tracerProvider.Shutdown(ctx); err != nil {
359+
logrus.Errorf("Unable to shutdown tracer provider: %v", err)
360+
}
361+
}
304362
}

go.mod

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ require (
1616
github.com/opencontainers/selinux v1.11.0
1717
github.com/sirupsen/logrus v1.9.3
1818
github.com/urfave/cli/v2 v2.26.0
19+
go.opentelemetry.io/otel v1.21.0
20+
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.21.0
21+
go.opentelemetry.io/otel/sdk v1.21.0
22+
go.opentelemetry.io/otel/trace v1.21.0
1923
golang.org/x/net v0.19.0
2024
golang.org/x/sys v0.15.0
2125
golang.org/x/term v0.15.0
@@ -77,21 +81,17 @@ require (
7781
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
7882
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.42.0 // indirect
7983
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.44.0 // indirect
80-
go.opentelemetry.io/otel v1.19.0 // indirect
81-
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.19.0 // indirect
82-
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.19.0 // indirect
83-
go.opentelemetry.io/otel/metric v1.19.0 // indirect
84-
go.opentelemetry.io/otel/sdk v1.19.0 // indirect
85-
go.opentelemetry.io/otel/trace v1.19.0 // indirect
84+
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.21.0 // indirect
85+
go.opentelemetry.io/otel/metric v1.21.0 // indirect
8686
go.opentelemetry.io/proto/otlp v1.0.0 // indirect
8787
golang.org/x/mod v0.13.0 // indirect
88-
golang.org/x/oauth2 v0.10.0 // indirect
88+
golang.org/x/oauth2 v0.11.0 // indirect
8989
golang.org/x/time v0.3.0 // indirect
9090
golang.org/x/tools v0.14.0 // indirect
9191
google.golang.org/appengine v1.6.7 // indirect
92-
google.golang.org/genproto/googleapis/api v0.0.0-20230726155614-23370e0ffb3e // indirect
92+
google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d // indirect
9393
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect
94-
google.golang.org/grpc v1.58.3 // indirect
94+
google.golang.org/grpc v1.59.0 // indirect
9595
google.golang.org/protobuf v1.31.0 // indirect
9696
gopkg.in/inf.v0 v0.9.1 // indirect
9797
gopkg.in/yaml.v2 v2.4.0 // indirect

go.sum

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEe
6060
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls=
6161
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
6262
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
63-
github.com/golang/glog v1.1.0 h1:/d3pCKDPWNnvIWe0vVUpNP32qc8U3PDVxySP/y360qE=
64-
github.com/golang/glog v1.1.0/go.mod h1:pfYeQZ3JWZoXTV5sFc986z3HTpwQs9At6P4ImfuP3NQ=
63+
github.com/golang/glog v1.1.2 h1:DVjP2PbBOzHyzA+dn3WhHIq4NdVu3Q+pvivFICf/7fo=
64+
github.com/golang/glog v1.1.2/go.mod h1:zR+okUeTbrL6EL3xHUDxZuEtGv04p5shwip1+mL/rLQ=
6565
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
6666
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
6767
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
@@ -169,22 +169,22 @@ go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.4
169169
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.42.0/go.mod h1:5z+/ZWJQKXa9YT34fQNx5K8Hd1EoIhvtUygUQPqEOgQ=
170170
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.44.0 h1:KfYpVmrjI7JuToy5k8XV3nkapjWx48k4E4JOtVstzQI=
171171
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.44.0/go.mod h1:SeQhzAEccGVZVEy7aH87Nh0km+utSpo1pTv6eMMop48=
172-
go.opentelemetry.io/otel v1.19.0 h1:MuS/TNf4/j4IXsZuJegVzI1cwut7Qc00344rgH7p8bs=
173-
go.opentelemetry.io/otel v1.19.0/go.mod h1:i0QyjOq3UPoTzff0PJB2N66fb4S0+rSbSB15/oyH9fY=
174-
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.19.0 h1:Mne5On7VWdx7omSrSSZvM4Kw7cS7NQkOOmLcgscI51U=
175-
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.19.0/go.mod h1:IPtUMKL4O3tH5y+iXVyAXqpAwMuzC1IrxVS81rummfE=
176-
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.19.0 h1:3d+S281UTjM+AbF31XSOYn1qXn3BgIdWl8HNEpx08Jk=
177-
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.19.0/go.mod h1:0+KuTDyKL4gjKCF75pHOX4wuzYDUZYfAQdSu43o+Z2I=
178-
go.opentelemetry.io/otel/metric v1.19.0 h1:aTzpGtV0ar9wlV4Sna9sdJyII5jTVJEvKETPiOKwvpE=
179-
go.opentelemetry.io/otel/metric v1.19.0/go.mod h1:L5rUsV9kM1IxCj1MmSdS+JQAcVm319EUrDVLrt7jqt8=
180-
go.opentelemetry.io/otel/sdk v1.19.0 h1:6USY6zH+L8uMH8L3t1enZPR3WFEmSTADlqldyHtJi3o=
181-
go.opentelemetry.io/otel/sdk v1.19.0/go.mod h1:NedEbbS4w3C6zElbLdPJKOpJQOrGUJ+GfzpjUvI0v1A=
182-
go.opentelemetry.io/otel/trace v1.19.0 h1:DFVQmlVbfVeOuBRrwdtaehRrWiL1JoVs9CPIQ1Dzxpg=
183-
go.opentelemetry.io/otel/trace v1.19.0/go.mod h1:mfaSyvGyEJEI0nyV2I4qhNQnbBOUUmYZpYojqMnX2vo=
172+
go.opentelemetry.io/otel v1.21.0 h1:hzLeKBZEL7Okw2mGzZ0cc4k/A7Fta0uoPgaJCr8fsFc=
173+
go.opentelemetry.io/otel v1.21.0/go.mod h1:QZzNPQPm1zLX4gZK4cMi+71eaorMSGT3A4znnUvNNEo=
174+
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.21.0 h1:cl5P5/GIfFh4t6xyruOgJP5QiA1pw4fYYdv6nc6CBWw=
175+
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.21.0/go.mod h1:zgBdWWAu7oEEMC06MMKc5NLbA/1YDXV1sMpSqEeLQLg=
176+
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.21.0 h1:tIqheXEFWAZ7O8A7m+J0aPTmpJN3YQ7qetUAdkkkKpk=
177+
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.21.0/go.mod h1:nUeKExfxAQVbiVFn32YXpXZZHZ61Cc3s3Rn1pDBGAb0=
178+
go.opentelemetry.io/otel/metric v1.21.0 h1:tlYWfeo+Bocx5kLEloTjbcDwBuELRrIFxwdQ36PlJu4=
179+
go.opentelemetry.io/otel/metric v1.21.0/go.mod h1:o1p3CA8nNHW8j5yuQLdc1eeqEaPfzug24uvsyIEJRWM=
180+
go.opentelemetry.io/otel/sdk v1.21.0 h1:FTt8qirL1EysG6sTQRZ5TokkU8d0ugCj8htOgThZXQ8=
181+
go.opentelemetry.io/otel/sdk v1.21.0/go.mod h1:Nna6Yv7PWTdgJHVRD9hIYywQBRx7pbox6nwBnZIxl/E=
182+
go.opentelemetry.io/otel/trace v1.21.0 h1:WD9i5gzvoUPuXIXH24ZNBudiarZDKuekPqi/E8fpfLc=
183+
go.opentelemetry.io/otel/trace v1.21.0/go.mod h1:LGbsEB0f9LGjN+OZaQQ26sohbOmiMR+BaslueVtS/qQ=
184184
go.opentelemetry.io/proto/otlp v1.0.0 h1:T0TX0tmXU8a3CbNXzEKGeU5mIVOdf0oykP+u2lIVU/I=
185185
go.opentelemetry.io/proto/otlp v1.0.0/go.mod h1:Sy6pihPLfYHkr3NkUbEhGHFhINUSI/v80hjKIs5JXpM=
186-
go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A=
187-
go.uber.org/goleak v1.2.1/go.mod h1:qlT2yGI9QafXHhZZLxlSuNsMw3FFLxBr+tBRlmO1xH4=
186+
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
187+
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
188188
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
189189
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
190190
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
@@ -199,8 +199,8 @@ golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLL
199199
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
200200
golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c=
201201
golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U=
202-
golang.org/x/oauth2 v0.10.0 h1:zHCpF2Khkwy4mMB4bv0U37YtJdTGW8jI0glAApi0Kh8=
203-
golang.org/x/oauth2 v0.10.0/go.mod h1:kTpgurOux7LqtuxjuyZa4Gj2gdezIt/jQtGnNFfypQI=
202+
golang.org/x/oauth2 v0.11.0 h1:vPL4xzxBM4niKCW6g9whtaWVXTJf1U5e4aZxxFx/gbU=
203+
golang.org/x/oauth2 v0.11.0/go.mod h1:LdF7O/8bLR/qWK9DrpXmbHLTouvRHK0SgJl0GmDBchk=
204204
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
205205
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
206206
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -236,14 +236,14 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8T
236236
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
237237
google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c=
238238
google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
239-
google.golang.org/genproto v0.0.0-20230803162519-f966b187b2e5 h1:L6iMMGrtzgHsWofoFcihmDEMYeDR9KN/ThbPWGrh++g=
240-
google.golang.org/genproto v0.0.0-20230803162519-f966b187b2e5/go.mod h1:oH/ZOT02u4kWEp7oYBGYFFkCdKS/uYR9Z7+0/xuuFp8=
241-
google.golang.org/genproto/googleapis/api v0.0.0-20230726155614-23370e0ffb3e h1:z3vDksarJxsAKM5dmEGv0GHwE2hKJ096wZra71Vs4sw=
242-
google.golang.org/genproto/googleapis/api v0.0.0-20230726155614-23370e0ffb3e/go.mod h1:rsr7RhLuwsDKL7RmgDDCUc6yaGr1iqceVb5Wv6f6YvQ=
239+
google.golang.org/genproto v0.0.0-20230822172742-b8732ec3820d h1:VBu5YqKPv6XiJ199exd8Br+Aetz+o08F+PLMnwJQHAY=
240+
google.golang.org/genproto v0.0.0-20230822172742-b8732ec3820d/go.mod h1:yZTlhN0tQnXo3h00fuXNCxJdLdIdnVFVBaRJ5LWBbw4=
241+
google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d h1:DoPTO70H+bcDXcd39vOqb2viZxgqeBeSGtZ55yZU4/Q=
242+
google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d/go.mod h1:KjSP20unUpOx5kyQUFa7k4OJg0qeJ7DEZflGDu2p6Bk=
243243
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d h1:uvYuEyMHKNt+lT4K3bN6fGswmK8qSvcreM3BwjDh+y4=
244244
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d/go.mod h1:+Bk1OCOj40wS2hwAMA+aCW9ypzm63QTBBHp6lQ3p+9M=
245-
google.golang.org/grpc v1.58.3 h1:BjnpXut1btbtgN/6sp+brB2Kbm2LjNXnidYujAVbSoQ=
246-
google.golang.org/grpc v1.58.3/go.mod h1:tgX3ZQDlNJGU96V6yHh1T/JeoBQ2TXdr43YbYSsCJk0=
245+
google.golang.org/grpc v1.59.0 h1:Z5Iec2pjwb+LEOqzpB2MR12/eKFhDPhuqW91O+4bwUk=
246+
google.golang.org/grpc v1.59.0/go.mod h1:aUPDwccQo6OTjy7Hct4AfBPD1GptF4fyUjIkQ9YtF98=
247247
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
248248
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
249249
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=

hack/tracing/env

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env bash
2+
set -uo pipefail
3+
4+
cd "$(dirname "$0")"
5+
6+
CONTAINER_RUNTIME=$(which podman 2>/dev/null) || CONTAINER_RUNTIME=$(which docker 2>/dev/null)
7+
if [[ -z "$CONTAINER_RUNTIME" ]]; then
8+
echo "Neither docker nor podman found in \$PATH"
9+
exit 1
10+
fi
11+
12+
set -e
13+
14+
export OTLP_CTR=otlp
15+
export JAEGER_CTR=jaeger
16+
export CONTAINER_RUNTIME

hack/tracing/logs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
set -uo pipefail
3+
4+
# Global vars to be used
5+
# shellcheck source=env
6+
source "$(dirname "${BASH_SOURCE[0]}")"/env
7+
8+
"$CONTAINER_RUNTIME" logs "$OTLP_CTR" 2>&1
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
receivers:
2+
otlp:
3+
protocols:
4+
http:
5+
grpc:
6+
7+
exporters:
8+
logging:
9+
loglevel: debug
10+
11+
jaeger:
12+
endpoint: localhost:14250
13+
tls:
14+
insecure: true
15+
16+
processors:
17+
batch:
18+
19+
extensions:
20+
health_check:
21+
pprof:
22+
endpoint: :1888
23+
zpages:
24+
endpoint: :55679
25+
26+
service:
27+
extensions: [pprof, zpages, health_check]
28+
pipelines:
29+
traces:
30+
receivers: [otlp]
31+
processors: [batch]
32+
exporters: [logging, jaeger]
33+
metrics:
34+
receivers: [otlp]
35+
processors: [batch]
36+
exporters: [logging]

hack/tracing/start

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env bash
2+
set -uo pipefail
3+
4+
# Global vars to be used
5+
# shellcheck source=stop
6+
source "$(dirname "${BASH_SOURCE[0]}")"/stop
7+
8+
JAEGER_IMG="jaegertracing/all-in-one:1.41.0"
9+
OTLP_IMG="otel/opentelemetry-collector:0.70.0"
10+
11+
echo "Starting $JAEGER_CTR"
12+
"$CONTAINER_RUNTIME" run -d --rm --network host --name "$JAEGER_CTR" "$JAEGER_IMG"
13+
14+
PORT=14250
15+
MAX_CNT=100
16+
for ((i = 0; i <= "$MAX_CNT"; i++)); do
17+
if netstat -tuplen 2>/dev/null | grep -q "$PORT .* LISTEN"; then
18+
break
19+
fi
20+
21+
if [[ $i == "$MAX_CNT" ]]; then
22+
echo "Giving up"
23+
exit 1
24+
fi
25+
26+
echo "Waiting for gRPC port $PORT to listen… ($i)"
27+
sleep 3
28+
done
29+
30+
echo "Starting $OTLP_CTR"
31+
"$CONTAINER_RUNTIME" run -d --rm --network host --name "$OTLP_CTR" \
32+
-v ./otel-collector-config.yaml:/etc/otel-collector-config.yaml \
33+
"$OTLP_IMG" --config=/etc/otel-collector-config.yaml
34+
35+
for ((i = 0; i <= "$MAX_CNT"; i++)); do
36+
if ./logs | grep -q '"jaeger", "state": "READY"'; then
37+
break
38+
fi
39+
40+
if [[ $i == "$MAX_CNT" ]]; then
41+
echo "Giving up"
42+
exit 1
43+
fi
44+
45+
echo "Waiting for OTLP to become ready… ($i)"
46+
sleep 3
47+
done
48+
49+
echo "Everything is ready, open http://localhost:16686 to access jaeger"

0 commit comments

Comments
 (0)