From 7f0339a2948295bc252475065a6ec9fac120d464 Mon Sep 17 00:00:00 2001 From: Alexander <39818795+QxBytes@users.noreply.github.com> Date: Mon, 4 Nov 2024 13:39:37 -0800 Subject: [PATCH] fix: pass ai metadata to telemetry during cni image build (#3095) * fix log on ai telemetry handle create error * fix failure to pass cni ai id at build time for cni images * address feedback * move ai id to hardcoded variable * update unit test * Revert "move ai id to hardcoded variable" This reverts commit 666c2b0a8f5efbee6d8b970f87fbb94763347916. * fix typo --- Makefile | 3 ++- cni/Dockerfile | 4 +++- cni/telemetry/service/telemetrymain.go | 4 ++-- cns/service/main.go | 2 +- telemetry/aiwrapper_test.go | 10 +--------- 5 files changed, 9 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index a3abe5b2e..5b94bdfbe 100644 --- a/Makefile +++ b/Makefile @@ -436,7 +436,8 @@ cni-image: ## build cni container image. TARGET=$(OS) \ OS=$(OS) \ ARCH=$(ARCH) \ - OS_VERSION=$(OS_VERSION) + OS_VERSION=$(OS_VERSION) \ + EXTRA_BUILD_ARGS='--build-arg CNI_AI_PATH=$(CNI_AI_PATH) --build-arg CNI_AI_ID=$(CNI_AI_ID)' cni-image-push: ## push cni container image. $(MAKE) container-push \ diff --git a/cni/Dockerfile b/cni/Dockerfile index 097c07900..e8461c8e5 100644 --- a/cni/Dockerfile +++ b/cni/Dockerfile @@ -12,10 +12,12 @@ FROM --platform=linux/${ARCH} mcr.microsoft.com/cbl-mariner/base/core@sha256:a49 FROM go AS azure-vnet ARG OS ARG VERSION +ARG CNI_AI_PATH +ARG CNI_AI_ID WORKDIR /azure-container-networking COPY . . RUN GOOS=$OS CGO_ENABLED=0 go build -a -o /go/bin/azure-vnet -trimpath -ldflags "-X main.version="$VERSION"" -gcflags="-dwarflocationlists=true" cni/network/plugin/main.go -RUN GOOS=$OS CGO_ENABLED=0 go build -a -o /go/bin/azure-vnet-telemetry -trimpath -ldflags "-X main.version="$VERSION"" -gcflags="-dwarflocationlists=true" cni/telemetry/service/telemetrymain.go +RUN GOOS=$OS CGO_ENABLED=0 go build -a -o /go/bin/azure-vnet-telemetry -trimpath -ldflags "-X main.version="$VERSION" -X "$CNI_AI_PATH"="$CNI_AI_ID"" -gcflags="-dwarflocationlists=true" cni/telemetry/service/telemetrymain.go RUN GOOS=$OS CGO_ENABLED=0 go build -a -o /go/bin/azure-vnet-ipam -trimpath -ldflags "-X main.version="$VERSION"" -gcflags="-dwarflocationlists=true" cni/ipam/plugin/main.go RUN GOOS=$OS CGO_ENABLED=0 go build -a -o /go/bin/azure-vnet-stateless -trimpath -ldflags "-X main.version="$VERSION"" -gcflags="-dwarflocationlists=true" cni/network/stateless/main.go diff --git a/cni/telemetry/service/telemetrymain.go b/cni/telemetry/service/telemetrymain.go index bf21571d0..8c278eafe 100644 --- a/cni/telemetry/service/telemetrymain.go +++ b/cni/telemetry/service/telemetrymain.go @@ -167,8 +167,8 @@ func main() { GetEnvRetryWaitTimeInSecs: config.GetEnvRetryWaitTimeInSecs, } - if tb.CreateAITelemetryHandle(aiConfig, config.DisableAll, config.DisableTrace, config.DisableMetric) != nil { - logger.Error("AI Handle creation error", zap.Error(err)) + if err := tb.CreateAITelemetryHandle(aiConfig, config.DisableAll, config.DisableTrace, config.DisableMetric); err != nil { // nolint + logger.Error("AI Handle creation error:", zap.Error(err)) } logger.Info("Report to host interval", zap.Duration("seconds", config.ReportToHostIntervalInSeconds)) tb.PushData(context.Background()) diff --git a/cns/service/main.go b/cns/service/main.go index 5219ed25d..762e26b34 100644 --- a/cns/service/main.go +++ b/cns/service/main.go @@ -672,7 +672,7 @@ func main() { } if telemetryDaemonEnabled { - logger.Printf("CNI Telemtry is enabled") + logger.Printf("CNI Telemetry is enabled") go startTelemetryService(rootCtx) } diff --git a/telemetry/aiwrapper_test.go b/telemetry/aiwrapper_test.go index c10e39fe7..326e99f55 100644 --- a/telemetry/aiwrapper_test.go +++ b/telemetry/aiwrapper_test.go @@ -17,15 +17,7 @@ func TestCreateAITelemetryHandle(t *testing.T) { wantErr bool }{ { - name: "disable telemetry", - aiConfig: aitelemetry.AIConfig{}, - disableAll: false, - disableMetric: true, - disableTrace: true, - wantErr: true, - }, - { - name: "empty aiconfig", + name: "disabled telemetry with empty aiconfig", aiConfig: aitelemetry.AIConfig{}, disableAll: true, disableMetric: true,