From ffea69f1ed90a0b0d415bd8385062394c5d84994 Mon Sep 17 00:00:00 2001 From: Carpe-Wang <1592622761@qq.com> Date: Wed, 19 Jun 2024 13:40:27 +0800 Subject: [PATCH 1/3] refactor: To ensure telemetry is only enabled when both conditions are met. Signed-off-by: Carpe-Wang <1592622761@qq.com> --- init/retina/main_linux.go | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/init/retina/main_linux.go b/init/retina/main_linux.go index 70152b5796..b0dc2f02ba 100644 --- a/init/retina/main_linux.go +++ b/init/retina/main_linux.go @@ -4,7 +4,10 @@ package main import ( + "flag" + "github.com/microsoft/retina/pkg/bpf" + "github.com/microsoft/retina/pkg/config" "github.com/microsoft/retina/pkg/log" "github.com/microsoft/retina/pkg/telemetry" "go.uber.org/zap" @@ -21,9 +24,24 @@ var ( func main() { // Initialize logger opts := log.GetDefaultLogOpts() + zl, err := log.SetupZapLogger(opts) + if err != nil { + panic(err) + } + + // Define a command-line flag "config" with a default value and parse the flags, then create a logger with a name and version. + configPath := flag.String("config", "/retina/config/config.yaml", "path to the config file") + flag.Parse() + l := zl.Named("init-retina").With(zap.String("version", version)) + + // Load configuration + cfg, err := config.GetConfig(*configPath) + if err != nil { + l.Fatal("Failed to get config", zap.Error(err)) + } // Enable telemetry if applicationInsightsID is provided - if applicationInsightsID != "" { + if applicationInsightsID != "" && cfg.EnableTelemetry { opts.EnableTelemetry = true opts.ApplicationInsightsID = applicationInsightsID // Initialize application insights @@ -31,13 +49,6 @@ func main() { defer telemetry.ShutdownAppInsights() defer telemetry.TrackPanic() } - - zl, err := log.SetupZapLogger(opts) - if err != nil { - panic(err) - } - l := zl.Named("init-retina").With(zap.String("version", version)) - // Setup BPF bpf.Setup(l) } From 918ba06aff28270150e63f592c437ff0a0c6be01 Mon Sep 17 00:00:00 2001 From: Carpe-Wang <1592622761@qq.com> Date: Thu, 20 Jun 2024 11:41:44 +0800 Subject: [PATCH 2/3] the path to the config via arguments to the init-container Signed-off-by: Carpe-Wang <1592622761@qq.com> --- .../manifests/controller/helm/retina/templates/daemonset.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/deploy/manifests/controller/helm/retina/templates/daemonset.yaml b/deploy/manifests/controller/helm/retina/templates/daemonset.yaml index c712ca9405..f84c260d20 100644 --- a/deploy/manifests/controller/helm/retina/templates/daemonset.yaml +++ b/deploy/manifests/controller/helm/retina/templates/daemonset.yaml @@ -37,6 +37,8 @@ spec: - name: bpf mountPath: /sys/fs/bpf mountPropagation: Bidirectional + args: + - --config=/retina/config/config.yaml containers: - name: {{ include "retina.name" . }} livenessProbe: From c4665afa7d360dfeacf443903f0093e3015322be Mon Sep 17 00:00:00 2001 From: Carpe-Wang <1592622761@qq.com> Date: Sat, 22 Jun 2024 09:11:53 +0800 Subject: [PATCH 3/3] the path to the config via arguments to the init-container Signed-off-by: Carpe-Wang <1592622761@qq.com> --- deploy/manifests/controller/helm/retina/templates/daemonset.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/deploy/manifests/controller/helm/retina/templates/daemonset.yaml b/deploy/manifests/controller/helm/retina/templates/daemonset.yaml index f84c260d20..5a3a5a4b20 100644 --- a/deploy/manifests/controller/helm/retina/templates/daemonset.yaml +++ b/deploy/manifests/controller/helm/retina/templates/daemonset.yaml @@ -62,6 +62,7 @@ spec: {{- range $.Values.daemonset.container.retina.args}} - {{ . | quote }} {{- end}} + - --config=/retina/config/config.yaml {{- end}} ports: - name: retina