Skip to content

Commit 2c674dd

Browse files
authored
Merge pull request #1403 from DataDog/fricounet/upstream/otel-tracing
Add opentelemetry tracing on gRPC calls for self-managed drivers
2 parents 4422ff9 + 99c130e commit 2c674dd

File tree

238 files changed

+46564
-9
lines changed

Some content is hidden

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

238 files changed

+46564
-9
lines changed

cmd/gce-pd-csi-driver/main.go

+18-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ var (
4343
httpEndpoint = flag.String("http-endpoint", "", "The TCP network address where the prometheus metrics endpoint will listen (example: `:8080`). The default is empty string, which means metrics endpoint is disabled.")
4444
metricsPath = flag.String("metrics-path", "/metrics", "The HTTP path where prometheus metrics will be exposed. Default is `/metrics`.")
4545
grpcLogCharCap = flag.Int("grpc-log-char-cap", 10000, "The maximum amount of characters logged for every grpc responses")
46+
enableOtelTracing = flag.Bool("enable-otel-tracing", false, "If set, enable opentelemetry tracing for the driver. The tracing is disabled by default. Configure the exporter endpoint with OTEL_EXPORTER_OTLP_ENDPOINT and other env variables, see https://opentelemetry.io/docs/specs/otel/configuration/sdk-environment-variables/#general-sdk-configuration.")
4647

4748
errorBackoffInitialDurationMs = flag.Int("backoff-initial-duration-ms", 200, "The amount of ms for the initial duration of the backoff condition for controller publish/unpublish CSI operations. Default is 200.")
4849
errorBackoffMaxDurationMs = flag.Int("backoff-max-duration-ms", 300000, "The amount of ms for the max duration of the backoff condition for controller publish/unpublish CSI operations. Default is 300000 (5m).")
@@ -101,6 +102,22 @@ func handle() {
101102
}
102103
klog.V(2).Infof("Driver vendor version %v", version)
103104

105+
// Start tracing as soon as possible
106+
if *enableOtelTracing {
107+
exporter, err := driver.InitOtelTracing()
108+
if err != nil {
109+
klog.Fatalf("Failed to initialize otel tracing: %v", err.Error())
110+
}
111+
// Exporter will flush traces on shutdown
112+
defer func() {
113+
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
114+
defer cancel()
115+
if err := exporter.Shutdown(ctx); err != nil {
116+
klog.Errorf("Could not shutdown otel exporter: %v", err.Error())
117+
}
118+
}()
119+
}
120+
104121
if *runControllerService && *httpEndpoint != "" {
105122
mm := metrics.NewMetricsManager()
106123
mm.InitializeHttpHandler(*httpEndpoint, *metricsPath)
@@ -178,5 +195,5 @@ func handle() {
178195
gce.WaitForOpBackoff.Steps = *waitForOpBackoffSteps
179196
gce.WaitForOpBackoff.Cap = *waitForOpBackoffCap
180197

181-
gceDriver.Run(*endpoint, *grpcLogCharCap)
198+
gceDriver.Run(*endpoint, *grpcLogCharCap, *enableOtelTracing)
182199
}

go.mod

+11
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ require (
1313
github.com/kubernetes-csi/csi-test/v4 v4.4.0
1414
github.com/onsi/ginkgo/v2 v2.13.2
1515
github.com/onsi/gomega v1.30.0
16+
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.46.1
17+
go.opentelemetry.io/otel v1.21.0
18+
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.21.0
19+
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.21.0
20+
go.opentelemetry.io/otel/sdk v1.21.0
1621
golang.org/x/oauth2 v0.15.0
1722
golang.org/x/sys v0.15.0
1823
google.golang.org/api v0.151.0
@@ -39,11 +44,13 @@ require (
3944
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
4045
github.com/beorn7/perks v1.0.1 // indirect
4146
github.com/blang/semver/v4 v4.0.0 // indirect
47+
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
4248
github.com/cespare/xxhash/v2 v2.2.0 // indirect
4349
github.com/davecgh/go-spew v1.1.1 // indirect
4450
github.com/emicklei/go-restful v2.9.5+incompatible // indirect
4551
github.com/fsnotify/fsnotify v1.5.4 // indirect
4652
github.com/go-logr/logr v1.3.0 // indirect
53+
github.com/go-logr/stdr v1.2.2 // indirect
4754
github.com/go-openapi/jsonpointer v0.20.0 // indirect
4855
github.com/go-openapi/jsonreference v0.19.6 // indirect
4956
github.com/go-openapi/swag v0.22.4 // indirect
@@ -58,6 +65,7 @@ require (
5865
github.com/google/s2a-go v0.1.7 // indirect
5966
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
6067
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
68+
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect
6169
github.com/hashicorp/errwrap v1.0.0 // indirect
6270
github.com/hashicorp/go-multierror v1.1.0 // indirect
6371
github.com/imdario/mergo v0.3.12 // indirect
@@ -79,6 +87,9 @@ require (
7987
github.com/sirupsen/logrus v1.9.0 // indirect
8088
github.com/spf13/pflag v1.0.5 // indirect
8189
go.opencensus.io v0.24.0 // indirect
90+
go.opentelemetry.io/otel/metric v1.21.0 // indirect
91+
go.opentelemetry.io/otel/trace v1.21.0 // indirect
92+
go.opentelemetry.io/proto/otlp v1.0.0 // indirect
8293
go4.org v0.0.0-20201209231011-d4a079459e60 // indirect
8394
golang.org/x/crypto v0.16.0 // indirect
8495
golang.org/x/mod v0.14.0 // indirect

go.sum

+27
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,8 @@ github.com/bwmarrin/snowflake v0.0.0/go.mod h1:NdZxfVWX+oR6y2K0o6qAYv6gIOP9rjG0/
848848
github.com/caarlos0/ctrlc v1.0.0/go.mod h1:CdXpj4rmq0q/1Eb44M9zi2nKB0QraNKuRGYGrrHhcQw=
849849
github.com/campoy/unique v0.0.0-20180121183637-88950e537e7e/go.mod h1:9IOqJGCPMSc6E5ydlp5NIonxObaeu/Iub/X03EKPVYo=
850850
github.com/cavaliercoder/go-cpio v0.0.0-20180626203310-925f9528c45e/go.mod h1:oDpT4efm8tSYHXV5tHSdRvBet/b/QzxZ+XyyPehvm3A=
851+
github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM=
852+
github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
851853
github.com/census-instrumentation/opencensus-proto v0.2.0/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
852854
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
853855
github.com/census-instrumentation/opencensus-proto v0.3.0/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
@@ -881,6 +883,7 @@ github.com/cncf/xds/go v0.0.0-20211001041855-01bcc9b48dfe/go.mod h1:eXthEFrGJvWH
881883
github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
882884
github.com/cncf/xds/go v0.0.0-20220314180256-7f1daf1720fc/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
883885
github.com/cncf/xds/go v0.0.0-20230105202645-06c439db220b/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
886+
github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4 h1:/inchEIKaYC1Akx+H+gqO04wryn5h75LSazbRlnya1k=
884887
github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8=
885888
github.com/cockroachdb/datadriven v0.0.0-20200714090401-bf6692d28da5/go.mod h1:h6jFvWxBdQXxjopDMZyH2UVceIRfR84bdzbkoKrsWNo=
886889
github.com/cockroachdb/errors v1.2.4/go.mod h1:rQD95gz6FARkaKkQXUksEje/d9a6wBJoCr5oaCLELYA=
@@ -990,6 +993,7 @@ github.com/envoyproxy/go-control-plane v0.10.3/go.mod h1:fJJn/j26vwOu972OllsvAgJ
990993
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
991994
github.com/envoyproxy/protoc-gen-validate v0.6.7/go.mod h1:dyJXwwfPK2VSqiB9Klm1J6romD608Ba7Hij42vrOBCo=
992995
github.com/envoyproxy/protoc-gen-validate v0.9.1/go.mod h1:OKNgG7TCp5pF4d6XftA0++PMirau2/yoOwVac3AbF2w=
996+
github.com/envoyproxy/protoc-gen-validate v1.0.2 h1:QkIBuU5k+x7/QXPvPPnWXWlCdaBFApVqftFV6k087DA=
993997
github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5/go.mod h1:a2zkGnVExMxdzMo3M0Hi/3sEU+cWnZpSni0O6/Yb/P0=
994998
github.com/evanphx/json-patch v0.0.0-20190203023257-5858425f7550/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
995999
github.com/evanphx/json-patch v0.5.2/go.mod h1:ZWS5hhDbVDyob71nXKNL0+PWn6ToqBHMikGIFbs31qQ=
@@ -1058,8 +1062,11 @@ github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7
10581062
github.com/go-logr/logr v0.2.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU=
10591063
github.com/go-logr/logr v0.4.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU=
10601064
github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
1065+
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
10611066
github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY=
10621067
github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
1068+
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
1069+
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
10631070
github.com/go-logr/zapr v0.1.0/go.mod h1:tabnROwaDl0UNxkVeFRbY8bwB37GwRv0P8lg6aAiEnk=
10641071
github.com/go-logr/zapr v0.1.1/go.mod h1:tabnROwaDl0UNxkVeFRbY8bwB37GwRv0P8lg6aAiEnk=
10651072
github.com/go-logr/zapr v0.4.0/go.mod h1:tabnROwaDl0UNxkVeFRbY8bwB37GwRv0P8lg6aAiEnk=
@@ -1263,6 +1270,7 @@ github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGw
12631270
github.com/golang/gddo v0.0.0-20190419222130-af0f2af80721/go.mod h1:xEhNfoBDX1hzLm2Nf80qUvZ2sVwoMZ8d6IE2SrsQfh4=
12641271
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
12651272
github.com/golang/glog v1.0.0/go.mod h1:EWib/APOK0SL3dFbYqvxE3UYd8E6s1ouQ7iEp/0LWV4=
1273+
github.com/golang/glog v1.1.2 h1:DVjP2PbBOzHyzA+dn3WhHIq4NdVu3Q+pvivFICf/7fo=
12661274
github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
12671275
github.com/golang/groupcache v0.0.0-20180513044358-24b0969c4cb7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
12681276
github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
@@ -1499,6 +1507,8 @@ github.com/grpc-ecosystem/grpc-gateway v1.12.2/go.mod h1:8XEsbTttt/W+VvjtQhLACqC
14991507
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
15001508
github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0/go.mod h1:hgWBS7lorOAVIJEQMi4ZsPv9hVvWI6+ch50m39Pf2Ks=
15011509
github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3/go.mod h1:o//XUCC/F+yRGJoPO/VU0GSB0f8Nhgmxx0VIRUvaC0w=
1510+
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 h1:YBftPWNWd4WwGqtY2yeZL2ef8rHAxPBD8KFhJpmcqms=
1511+
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0/go.mod h1:YN5jB8ie0yfIUg6VvR9Kz84aCaG7AsGZnLjhHbUqwPg=
15021512
github.com/h2non/gock v1.0.9/go.mod h1:CZMcB0Lg5IWnr9bF79pPMg9WeV6WumxQiUJ1UvdO1iE=
15031513
github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q=
15041514
github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8=
@@ -2178,17 +2188,33 @@ go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0=
21782188
go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo=
21792189
go.opentelemetry.io/contrib v0.20.0/go.mod h1:G/EtFaa6qaN7+LxqfIAT3GiZa7Wv5DTBUzl5H4LY0Kc=
21802190
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.20.0/go.mod h1:oVGt1LRbBOBq1A5BQLlUg9UaU/54aiHw8cgjV3aWZ/E=
2191+
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.46.1 h1:SpGay3w+nEwMpfVnbqOLH5gY52/foP8RE8UzTZ1pdSE=
2192+
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.46.1/go.mod h1:4UoMYEZOC0yN/sPGH76KPkkU7zgiEWYWL9vwmbnTJPE=
21812193
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.20.0/go.mod h1:2AboqHi0CiIZU0qwhtUfCYD1GeUzvvIXWNkhDt7ZMG4=
21822194
go.opentelemetry.io/otel v0.20.0/go.mod h1:Y3ugLH2oa81t5QO+Lty+zXf8zC9L26ax4Nzoxm/dooo=
2195+
go.opentelemetry.io/otel v1.21.0 h1:hzLeKBZEL7Okw2mGzZ0cc4k/A7Fta0uoPgaJCr8fsFc=
2196+
go.opentelemetry.io/otel v1.21.0/go.mod h1:QZzNPQPm1zLX4gZK4cMi+71eaorMSGT3A4znnUvNNEo=
21832197
go.opentelemetry.io/otel/exporters/otlp v0.20.0/go.mod h1:YIieizyaN77rtLJra0buKiNBOm9XQfkPEKBeuhoMwAM=
2198+
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.21.0 h1:cl5P5/GIfFh4t6xyruOgJP5QiA1pw4fYYdv6nc6CBWw=
2199+
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.21.0/go.mod h1:zgBdWWAu7oEEMC06MMKc5NLbA/1YDXV1sMpSqEeLQLg=
2200+
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.21.0 h1:tIqheXEFWAZ7O8A7m+J0aPTmpJN3YQ7qetUAdkkkKpk=
2201+
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.21.0/go.mod h1:nUeKExfxAQVbiVFn32YXpXZZHZ61Cc3s3Rn1pDBGAb0=
21842202
go.opentelemetry.io/otel/metric v0.20.0/go.mod h1:598I5tYlH1vzBjn+BTuhzTCSb/9debfNp6R3s7Pr1eU=
2203+
go.opentelemetry.io/otel/metric v1.21.0 h1:tlYWfeo+Bocx5kLEloTjbcDwBuELRrIFxwdQ36PlJu4=
2204+
go.opentelemetry.io/otel/metric v1.21.0/go.mod h1:o1p3CA8nNHW8j5yuQLdc1eeqEaPfzug24uvsyIEJRWM=
21852205
go.opentelemetry.io/otel/oteltest v0.20.0/go.mod h1:L7bgKf9ZB7qCwT9Up7i9/pn0PWIa9FqQ2IQ8LoxiGnw=
21862206
go.opentelemetry.io/otel/sdk v0.20.0/go.mod h1:g/IcepuwNsoiX5Byy2nNV0ySUF1em498m7hBWC279Yc=
2207+
go.opentelemetry.io/otel/sdk v1.21.0 h1:FTt8qirL1EysG6sTQRZ5TokkU8d0ugCj8htOgThZXQ8=
2208+
go.opentelemetry.io/otel/sdk v1.21.0/go.mod h1:Nna6Yv7PWTdgJHVRD9hIYywQBRx7pbox6nwBnZIxl/E=
21872209
go.opentelemetry.io/otel/sdk/export/metric v0.20.0/go.mod h1:h7RBNMsDJ5pmI1zExLi+bJK+Dr8NQCh0qGhm1KDnNlE=
21882210
go.opentelemetry.io/otel/sdk/metric v0.20.0/go.mod h1:knxiS8Xd4E/N+ZqKmUPf3gTTZ4/0TjTXukfxjzSTpHE=
21892211
go.opentelemetry.io/otel/trace v0.20.0/go.mod h1:6GjCW8zgDjwGHGa6GkyeB8+/5vjT16gUEi0Nf1iBdgw=
2212+
go.opentelemetry.io/otel/trace v1.21.0 h1:WD9i5gzvoUPuXIXH24ZNBudiarZDKuekPqi/E8fpfLc=
2213+
go.opentelemetry.io/otel/trace v1.21.0/go.mod h1:LGbsEB0f9LGjN+OZaQQ26sohbOmiMR+BaslueVtS/qQ=
21902214
go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
21912215
go.opentelemetry.io/proto/otlp v0.15.0/go.mod h1:H7XAot3MsfNsj7EXtrA2q5xSNQ10UqI405h3+duxN4U=
2216+
go.opentelemetry.io/proto/otlp v1.0.0 h1:T0TX0tmXU8a3CbNXzEKGeU5mIVOdf0oykP+u2lIVU/I=
2217+
go.opentelemetry.io/proto/otlp v1.0.0/go.mod h1:Sy6pihPLfYHkr3NkUbEhGHFhINUSI/v80hjKIs5JXpM=
21922218
go.uber.org/atomic v0.0.0-20181018215023-8dc6146f7569/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
21932219
go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
21942220
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
@@ -2197,6 +2223,7 @@ go.uber.org/atomic v1.5.1/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
21972223
go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
21982224
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
21992225
go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A=
2226+
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
22002227
go.uber.org/multierr v0.0.0-20180122172545-ddea229ff1df/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
22012228
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
22022229
go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4=

pkg/gce-pd-csi-driver/gce-pd-driver.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,12 @@ func NewControllerServer(gceDriver *GCEDriver, cloudProvider gce.GCECompute, err
162162
}
163163
}
164164

165-
func (gceDriver *GCEDriver) Run(endpoint string, grpcLogCharCap int) {
165+
func (gceDriver *GCEDriver) Run(endpoint string, grpcLogCharCap int, enableOtelTracing bool) {
166166
maxLogChar = grpcLogCharCap
167167

168168
klog.V(4).Infof("Driver: %v", gceDriver.name)
169169
//Start the nonblocking GRPC
170-
s := NewNonBlockingGRPCServer()
170+
s := NewNonBlockingGRPCServer(enableOtelTracing)
171171
// TODO(#34): Only start specific servers based on a flag.
172172
// In the future have this only run specific combinations of servers depending on which version this is.
173173
// The schema for that was in util. basically it was just s.start but with some nil servers.

pkg/gce-pd-csi-driver/server.go

+12-5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"path/filepath"
2222
"sync"
2323

24+
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
2425
"google.golang.org/grpc"
2526
"k8s.io/klog/v2"
2627

@@ -39,14 +40,15 @@ type NonBlockingGRPCServer interface {
3940
ForceStop()
4041
}
4142

42-
func NewNonBlockingGRPCServer() NonBlockingGRPCServer {
43-
return &nonBlockingGRPCServer{}
43+
func NewNonBlockingGRPCServer(enableOtelTracing bool) NonBlockingGRPCServer {
44+
return &nonBlockingGRPCServer{otelTracing: enableOtelTracing}
4445
}
4546

4647
// NonBlocking server
4748
type nonBlockingGRPCServer struct {
48-
wg sync.WaitGroup
49-
server *grpc.Server
49+
wg sync.WaitGroup
50+
server *grpc.Server
51+
otelTracing bool
5052
}
5153

5254
func (s *nonBlockingGRPCServer) Start(endpoint string, ids csi.IdentityServer, cs csi.ControllerServer, ns csi.NodeServer) {
@@ -71,8 +73,13 @@ func (s *nonBlockingGRPCServer) ForceStop() {
7173
}
7274

7375
func (s *nonBlockingGRPCServer) serve(endpoint string, ids csi.IdentityServer, cs csi.ControllerServer, ns csi.NodeServer) {
76+
grpcInterceptor := grpc.UnaryInterceptor(logGRPC)
77+
if s.otelTracing {
78+
grpcInterceptor = grpc.ChainUnaryInterceptor(logGRPC, otelgrpc.UnaryServerInterceptor())
79+
}
80+
7481
opts := []grpc.ServerOption{
75-
grpc.UnaryInterceptor(logGRPC),
82+
grpcInterceptor,
7683
}
7784

7885
u, err := url.Parse(endpoint)

pkg/gce-pd-csi-driver/trace.go

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
Copyright 2023 The Kubernetes Authors.
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
14+
package gceGCEDriver
15+
16+
import (
17+
"context"
18+
"fmt"
19+
20+
"go.opentelemetry.io/otel"
21+
"go.opentelemetry.io/otel/exporters/otlp/otlptrace"
22+
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc"
23+
"go.opentelemetry.io/otel/sdk/resource"
24+
"go.opentelemetry.io/otel/sdk/trace"
25+
"k8s.io/klog/v2"
26+
)
27+
28+
func InitOtelTracing() (*otlptrace.Exporter, error) {
29+
// Setup OTLP exporter
30+
ctx := context.Background()
31+
exporter, err := otlptracegrpc.New(ctx)
32+
if err != nil {
33+
return nil, fmt.Errorf("failed to create the OTLP exporter: %w", err)
34+
}
35+
36+
// Resource will auto populate spans with common attributes
37+
resource, err := resource.New(ctx,
38+
resource.WithFromEnv(), // pull attributes from OTEL_RESOURCE_ATTRIBUTES and OTEL_SERVICE_NAME environment variables
39+
resource.WithProcess(),
40+
resource.WithOS(),
41+
resource.WithContainer(),
42+
resource.WithHost(),
43+
)
44+
if err != nil {
45+
klog.Errorf("Failed to create the OTLP resource, spans will lack some metadata: %v", err)
46+
}
47+
48+
// Create a trace provider with the exporter.
49+
// Use propagator and sampler defined in environment variables.
50+
traceProvider := trace.NewTracerProvider(trace.WithBatcher(exporter), trace.WithResource(resource))
51+
52+
// Register the trace provider as global.
53+
otel.SetTracerProvider(traceProvider)
54+
55+
return exporter, nil
56+
}

test/sanity/sanity_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func TestSanity(t *testing.T) {
9292
}()
9393

9494
go func() {
95-
gceDriver.Run(endpoint, 10000)
95+
gceDriver.Run(endpoint, 10000, false)
9696
}()
9797

9898
// TODO(#818): Fix failing tests and remove test skip flag.

vendor/github.com/cenkalti/backoff/v4/.gitignore

+25
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/cenkalti/backoff/v4/LICENSE

+20
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)