Skip to content

fix: Fixing CNI Telemtry Service run by CNS #3824

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 30 additions & 4 deletions cns/service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
// Service name.
name = "azure-cns"
pluginName = "azure-vnet"
aiPluginName = "AzureCNI"
Copy link
Preview

Copilot AI Jul 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a typo in the PR title 'Telemtry' which should be 'Telemetry'. While this constant name is correct, ensure consistency in naming throughout the codebase.

Copilot uses AI. Check for mistakes.

endpointStoreName = "azure-endpoints"
endpointStoreLocationLinux = "/var/run/azure-cns/"
endpointStoreLocationWindows = "/k/azurecns/"
Expand Down Expand Up @@ -470,11 +471,36 @@
return nil
}

func startTelemetryService(ctx context.Context) {
var config aitelemetry.AIConfig
func startTelemetryService(ctx context.Context, cnsconfig *configuration.CNSConfig) {
// Use the same telemetry settings as the main CNS service
ts := cnsconfig.TelemetrySettings

// Check if telemetry is disabled
if ts.DisableAll {
logger.Printf("Telemetry is disabled, skipping CNI telemetry service")

Check failure on line 480 in cns/service/main.go

View workflow job for this annotation

GitHub Actions / Lint (1.23.x, ubuntu-latest)

SA1019: logger.Printf is deprecated: The global logger is deprecated. Migrate to zap using the cns/logger/v2 package and pass the logger instead. (staticcheck)

Check failure on line 480 in cns/service/main.go

View workflow job for this annotation

GitHub Actions / Lint (1.22.x, windows-latest)

SA1019: logger.Printf is deprecated: The global logger is deprecated. Migrate to zap using the cns/logger/v2 package and pass the logger instead. (staticcheck)

Check failure on line 480 in cns/service/main.go

View workflow job for this annotation

GitHub Actions / Lint (1.22.x, ubuntu-latest)

SA1019: logger.Printf is deprecated: The global logger is deprecated. Migrate to zap using the cns/logger/v2 package and pass the logger instead. (staticcheck)

Check failure on line 480 in cns/service/main.go

View workflow job for this annotation

GitHub Actions / Lint (1.23.x, windows-latest)

SA1019: logger.Printf is deprecated: The global logger is deprecated. Migrate to zap using the cns/logger/v2 package and pass the logger instead. (staticcheck)
return
}

aiConfig := aitelemetry.AIConfig{
AppName: aiPluginName,
AppVersion: version,
BatchSize: ts.TelemetryBatchSizeBytes,
BatchInterval: ts.TelemetryBatchIntervalInSecs,
RefreshTimeout: ts.RefreshIntervalInSecs,
DisableMetadataRefreshThread: ts.DisableMetadataRefreshThread,
DebugMode: ts.DebugMode,
}

tb := telemetry.NewTelemetryBuffer(nil)
err := tb.CreateAITelemetryHandle(config, false, false, false)

var err error
if cnsconfig.TelemetrySettings.AppInsightsInstrumentationKey != "" {
err = tb.CreateAITelemetryHandle(aiConfig, ts.DisableTrace, ts.DisableMetric, ts.DisableEvent)
} else {
logger.Printf("No Application Insights key provided for CNI telemetry service")

Check failure on line 500 in cns/service/main.go

View workflow job for this annotation

GitHub Actions / Lint (1.23.x, ubuntu-latest)

SA1019: logger.Printf is deprecated: The global logger is deprecated. Migrate to zap using the cns/logger/v2 package and pass the logger instead. (staticcheck)

Check failure on line 500 in cns/service/main.go

View workflow job for this annotation

GitHub Actions / Lint (1.22.x, windows-latest)

SA1019: logger.Printf is deprecated: The global logger is deprecated. Migrate to zap using the cns/logger/v2 package and pass the logger instead. (staticcheck)

Check failure on line 500 in cns/service/main.go

View workflow job for this annotation

GitHub Actions / Lint (1.22.x, ubuntu-latest)

SA1019: logger.Printf is deprecated: The global logger is deprecated. Migrate to zap using the cns/logger/v2 package and pass the logger instead. (staticcheck)

Check failure on line 500 in cns/service/main.go

View workflow job for this annotation

GitHub Actions / Lint (1.23.x, windows-latest)

SA1019: logger.Printf is deprecated: The global logger is deprecated. Migrate to zap using the cns/logger/v2 package and pass the logger instead. (staticcheck)
Comment on lines +497 to +500
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should check other way and remove else?

if cnsconfig.TelemetrySettings.AppInsightsInstrumentationKey == "" {
  logger.Printf("No Application Insights key provided for CNI telemetry service")
  return
}
err = tb.CreateAITelemetryHandle(aiConfig, ts.DisableTrace, ts.DisableMetric, ts.DisableEvent)

return
}

if err != nil {
logger.Errorf("AI telemetry handle creation failed: %v", err)
return
Expand Down Expand Up @@ -705,7 +731,7 @@

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

// Log platform information.
Expand Down
Loading