Skip to content

Commit ba84f91

Browse files
committed
Add loglevel config option when printing application insight logs
1 parent 8a8eff1 commit ba84f91

File tree

6 files changed

+13
-7
lines changed

6 files changed

+13
-7
lines changed

npm/cmd/start.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ func start(config npmconfig.Config, flags npmconfig.Flags) error {
135135
)
136136
}
137137

138-
err = metrics.CreateTelemetryHandle(config.NPMVersion(), version, npm.GetAIMetadata())
138+
err = metrics.CreateTelemetryHandle(config.NPMVersion(), version, npm.GetAIMetadata(), npmconfig.DefaultConfig.LogLevel)
139139
if err != nil {
140140
klog.Infof("CreateTelemetryHandle failed with error %v. AITelemetry is not initialized.", err)
141141
}

npm/cmd/start_daemon.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func startDaemon(config npmconfig.Config) error {
9494
return fmt.Errorf("failed to create dataplane: %w", err)
9595
}
9696

97-
err = metrics.CreateTelemetryHandle(config.NPMVersion(), version, npm.GetAIMetadata())
97+
err = metrics.CreateTelemetryHandle(config.NPMVersion(), version, npm.GetAIMetadata(), npmconfig.DefaultConfig.LogLevel)
9898
if err != nil {
9999
klog.Infof("CreateTelemetryHandle failed with error %v. AITelemetry is not initialized.", err)
100100
}

npm/cmd/start_server.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func startControlplane(config npmconfig.Config, flags npmconfig.Flags) error {
113113
return fmt.Errorf("failed to create NPM controlplane manager: %w", err)
114114
}
115115

116-
err = metrics.CreateTelemetryHandle(config.NPMVersion(), version, npm.GetAIMetadata())
116+
err = metrics.CreateTelemetryHandle(config.NPMVersion(), version, npm.GetAIMetadata(), npmconfig.DefaultConfig.LogLevel)
117117
if err != nil {
118118
klog.Infof("CreateTelemetryHandle failed with error %v. AITelemetry is not initialized.", err)
119119
}

npm/config/config.go

+4
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ var DefaultConfig = Config{
5353
NetPolInBackground: true,
5454
EnableNPMLite: false,
5555
},
56+
57+
// Setting LogLevel to "info" by default. Set to "debug" to get application insight logs (creates a listener that outputs diagnosticMessageWriter logs).
58+
LogLevel: "debug",
5659
}
5760

5861
type GrpcServerConfig struct {
@@ -82,6 +85,7 @@ type Config struct {
8285
MaxPendingNetPols int `json:"MaxPendingNetPols,omitempty"`
8386
NetPolInvervalInMilliseconds int `json:"NetPolInvervalInMilliseconds,omitempty"`
8487
Toggles Toggles `json:"Toggles,omitempty"`
88+
LogLevel string `json:"LogLevel,omitempty"`
8589
}
8690

8791
type Toggles struct {

npm/metrics/ai-utils.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package metrics
33
import (
44
"fmt"
55
"strconv"
6+
"strings"
67
"time"
78

89
"github.com/Azure/azure-container-networking/aitelemetry"
@@ -21,15 +22,18 @@ var (
2122
)
2223

2324
// CreateTelemetryHandle creates a handler to initialize AI telemetry
24-
func CreateTelemetryHandle(npmVersionNum int, imageVersion, aiMetadata string) error {
25+
func CreateTelemetryHandle(npmVersionNum int, imageVersion, aiMetadata, logLevel string) error {
2526
npmVersion = npmVersionNum
27+
debugMode := strings.EqualFold(logLevel, "debug")
28+
klog.Infof("LogLevel is %s. Debugmode is set to: %v.", logLevel, debugMode)
29+
2630
aiConfig := aitelemetry.AIConfig{
2731
AppName: util.AzureNpmFlag,
2832
AppVersion: imageVersion,
2933
BatchSize: util.BatchSizeInBytes,
3034
BatchInterval: util.BatchIntervalInSecs,
3135
RefreshTimeout: util.RefreshTimeoutInSecs,
32-
DebugMode: util.DebugMode,
36+
DebugMode: debugMode,
3337
GetEnvRetryCount: util.GetEnvRetryCount,
3438
GetEnvRetryWaitTimeInSecs: util.GetEnvRetryWaitTimeInSecs,
3539
}

npm/util/const.go

-2
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,6 @@ const (
238238
AiInitializeRetryCount int = 3
239239
AiInitializeRetryInMin int = 1
240240

241-
DebugMode bool = true
242-
243241
ErrorValue float64 = 1
244242
)
245243

0 commit comments

Comments
 (0)