Skip to content

Commit 7f0339a

Browse files
authored
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 666c2b0. * fix typo
1 parent 7b188cc commit 7f0339a

File tree

5 files changed

+9
-14
lines changed

5 files changed

+9
-14
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,8 @@ cni-image: ## build cni container image.
436436
TARGET=$(OS) \
437437
OS=$(OS) \
438438
ARCH=$(ARCH) \
439-
OS_VERSION=$(OS_VERSION)
439+
OS_VERSION=$(OS_VERSION) \
440+
EXTRA_BUILD_ARGS='--build-arg CNI_AI_PATH=$(CNI_AI_PATH) --build-arg CNI_AI_ID=$(CNI_AI_ID)'
440441

441442
cni-image-push: ## push cni container image.
442443
$(MAKE) container-push \

cni/Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ FROM --platform=linux/${ARCH} mcr.microsoft.com/cbl-mariner/base/core@sha256:a49
1212
FROM go AS azure-vnet
1313
ARG OS
1414
ARG VERSION
15+
ARG CNI_AI_PATH
16+
ARG CNI_AI_ID
1517
WORKDIR /azure-container-networking
1618
COPY . .
1719
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
18-
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
20+
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
1921
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
2022
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
2123

cni/telemetry/service/telemetrymain.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ func main() {
167167
GetEnvRetryWaitTimeInSecs: config.GetEnvRetryWaitTimeInSecs,
168168
}
169169

170-
if tb.CreateAITelemetryHandle(aiConfig, config.DisableAll, config.DisableTrace, config.DisableMetric) != nil {
171-
logger.Error("AI Handle creation error", zap.Error(err))
170+
if err := tb.CreateAITelemetryHandle(aiConfig, config.DisableAll, config.DisableTrace, config.DisableMetric); err != nil { // nolint
171+
logger.Error("AI Handle creation error:", zap.Error(err))
172172
}
173173
logger.Info("Report to host interval", zap.Duration("seconds", config.ReportToHostIntervalInSeconds))
174174
tb.PushData(context.Background())

cns/service/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ func main() {
672672
}
673673

674674
if telemetryDaemonEnabled {
675-
logger.Printf("CNI Telemtry is enabled")
675+
logger.Printf("CNI Telemetry is enabled")
676676
go startTelemetryService(rootCtx)
677677
}
678678

telemetry/aiwrapper_test.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,7 @@ func TestCreateAITelemetryHandle(t *testing.T) {
1717
wantErr bool
1818
}{
1919
{
20-
name: "disable telemetry",
21-
aiConfig: aitelemetry.AIConfig{},
22-
disableAll: false,
23-
disableMetric: true,
24-
disableTrace: true,
25-
wantErr: true,
26-
},
27-
{
28-
name: "empty aiconfig",
20+
name: "disabled telemetry with empty aiconfig",
2921
aiConfig: aitelemetry.AIConfig{},
3022
disableAll: true,
3123
disableMetric: true,

0 commit comments

Comments
 (0)