From 61b575e4cd5ce6326ec1cd19939db117ba10fc85 Mon Sep 17 00:00:00 2001 From: Bastian Krol Date: Tue, 3 Sep 2024 09:18:46 +0200 Subject: [PATCH] chore(images): extract Go OTel SDK setup into reusable module --- .github/actions/build-image/action.yaml | 1 + .github/workflows/ci.yaml | 26 ++-- Makefile | 29 +++-- go.mod | 4 +- go.sum | 4 + images/configreloader/Dockerfile | 4 +- images/configreloader/src/configreloader.go | 98 +------------- images/configreloader/src/go.mod | 11 +- images/filelogoffsetsynch/Dockerfile | 4 +- .../src/filelogoffsetsynch.go | 93 +------------- images/filelogoffsetsynch/src/go.mod | 11 +- images/filelogoffsetsynch/src/go.sum | 8 +- images/pkg/common/go.mod | 29 +++++ images/pkg/common/go.sum | 51 ++++++++ images/pkg/common/otel.go | 121 ++++++++++++++++++ test/e2e/container_images.go | 12 +- test/e2e/e2e_test.go | 1 + test/e2e/metrics.go | 30 ++--- 18 files changed, 295 insertions(+), 242 deletions(-) create mode 100644 images/pkg/common/go.mod create mode 100644 images/pkg/common/go.sum create mode 100644 images/pkg/common/otel.go diff --git a/.github/actions/build-image/action.yaml b/.github/actions/build-image/action.yaml index de972a4d..58c1f41e 100644 --- a/.github/actions/build-image/action.yaml +++ b/.github/actions/build-image/action.yaml @@ -73,6 +73,7 @@ runs: uses: docker/build-push-action@v6 with: context: ${{ inputs.context }} + file: ${{ inputs.file != '' && inputs.file || format('{0}/Dockerfile', inputs.context) }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} # Maintenance note: keep the expression for building both platforms in sync with the "push" expression. diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 3492c2c1..31f6eaae 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -78,6 +78,16 @@ jobs: with: fetch-depth: 0 + - name: build operator controller image + uses: ./.github/actions/build-image + with: + githubToken: ${{ secrets.GITHUB_TOKEN }} + imageName: operator-controller + imageTitle: Dash0 Kubernetes Operator Controller + imageDescription: the controller for the Dash0 Kubernetes operator + imageUrl: https://github.com/dash0hq/dash0-operator/tree/main + context: . + - name: build instrumentation image uses: ./.github/actions/build-image with: @@ -106,17 +116,8 @@ jobs: imageTitle: Dash0 Kubernetes Configuration Reloader imageDescription: the configuration reloader for the Dash0 Kubernetes operator imageUrl: https://github.com/dash0hq/dash0-operator/tree/main/images/configreloader - context: images/configreloader - - - name: build operator controller image - uses: ./.github/actions/build-image - with: - githubToken: ${{ secrets.GITHUB_TOKEN }} - imageName: operator-controller - imageTitle: Dash0 Kubernetes Operator Controller - imageDescription: the controller for the Dash0 Kubernetes operator - imageUrl: https://github.com/dash0hq/dash0-operator/tree/main - context: . + context: images + file: images/configreloader/Dockerfile - name: build filelog offset synch image uses: ./.github/actions/build-image @@ -126,7 +127,8 @@ jobs: imageTitle: Dash0 Kubernetes Filelog Offset Synch imageDescription: the filelog offset synch for the Dash0 Kubernetes operator imageUrl: https://github.com/dash0hq/dash0-operator/tree/main - context: images/filelogoffsetsynch + context: images + file: images/filelogoffsetsynch/Dockerfile publish-helm-chart-dry-run: name: Publish Helm Chart (Dry Run) diff --git a/Makefile b/Makefile index bdcf1153..a73e7057 100644 --- a/Makefile +++ b/Makefile @@ -196,21 +196,26 @@ define build_container_image $(eval $@_IMAGE_REPOSITORY = $(1)) $(eval $@_IMAGE_TAG = $(2)) $(eval $@_CONTEXT = $(3)) -if [[ -n "$($@_IMAGE_REPOSITORY)" ]]; then \ - if [[ "$($@_IMAGE_REPOSITORY)" = *"/"* ]]; then \ - echo "not rebuilding the image $($@_IMAGE_REPOSITORY), this looks like a remote image"; \ - else \ - echo $(CONTAINER_TOOL) build -t $($@_IMAGE_REPOSITORY):$($@_IMAGE_TAG) $($@_CONTEXT); \ - $(CONTAINER_TOOL) build -t $($@_IMAGE_REPOSITORY):$($@_IMAGE_TAG) $($@_CONTEXT); \ - fi; \ -elif [[ -n "$(OPERATOR_HELM_CHART_URL)" ]]; then \ - echo "not rebuilding image, a remote Helm chart is used with the default image from the chart"; \ +$(eval $@_DOCKERFILE = $(4)) +if [[ -n "$($@_IMAGE_REPOSITORY)" ]]; then \ + if [[ "$($@_IMAGE_REPOSITORY)" = *"/"* ]]; then \ + echo "not rebuilding the image $($@_IMAGE_REPOSITORY), this looks like a remote image"; \ + else \ + dockerfile=$($@_DOCKERFILE); \ + if [[ -z $$dockerfile ]]; then \ + dockerfile=$($@_CONTEXT)/Dockerfile; \ + fi; \ + echo $(CONTAINER_TOOL) build -t $($@_IMAGE_REPOSITORY):$($@_IMAGE_TAG) -f $$dockerfile $($@_CONTEXT); \ + $(CONTAINER_TOOL) build -t $($@_IMAGE_REPOSITORY):$($@_IMAGE_TAG) -f $$dockerfile $($@_CONTEXT); \ + fi; \ +elif [[ -n "$(OPERATOR_HELM_CHART_URL)" ]]; then \ + echo "not rebuilding image, a remote Helm chart is used with the default image from the chart"; \ fi endef .PHONY: docker-build-controller docker-build-controller: ## Build the manager container image. - @$(call build_container_image,$(CONTROLLER_IMG_REPOSITORY),$(CONTROLLER_IMG_TAG),".") + @$(call build_container_image,$(CONTROLLER_IMG_REPOSITORY),$(CONTROLLER_IMG_TAG),.) .PHONY: docker-build-instrumentation docker-build-instrumentation: ## Build the instrumentation image. @@ -222,11 +227,11 @@ docker-build-collector: ## Build the OpenTelemetry collector container image. .PHONY: docker-build-config-reloader docker-build-config-reloader: ## Build the config reloader container image. - @$(call build_container_image,$(CONFIGURATION_RELOADER_IMG_REPOSITORY),$(CONFIGURATION_RELOADER_IMG_TAG),images/configreloader) + @$(call build_container_image,$(CONFIGURATION_RELOADER_IMG_REPOSITORY),$(CONFIGURATION_RELOADER_IMG_TAG),images,images/configreloader/Dockerfile) .PHONY: docker-build-filelog-offset-synch docker-build-filelog-offset-synch: ## Build the filelog offset synch container image. - @$(call build_container_image,$(FILELOG_OFFSET_SYNCH_IMG_REPOSITORY),$(FILELOG_OFFSET_SYNCH_IMG_TAG),images/filelogoffsetsynch) + @$(call build_container_image,$(FILELOG_OFFSET_SYNCH_IMG_REPOSITORY),$(FILELOG_OFFSET_SYNCH_IMG_TAG),images,images/filelogoffsetsynch/Dockerfile) ifndef ignore-not-found ignore-not-found = false diff --git a/go.mod b/go.mod index a3ebec94..8fb31577 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/google/go-cmp v0.6.0 github.com/google/uuid v1.6.0 github.com/onsi/ginkgo/v2 v2.20.1 - github.com/onsi/gomega v1.34.1 + github.com/onsi/gomega v1.34.2 go.opentelemetry.io/collector/pdata v1.14.1 gopkg.in/yaml.v3 v3.0.1 k8s.io/api v0.31.0 @@ -37,7 +37,7 @@ require ( github.com/golang/protobuf v1.5.4 // indirect github.com/google/gnostic-models v0.6.8 // indirect github.com/google/gofuzz v1.2.0 // indirect - github.com/google/pprof v0.0.0-20240727154555-813a5fbdbec8 // indirect + github.com/google/pprof v0.0.0-20240827171923-fa2c70bbbfe5 // indirect github.com/imdario/mergo v0.3.16 // indirect github.com/josharian/intern v1.0.0 // indirect github.com/json-iterator/go v1.1.12 // indirect diff --git a/go.sum b/go.sum index 1075d1df..fee450f7 100644 --- a/go.sum +++ b/go.sum @@ -44,6 +44,8 @@ github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0= github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/pprof v0.0.0-20240727154555-813a5fbdbec8 h1:FKHo8hFI3A+7w0aUQuYXQ+6EN5stWmeY/AZqtM8xk9k= github.com/google/pprof v0.0.0-20240727154555-813a5fbdbec8/go.mod h1:K1liHPHnj73Fdn/EKuT8nrFqBihUSKXoLYU0BuatOYo= +github.com/google/pprof v0.0.0-20240827171923-fa2c70bbbfe5 h1:5iH8iuqE5apketRbSFBy+X1V0o+l+8NF1avt4HWl7cA= +github.com/google/pprof v0.0.0-20240827171923-fa2c70bbbfe5/go.mod h1:vavhavw2zAxS5dIdcRluK6cSGGPlZynqzFM8NdvU144= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/imdario/mergo v0.3.16 h1:wwQJbIsHYGMUyLSPrEq1CT16AhnhNJQ51+4fdHUnCl4= @@ -71,6 +73,8 @@ github.com/onsi/ginkgo/v2 v2.20.1 h1:YlVIbqct+ZmnEph770q9Q7NVAz4wwIiVNahee6JyUzo github.com/onsi/ginkgo/v2 v2.20.1/go.mod h1:lG9ey2Z29hR41WMVthyJBGUBcBhGOtoPF2VFMvBXFCI= github.com/onsi/gomega v1.34.1 h1:EUMJIKUjM8sKjYbtxQI9A4z2o+rruxnzNvpknOXie6k= github.com/onsi/gomega v1.34.1/go.mod h1:kU1QgUvBDLXBJq618Xvm2LUX6rSAfRaFRTcdOeDLwwY= +github.com/onsi/gomega v1.34.2 h1:pNCwDkzrsv7MS9kpaQvVb1aVLahQXyJ/Tv5oAZMI3i8= +github.com/onsi/gomega v1.34.2/go.mod h1:v1xfxRgk0KIsG+QOdm7p8UosrOzPYRo60fd3B/1Dukc= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= diff --git a/images/configreloader/Dockerfile b/images/configreloader/Dockerfile index 1414a1e2..31e7a111 100644 --- a/images/configreloader/Dockerfile +++ b/images/configreloader/Dockerfile @@ -1,5 +1,7 @@ +# Note: Expects dash0-operator/images as the build context. FROM golang:alpine AS builder -COPY ./src /usr/local/go/src/configreloader +COPY configreloader/src /usr/local/go/src/configreloader +COPY pkg /usr/local/go/pkg WORKDIR /usr/local/go/src/configreloader RUN CGO_ENABLED=0 go build -ldflags '-extldflags "-static"' configreloader diff --git a/images/configreloader/src/configreloader.go b/images/configreloader/src/configreloader.go index 3f9f09a9..627ac96e 100644 --- a/images/configreloader/src/configreloader.go +++ b/images/configreloader/src/configreloader.go @@ -19,15 +19,10 @@ import ( "syscall" "time" - "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc" - "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp" otelmetric "go.opentelemetry.io/otel/metric" - metricnoop "go.opentelemetry.io/otel/metric/noop" - sdkmetric "go.opentelemetry.io/otel/sdk/metric" - "go.opentelemetry.io/otel/sdk/resource" - semconv "go.opentelemetry.io/otel/semconv/v1.26.0" + + "github.com/dash0hq/dash0-operator/images/pkg/common" ) const ( @@ -43,7 +38,6 @@ var ( configurationFileHashes = make(map[string]string) metricNamePrefix = fmt.Sprintf("%s.", meterName) - meterProvider otelmetric.MeterProvider configFilesChangesMetricName = fmt.Sprintf("%s%s", metricNamePrefix, "config_file_changes") configFilesChangesMetric otelmetric.Int64Counter @@ -77,7 +71,7 @@ func main() { done := make(chan bool, 1) signal.Notify(shutdown, syscall.SIGTERM) - meter, selfMonitoringShutdownFunctions := setUpSelfMonitoring(ctx) + meter, selfMonitoringShutdownFunctions := common.InitOTelSdk(ctx, meterName) setUpSelfMonitoringMetrics(meter) go func() { @@ -102,7 +96,7 @@ func main() { <-done - shutDownSelfMonitoring(ctx, selfMonitoringShutdownFunctions) + common.ShutDownOTelSdk(ctx, selfMonitoringShutdownFunctions) } func initializeHashes(configurationFilePaths []string) error { @@ -240,90 +234,6 @@ func triggerConfigurationReload(collectorPid OTelColPid) error { return nil } -func setUpSelfMonitoring(ctx context.Context) (otelmetric.Meter, []func(ctx context.Context) error) { - podUid, isSet := os.LookupEnv("K8S_POD_UID") - if !isSet { - log.Println("Env var 'K8S_POD_UID' is not set") - } - - nodeName, isSet := os.LookupEnv("K8S_NODE_NAME") - if !isSet { - log.Println("Env var 'K8S_NODE_NAME' is not set") - } - - var doMeterShutdown func(ctx context.Context) error - - if _, isSet = os.LookupEnv("OTEL_EXPORTER_OTLP_ENDPOINT"); isSet { - var metricExporter sdkmetric.Exporter - - protocol, isProtocolSet := os.LookupEnv("OTEL_EXPORTER_OTLP_PROTOCOL") - if !isProtocolSet { - // http/protobuf is the default transport protocol, see spec: - // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md - protocol = "http/protobuf" - } - - var err error - switch protocol { - case "grpc": - if metricExporter, err = otlpmetricgrpc.New(ctx); err != nil { - log.Fatalf("Cannot create the OTLP gRPC metrics exporter: %v", err) - } - case "http/protobuf": - if metricExporter, err = otlpmetrichttp.New(ctx); err != nil { - log.Fatalf("Cannot create the OTLP HTTP metrics exporter: %v", err) - } - case "http/json": - log.Fatalf("Cannot create the OTLP HTTP exporter: the protocol 'http/json' is currently unsupported") - default: - log.Fatalf("Unexpected OTLP protocol set as value of the 'OTEL_EXPORTER_OTLP_PROTOCOL' environment variable: %v", protocol) - } - - r, err := resource.New(ctx, - resource.WithAttributes( - semconv.K8SPodUID(podUid), - semconv.K8SNodeName(nodeName), - ), - ) - if err != nil { - log.Fatalf("Cannot setup the OTLP resource: %v", err) - } - - sdkMeterProvider := sdkmetric.NewMeterProvider( - sdkmetric.WithResource(r), - sdkmetric.WithReader( - sdkmetric.NewPeriodicReader( - metricExporter, - sdkmetric.WithTimeout(10*time.Second), - sdkmetric.WithInterval(5*time.Second), - )), - ) - - meterProvider = sdkMeterProvider - doMeterShutdown = sdkMeterProvider.Shutdown - } else { - meterProvider = metricnoop.MeterProvider{} - doMeterShutdown = func(ctx context.Context) error { return nil } - } - - otel.SetMeterProvider(meterProvider) - - return meterProvider.Meter(meterName), []func(ctx context.Context) error{ - doMeterShutdown, - } -} - -func shutDownSelfMonitoring(ctx context.Context, shutdownFunctions []func(ctx context.Context) error) { - var err error - for _, shutdownFunction := range shutdownFunctions { - timeoutCtx, cancelFun := context.WithTimeout(ctx, time.Second) - if err = shutdownFunction(timeoutCtx); err != nil { - log.Printf("Failed to shutdown self monitoring, telemetry may have been lost:%v\n", err) - } - cancelFun() - } -} - func setUpSelfMonitoringMetrics(meter otelmetric.Meter) { var err error diff --git a/images/configreloader/src/go.mod b/images/configreloader/src/go.mod index c0f53917..9414420f 100644 --- a/images/configreloader/src/go.mod +++ b/images/configreloader/src/go.mod @@ -3,12 +3,9 @@ module github.com/dash0hq/dash0-operator/images/configreloader go 1.22.4 require ( + github.com/dash0hq/dash0-operator/images/pkg/common v0.0.0-00010101000000-000000000000 go.opentelemetry.io/otel v1.29.0 - go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.29.0 - go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.29.0 go.opentelemetry.io/otel/metric v1.29.0 - go.opentelemetry.io/otel/sdk v1.29.0 - go.opentelemetry.io/otel/sdk/metric v1.29.0 ) require ( @@ -17,6 +14,10 @@ require ( github.com/go-logr/stdr v1.2.2 // indirect github.com/google/uuid v1.6.0 // indirect github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.29.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.29.0 // indirect + go.opentelemetry.io/otel/sdk v1.29.0 // indirect + go.opentelemetry.io/otel/sdk/metric v1.29.0 // indirect go.opentelemetry.io/otel/trace v1.29.0 // indirect go.opentelemetry.io/proto/otlp v1.3.1 // indirect golang.org/x/net v0.28.0 // indirect @@ -27,3 +28,5 @@ require ( google.golang.org/grpc v1.65.0 // indirect google.golang.org/protobuf v1.34.2 // indirect ) + +replace github.com/dash0hq/dash0-operator/images/pkg/common => ../../pkg/common diff --git a/images/filelogoffsetsynch/Dockerfile b/images/filelogoffsetsynch/Dockerfile index fdb2f138..ab23606c 100644 --- a/images/filelogoffsetsynch/Dockerfile +++ b/images/filelogoffsetsynch/Dockerfile @@ -1,5 +1,7 @@ +# Note: Expects dash0-operator/images as the build context. FROM golang:alpine AS builder -COPY ./src /usr/local/go/src/filelogoffsetsynch +COPY filelogoffsetsynch/src /usr/local/go/src/filelogoffsetsynch +COPY pkg /usr/local/go/pkg WORKDIR /usr/local/go/src/filelogoffsetsynch RUN CGO_ENABLED=0 go build -ldflags '-extldflags "-static"' filelogoffsetsynch diff --git a/images/filelogoffsetsynch/src/filelogoffsetsynch.go b/images/filelogoffsetsynch/src/filelogoffsetsynch.go index 9baa9c8e..204fceb3 100644 --- a/images/filelogoffsetsynch/src/filelogoffsetsynch.go +++ b/images/filelogoffsetsynch/src/filelogoffsetsynch.go @@ -21,19 +21,14 @@ import ( "syscall" "time" - "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc" - "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp" otelmetric "go.opentelemetry.io/otel/metric" - metricnoop "go.opentelemetry.io/otel/metric/noop" - "go.opentelemetry.io/otel/sdk/metric" - "go.opentelemetry.io/otel/sdk/resource" - semconv "go.opentelemetry.io/otel/semconv/v1.17.0" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/kubernetes" "k8s.io/client-go/rest" + + "github.com/dash0hq/dash0-operator/images/pkg/common" ) type Settings struct { @@ -56,7 +51,6 @@ var ( currentValue string metricNamePrefix = fmt.Sprintf("%s.", meterName) - meterProvider otelmetric.MeterProvider updateSizeMetricName = fmt.Sprintf("%s%s", metricNamePrefix, "update.compressed_size") updateSizeMetric otelmetric.Int64Gauge @@ -114,7 +108,7 @@ func main() { log.Fatalf("Cannot create the Kube API client: %v\n", err) } - meter, selfMonitoringShutdownFunctions := setUpSelfMonitoring(ctx) + meter, selfMonitoringShutdownFunctions := common.InitOTelSdk(ctx, meterName) setUpSelfMonitoringMetrics(meter) // creates the clientset @@ -144,7 +138,7 @@ func main() { } } - shutDownSelfMonitoring(ctx, selfMonitoringShutdownFunctions) + common.ShutDownOTelSdk(ctx, selfMonitoringShutdownFunctions) } func initOffsets(ctx context.Context, settings *Settings) (int, error) { @@ -399,85 +393,6 @@ func tarFile(writer *tar.Writer, path string, info os.FileInfo) (HasAddedFileToA return true, nil } -func setUpSelfMonitoring(ctx context.Context) (otelmetric.Meter, []func(ctx context.Context) error) { - podUid, isSet := os.LookupEnv("K8S_POD_UID") - if !isSet { - log.Println("Env var 'K8S_POD_UID' is not set") - } - - nodeName, isSet := os.LookupEnv("K8S_NODE_NAME") - if !isSet { - log.Println("Env var 'K8S_NODE_NAME' is not set") - } - - var doMeterShutdown func(ctx context.Context) error - - if _, isSet = os.LookupEnv("OTEL_EXPORTER_OTLP_ENDPOINT"); isSet { - var metricExporter metric.Exporter - - protocol, isProtocolSet := os.LookupEnv("OTEL_EXPORTER_OTLP_PROTOCOL") - if !isProtocolSet { - // http/protobuf is the default transport protocol, see spec: - // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md - protocol = "http/protobuf" - } - - var err error - switch protocol { - case "grpc": - if metricExporter, err = otlpmetricgrpc.New(ctx); err != nil { - log.Fatalf("Cannot create the OTLP gRPC metrics exporter: %v", err) - } - case "http/protobuf": - if metricExporter, err = otlpmetrichttp.New(ctx); err != nil { - log.Fatalf("Cannot create the OTLP HTTP metrics exporter: %v", err) - } - case "http/json": - log.Fatalf("Cannot create the OTLP HTTP exporter: the protocol 'http/json' is currently unsupported") - default: - log.Fatalf("Unexpected OTLP protocol set as value of the 'OTEL_EXPORTER_OTLP_PROTOCOL' environment variable: %v", protocol) - } - - r, err := resource.New(ctx, - resource.WithAttributes( - semconv.K8SPodUID(podUid), - semconv.K8SNodeName(nodeName), - ), - ) - if err != nil { - log.Fatalf("Cannot setup the OTLP resource: %v", err) - } - - sdkMeterProvider := metric.NewMeterProvider( - metric.WithResource(r), - metric.WithReader(metric.NewPeriodicReader(metricExporter, metric.WithTimeout(1*time.Second))), - ) - - meterProvider = sdkMeterProvider - doMeterShutdown = sdkMeterProvider.Shutdown - } else { - meterProvider = metricnoop.MeterProvider{} - doMeterShutdown = func(ctx context.Context) error { return nil } - } - - otel.SetMeterProvider(meterProvider) - - return meterProvider.Meter(meterName), []func(ctx context.Context) error{ - doMeterShutdown, - } -} - -func shutDownSelfMonitoring(ctx context.Context, shutdownFunctions []func(ctx context.Context) error) { - var err error - for _, shutdownFunction := range shutdownFunctions { - timeoutCtx, cancelFun := context.WithTimeout(ctx, time.Second) - if err = shutdownFunction(timeoutCtx); err != nil { - log.Printf("Failed to shutdown self monitoring, telemetry may have been lost:%v\n", err) - } - cancelFun() - } -} - func setUpSelfMonitoringMetrics(meter otelmetric.Meter) { var err error diff --git a/images/filelogoffsetsynch/src/go.mod b/images/filelogoffsetsynch/src/go.mod index 56bff8a0..049cf5ae 100644 --- a/images/filelogoffsetsynch/src/go.mod +++ b/images/filelogoffsetsynch/src/go.mod @@ -3,12 +3,9 @@ module github.com/dash0hq/dash0-operator/images/filelogoffsetsynch go 1.22.4 require ( + github.com/dash0hq/dash0-operator/images/pkg/common v0.0.0-00010101000000-000000000000 go.opentelemetry.io/otel v1.29.0 - go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.28.0 - go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.28.0 go.opentelemetry.io/otel/metric v1.29.0 - go.opentelemetry.io/otel/sdk v1.29.0 - go.opentelemetry.io/otel/sdk/metric v1.29.0 k8s.io/apimachinery v0.31.0 k8s.io/client-go v0.31.0 ) @@ -37,6 +34,10 @@ require ( github.com/modern-go/reflect2 v1.0.2 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/x448/float16 v0.8.4 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.29.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.29.0 // indirect + go.opentelemetry.io/otel/sdk v1.29.0 // indirect + go.opentelemetry.io/otel/sdk/metric v1.29.0 // indirect go.opentelemetry.io/otel/trace v1.29.0 // indirect go.opentelemetry.io/proto/otlp v1.3.1 // indirect golang.org/x/net v0.28.0 // indirect @@ -60,3 +61,5 @@ require ( sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect sigs.k8s.io/yaml v1.4.0 // indirect ) + +replace github.com/dash0hq/dash0-operator/images/pkg/common => ../../pkg/common diff --git a/images/filelogoffsetsynch/src/go.sum b/images/filelogoffsetsynch/src/go.sum index 810cf69f..311e5925 100644 --- a/images/filelogoffsetsynch/src/go.sum +++ b/images/filelogoffsetsynch/src/go.sum @@ -79,10 +79,10 @@ github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= go.opentelemetry.io/otel v1.29.0 h1:PdomN/Al4q/lN6iBJEN3AwPvUiHPMlt93c8bqTG5Llw= go.opentelemetry.io/otel v1.29.0/go.mod h1:N/WtXPs1CNCUEx+Agz5uouwCba+i+bJGFicT8SR4NP8= -go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.28.0 h1:U2guen0GhqH8o/G2un8f/aG/y++OuW6MyCo6hT9prXk= -go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.28.0/go.mod h1:yeGZANgEcpdx/WK0IvvRFC+2oLiMS2u4L/0Rj2M2Qr0= -go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.28.0 h1:aLmmtjRke7LPDQ3lvpFz+kNEH43faFhzW7v8BFIEydg= -go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.28.0/go.mod h1:TC1pyCt6G9Sjb4bQpShH+P5R53pO6ZuGnHuuln9xMeE= +go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.29.0 h1:k6fQVDQexDE+3jG2SfCQjnHS7OamcP73YMoxEVq5B6k= +go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.29.0/go.mod h1:t4BrYLHU450Zo9fnydWlIuswB1bm7rM8havDpWOJeDo= +go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.29.0 h1:xvhQxJ/C9+RTnAj5DpTg7LSM1vbbMTiXt7e9hsfqHNw= +go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.29.0/go.mod h1:Fcvs2Bz1jkDM+Wf5/ozBGmi3tQ/c9zPKLnsipnfhGAo= go.opentelemetry.io/otel/metric v1.29.0 h1:vPf/HFWTNkPu1aYeIsc98l4ktOQaL6LeSoeV2g+8YLc= go.opentelemetry.io/otel/metric v1.29.0/go.mod h1:auu/QWieFVWx+DmQOUMgj0F8LHWdgalxXqvp7BII/W8= go.opentelemetry.io/otel/sdk v1.29.0 h1:vkqKjk7gwhS8VaWb0POZKmIEDimRCMsopNYnriHyryo= diff --git a/images/pkg/common/go.mod b/images/pkg/common/go.mod new file mode 100644 index 00000000..a2b011d3 --- /dev/null +++ b/images/pkg/common/go.mod @@ -0,0 +1,29 @@ +module github.com/dash0hq/dash0-operator/images/pkg/common + +go 1.22.4 + +require ( + go.opentelemetry.io/otel v1.29.0 + go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.29.0 + go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.29.0 + go.opentelemetry.io/otel/metric v1.29.0 + go.opentelemetry.io/otel/sdk v1.29.0 + go.opentelemetry.io/otel/sdk/metric v1.29.0 +) + +require ( + github.com/cenkalti/backoff/v4 v4.3.0 // indirect + github.com/go-logr/logr v1.4.2 // indirect + github.com/go-logr/stdr v1.2.2 // indirect + github.com/google/uuid v1.6.0 // indirect + github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 // indirect + go.opentelemetry.io/otel/trace v1.29.0 // indirect + go.opentelemetry.io/proto/otlp v1.3.1 // indirect + golang.org/x/net v0.28.0 // indirect + golang.org/x/sys v0.24.0 // indirect + golang.org/x/text v0.17.0 // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20240822170219-fc7c04adadcd // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240822170219-fc7c04adadcd // indirect + google.golang.org/grpc v1.65.0 // indirect + google.golang.org/protobuf v1.34.2 // indirect +) diff --git a/images/pkg/common/go.sum b/images/pkg/common/go.sum new file mode 100644 index 00000000..1433d655 --- /dev/null +++ b/images/pkg/common/go.sum @@ -0,0 +1,51 @@ +github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8= +github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= +github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= +github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 h1:asbCHRVmodnJTuQ3qamDwqVOIjwqUPTYmYuemVOx+Ys= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0/go.mod h1:ggCgvZ2r7uOoQjOyu2Y1NhHmEPPzzuhWgcza5M1Ji1I= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +go.opentelemetry.io/otel v1.29.0 h1:PdomN/Al4q/lN6iBJEN3AwPvUiHPMlt93c8bqTG5Llw= +go.opentelemetry.io/otel v1.29.0/go.mod h1:N/WtXPs1CNCUEx+Agz5uouwCba+i+bJGFicT8SR4NP8= +go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.29.0 h1:k6fQVDQexDE+3jG2SfCQjnHS7OamcP73YMoxEVq5B6k= +go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.29.0/go.mod h1:t4BrYLHU450Zo9fnydWlIuswB1bm7rM8havDpWOJeDo= +go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.29.0 h1:xvhQxJ/C9+RTnAj5DpTg7LSM1vbbMTiXt7e9hsfqHNw= +go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.29.0/go.mod h1:Fcvs2Bz1jkDM+Wf5/ozBGmi3tQ/c9zPKLnsipnfhGAo= +go.opentelemetry.io/otel/metric v1.29.0 h1:vPf/HFWTNkPu1aYeIsc98l4ktOQaL6LeSoeV2g+8YLc= +go.opentelemetry.io/otel/metric v1.29.0/go.mod h1:auu/QWieFVWx+DmQOUMgj0F8LHWdgalxXqvp7BII/W8= +go.opentelemetry.io/otel/sdk v1.29.0 h1:vkqKjk7gwhS8VaWb0POZKmIEDimRCMsopNYnriHyryo= +go.opentelemetry.io/otel/sdk v1.29.0/go.mod h1:pM8Dx5WKnvxLCb+8lG1PRNIDxu9g9b9g59Qr7hfAAok= +go.opentelemetry.io/otel/sdk/metric v1.29.0 h1:K2CfmJohnRgvZ9UAj2/FhIf/okdWcNdBwe1m8xFXiSY= +go.opentelemetry.io/otel/sdk/metric v1.29.0/go.mod h1:6zZLdCl2fkauYoZIOn/soQIDSWFmNSRcICarHfuhNJQ= +go.opentelemetry.io/otel/trace v1.29.0 h1:J/8ZNK4XgR7a21DZUAsbF8pZ5Jcw1VhACmnYt39JTi4= +go.opentelemetry.io/otel/trace v1.29.0/go.mod h1:eHl3w0sp3paPkYstJOmAimxhiFXPg+MMTlEh3nsQgWQ= +go.opentelemetry.io/proto/otlp v1.3.1 h1:TrMUixzpM0yuc/znrFTP9MMRh8trP93mkCiDVeXrui0= +go.opentelemetry.io/proto/otlp v1.3.1/go.mod h1:0X1WI4de4ZsLrrJNLAQbFeLCm3T7yBkR0XqQ7niQU+8= +golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE= +golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg= +golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg= +golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc= +golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= +google.golang.org/genproto/googleapis/api v0.0.0-20240822170219-fc7c04adadcd h1:BBOTEWLuuEGQy9n1y9MhVJ9Qt0BDu21X8qZs71/uPZo= +google.golang.org/genproto/googleapis/api v0.0.0-20240822170219-fc7c04adadcd/go.mod h1:fO8wJzT2zbQbAjbIoos1285VfEIYKDDY+Dt+WpTkh6g= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240822170219-fc7c04adadcd h1:6TEm2ZxXoQmFWFlt1vNxvVOa1Q0dXFQD1m/rYjXmS0E= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240822170219-fc7c04adadcd/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU= +google.golang.org/grpc v1.65.0 h1:bs/cUb4lp1G5iImFFd3u5ixQzweKizoZJAwBNLR42lc= +google.golang.org/grpc v1.65.0/go.mod h1:WgYC2ypjlB0EiQi6wdKixMqukr6lBc0Vo+oOgjrM5ZQ= +google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= +google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/images/pkg/common/otel.go b/images/pkg/common/otel.go new file mode 100644 index 00000000..f5f4d28c --- /dev/null +++ b/images/pkg/common/otel.go @@ -0,0 +1,121 @@ +// SPDX-FileCopyrightText: Copyright 2024 Dash0 Inc. +// SPDX-License-Identifier: Apache-2.0 + +package common // import "github.com/dash0hq/dash0-operator/images/pkg/common" + +import ( + "context" + "log" + "os" + "time" + + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc" + "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp" + otelmetric "go.opentelemetry.io/otel/metric" + metricnoop "go.opentelemetry.io/otel/metric/noop" + sdkmetric "go.opentelemetry.io/otel/sdk/metric" + "go.opentelemetry.io/otel/sdk/resource" + semconv "go.opentelemetry.io/otel/semconv/v1.26.0" +) + +var ( + meterProvider otelmetric.MeterProvider +) + +func InitOTelSdk( + ctx context.Context, + meterName string, +) (otelmetric.Meter, []func(ctx context.Context) error) { + podUid, isSet := os.LookupEnv("K8S_POD_UID") + if !isSet { + log.Println("Env var 'K8S_POD_UID' is not set") + } + + nodeName, isSet := os.LookupEnv("K8S_NODE_NAME") + if !isSet { + log.Println("Env var 'K8S_NODE_NAME' is not set") + } + + var doMeterShutdown func(ctx context.Context) error + + if _, isSet = os.LookupEnv("OTEL_EXPORTER_OTLP_ENDPOINT"); isSet { + var metricExporter sdkmetric.Exporter + + protocol, isProtocolSet := os.LookupEnv("OTEL_EXPORTER_OTLP_PROTOCOL") + if !isProtocolSet { + // http/protobuf is the default transport protocol, see spec: + // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md + protocol = "http/protobuf" + } + + var err error + switch protocol { + case "grpc": + if metricExporter, err = otlpmetricgrpc.New(ctx); err != nil { + log.Fatalf("Cannot create the OTLP gRPC metrics exporter: %v", err) + } + case "http/protobuf": + if metricExporter, err = otlpmetrichttp.New(ctx); err != nil { + log.Fatalf("Cannot create the OTLP HTTP metrics exporter: %v", err) + } + case "http/json": + log.Fatalf("Cannot create the OTLP HTTP exporter: the protocol 'http/json' is currently unsupported") + default: + log.Fatalf("Unexpected OTLP protocol set as value of the 'OTEL_EXPORTER_OTLP_PROTOCOL' environment variable: %v", protocol) + } + + resourceWithPodAndNode, err := resource.New(ctx, + resource.WithAttributes( + semconv.K8SPodUID(podUid), + semconv.K8SNodeName(nodeName), + ), + ) + if err != nil { + log.Fatalf("Cannot initialize the OpenTelemetry resource: %v", err) + } + // Note: Merging with resource.Environment() should not be necessary, the SDK is supposed to do that on its own, + // that is, merge the resource attributes provided here with the key-value pairs from OTEL_RESOURCE_ATTRIBUTES. + // + // Actually, the trace SDK does that correctly, but the metric SDK does not. + // - https://github.com/open-telemetry/opentelemetry-go/blob/932a4d8a5f2536645618d7aee8e5da6b8e3b6751/sdk/trace/provider.go#L353 + // - https://github.com/open-telemetry/opentelemetry-go/blob/932a4d8a5f2536645618d7aee8e5da6b8e3b6751/sdk/metric/config.go#L106 + finalResource, err := resource.Merge(resource.Environment(), resourceWithPodAndNode) + if err != nil { + log.Fatalf("Cannot merge the OpenTelemetry resource: %v", err) + } + + sdkMeterProvider := sdkmetric.NewMeterProvider( + sdkmetric.WithResource(finalResource), + sdkmetric.WithReader( + sdkmetric.NewPeriodicReader( + metricExporter, + sdkmetric.WithTimeout(10*time.Second), + sdkmetric.WithInterval(15*time.Second), + )), + ) + + meterProvider = sdkMeterProvider + doMeterShutdown = sdkMeterProvider.Shutdown + } else { + meterProvider = metricnoop.MeterProvider{} + doMeterShutdown = func(ctx context.Context) error { return nil } + } + + otel.SetMeterProvider(meterProvider) + + return meterProvider.Meter(meterName), []func(ctx context.Context) error{ + doMeterShutdown, + } +} + +func ShutDownOTelSdk(ctx context.Context, shutdownFunctions []func(ctx context.Context) error) { + var err error + for _, shutdownFunction := range shutdownFunctions { + timeoutCtx, cancelFun := context.WithTimeout(ctx, time.Second) + if err = shutdownFunction(timeoutCtx); err != nil { + log.Printf("Failed to shutdown self monitoring, telemetry may have been lost:%v\n", err) + } + cancelFun() + } +} diff --git a/test/e2e/container_images.go b/test/e2e/container_images.go index 3f07cb91..bbb190b3 100644 --- a/test/e2e/container_images.go +++ b/test/e2e/container_images.go @@ -82,9 +82,9 @@ func rebuildOperatorControllerImage(operatorImage ImageSpec) { exec.Command( "docker", "build", - ".", "-t", fmt.Sprintf("%s:%s", operatorImage.repository, operatorImage.tag), + ".", ))).To(Succeed()) additionalTag := ImageSpec{ @@ -140,9 +140,9 @@ func rebuildCollectorImage(collectorImage ImageSpec) { exec.Command( "docker", "build", - "images/collector", "-t", fmt.Sprintf("%s:%s", collectorImage.repository, collectorImage.tag), + "images/collector", ))).To(Succeed()) additionalTag := ImageSpec{ @@ -171,9 +171,11 @@ func rebuildConfigurationReloaderImage(configurationReloaderImage ImageSpec) { exec.Command( "docker", "build", - "images/configreloader", + "-f", + "images/configreloader/Dockerfile", "-t", fmt.Sprintf("%s:%s", configurationReloaderImage.repository, configurationReloaderImage.tag), + "images", ))).To(Succeed()) additionalTag := ImageSpec{ @@ -202,9 +204,11 @@ func rebuildFileLogOffsetSynchImage(fileLogOffsetSynchImage ImageSpec) { exec.Command( "docker", "build", - "images/filelogoffsetsynch", + "-f", + "images/filelogoffsetsynch/Dockerfile", "-t", fmt.Sprintf("%s:%s", fileLogOffsetSynchImage.repository, fileLogOffsetSynchImage.tag), + "images", ))).To(Succeed()) additionalTag := ImageSpec{ diff --git a/test/e2e/e2e_test.go b/test/e2e/e2e_test.go index e87ffbc3..10b38ef2 100644 --- a/test/e2e/e2e_test.go +++ b/test/e2e/e2e_test.go @@ -630,6 +630,7 @@ var _ = Describe("Dash0 Kubernetes Operator", Ordered, func() { newEndpoint := "ingress.us-east-2.aws.dash0-dev.com:4317" updateEndpointOfDash0MonitoringResource(applicationUnderTestNamespace, newEndpoint) + By("waiting for self-monitoring metrics") Eventually(func(g Gomega) { verifySelfMonitoringMetrics(g) }, 90*time.Second, time.Second).Should(Succeed()) diff --git a/test/e2e/metrics.go b/test/e2e/metrics.go index 4be8546d..07661a7d 100644 --- a/test/e2e/metrics.go +++ b/test/e2e/metrics.go @@ -90,21 +90,21 @@ func verifySelfMonitoringMetrics(g Gomega) { attributes := resourceMetrics.Resource().Attributes() var isSet bool - //serviceNamespace, isSet = attributes.Get("service.namespace") - //if !isSet { - // return false - //} - //if serviceNamespace.Str() != "dash0.operator" { - // return false - //} - //_, isSet = attributes.Get("service.name") - //if !isSet { - // return false - //} - //_, isSet = attributes.Get("service.version") - //if !isSet { - // return false - //} + serviceNamespace, isSet := attributes.Get("service.namespace") + if !isSet { + return false + } + if serviceNamespace.Str() != "dash0.operator" { + return false + } + _, isSet = attributes.Get("service.name") + if !isSet { + return false + } + _, isSet = attributes.Get("service.version") + if !isSet { + return false + } _, isSet = attributes.Get("k8s.node.name") if !isSet { return false