Skip to content

Commit

Permalink
backport: fix: pass ai metadata to telemetry during cni image build (#…
Browse files Browse the repository at this point in the history
…3095) (#3132)

* 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

* add cni ai info to cni image args and linux dockerfile
  • Loading branch information
QxBytes authored Nov 14, 2024
1 parent 13922b1 commit 46afd5e
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ cni-image: ## build cni container image.
$(MAKE) container \
DOCKERFILE=cni/$(OS).Dockerfile \
IMAGE=$(CNI_IMAGE) \
EXTRA_BUILD_ARGS='--build-arg OS=$(OS) --build-arg ARCH=$(ARCH) --build-arg OS_VERSION=$(OS_VERSION)' \
EXTRA_BUILD_ARGS='--build-arg OS=$(OS) --build-arg ARCH=$(ARCH) --build-arg OS_VERSION=$(OS_VERSION) --build-arg CNI_AI_PATH=$(CNI_AI_PATH) --build-arg CNI_AI_ID=$(CNI_AI_ID)' \
PLATFORM=$(PLATFORM) \
TAG=$(CNI_PLATFORM_TAG) \
OS=$(OS) \
Expand Down
4 changes: 3 additions & 1 deletion cni/linux.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ ARG OS
FROM mcr.microsoft.com/oss/go/microsoft/golang:1.22 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/azurecni-stateless -trimpath -ldflags "-X main.version="$VERSION"" -gcflags="-dwarflocationlists=true" cni/network/stateless/main.go

Expand Down
4 changes: 2 additions & 2 deletions cni/telemetry/service/telemetrymain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
4 changes: 3 additions & 1 deletion cni/windows.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ ARG OS_VERSION
FROM --platform=linux/${ARCH} mcr.microsoft.com/oss/go/microsoft/golang:1.22 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

Expand Down
2 changes: 1 addition & 1 deletion cns/service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ func main() {
}

if telemetryDaemonEnabled {
log.Printf("CNI Telemtry is enabled")
logger.Printf("CNI Telemetry is enabled")
go startTelemetryService(rootCtx)
}

Expand Down
10 changes: 1 addition & 9 deletions telemetry/aiwrapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 46afd5e

Please sign in to comment.