From 5f153088f8e37f13e7e03def741dea5612432a5d Mon Sep 17 00:00:00 2001 From: Rashmi Chandrashekar Date: Mon, 4 Nov 2024 17:07:44 -0800 Subject: [PATCH] adding telemetry --- .../prom-config-validator-builder/main.go | 21 ++++++++++++------- .../mp/tomlparser-set-global-config.go | 10 ++++----- .../telegraf-prometheus-collector-ds.conf | 2 ++ ...egraf-prometheus-collector-ta-enabled.conf | 3 ++- ...telegraf-prometheus-collector-windows.conf | 2 ++ 5 files changed, 25 insertions(+), 13 deletions(-) diff --git a/otelcollector/prom-config-validator-builder/main.go b/otelcollector/prom-config-validator-builder/main.go index 6463e6f1..1724c98c 100644 --- a/otelcollector/prom-config-validator-builder/main.go +++ b/otelcollector/prom-config-validator-builder/main.go @@ -221,14 +221,21 @@ func generateOtelConfig(promFilePath string, outputFilePath string, otelConfigTe globalSettings := globalSettingsFromMergedOtelConfig.(map[interface{}]interface{}) scrapeInterval := globalSettings["scrape_interval"] if (len(globalSettings) > 1) || (len(globalSettings) == 1 && scrapeInterval != "15s") { - if os.Getenv("CONTROLLER_TYPE") == "ReplicaSet" { - os.Setenv("AZMON_GLOBAL_SETTINGS_ENABLED_REPLICASET", "true") - } else if os.Getenv("CONTROLLER_TYPE") == "DaemonSet" && os.Getenv("OS_TYPE") == "linux" { - os.Setenv("AZMON_GLOBAL_SETTINGS_ENABLED_DAEMONSET_LINUX", "true") - } else if os.Getenv("CONTROLLER_TYPE") == "DaemonSet" && os.Getenv("OS_TYPE") != "linux" { - os.Setenv("AZMON_GLOBAL_SETTINGS_ENABLED_DAEMONSET_WINDOWS", "true") + setEnvVarString := fmt.Sprintf("export AZMON_GLOBAL_SETTINGS_CONFIGURED=\"true\"\n") + file, err := os.OpenFile("/opt/microsoft/prom_config_validator_env_var", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) + if err != nil { + log.Println("prom-config-validator::Unable to open file - prom_config_validator_env_var") + } + _, err = file.Write([]byte(setEnvVarString)) + if err != nil { + log.Println("prom-config-validator::Unable to write to the file prom_config_validator_env_var") + } + file.Close() + if err != nil { + log.Println("prom-config-validator::Unable to close file prom_config_validator_env_var", err) + } else { + log.Printf("prom-config-validator::Successfully set env variables for global config in file prom_config_validator_env_var\n") } - fmt.Printf("prom-config-validator::Successfully set env variables for global config\n") } } diff --git a/otelcollector/shared/configmap/mp/tomlparser-set-global-config.go b/otelcollector/shared/configmap/mp/tomlparser-set-global-config.go index 8143d967..2b396272 100644 --- a/otelcollector/shared/configmap/mp/tomlparser-set-global-config.go +++ b/otelcollector/shared/configmap/mp/tomlparser-set-global-config.go @@ -43,14 +43,14 @@ func SetGlobalSettingsInCollectorConfig() { mergedCollectorConfigPath := "/opt/microsoft/otelcollector/collector-config.yml" mergedCollectorConfigFileContents, err := os.ReadFile(mergedCollectorConfigPath) if err != nil { - fmt.Printf("config-reader::Unable to read file contents from: %s - %v\n", mergedCollectorConfigPath, err) + fmt.Printf("Unable to read file contents from: %s - %v\n", mergedCollectorConfigPath, err) return } var promScrapeConfig map[string]interface{} var otelConfig OtelConfig err = yaml.Unmarshal([]byte(mergedCollectorConfigFileContents), &otelConfig) if err != nil { - fmt.Printf("config-reader::Unable to unmarshal merged otel configuration from: %s - %v\n", mergedCollectorConfigFileContents, err) + fmt.Printf("Unable to unmarshal merged otel configuration from: %s - %v\n", mergedCollectorConfigFileContents, err) return } @@ -62,20 +62,20 @@ func SetGlobalSettingsInCollectorConfig() { collectorConfigReplicasetPath := "/opt/microsoft/otelcollector/collector-config-replicaset.yml" replicasetCollectorConfigFileContents, err := os.ReadFile(collectorConfigReplicasetPath) if err != nil { - fmt.Printf("config-reader::Unable to read file contents from: %s - %v\n", replicasetCollectorConfigFileContents, err) + fmt.Printf("Unable to read file contents from: %s - %v\n", replicasetCollectorConfigFileContents, err) return } var otelConfigReplicaset OtelConfig err = yaml.Unmarshal([]byte(replicasetCollectorConfigFileContents), &otelConfigReplicaset) if err != nil { - fmt.Printf("config-reader::Unable to unmarshal merged otel configuration from: %s - %v\n", replicasetCollectorConfigFileContents, err) + fmt.Printf("Unable to unmarshal merged otel configuration from: %s - %v\n", replicasetCollectorConfigFileContents, err) return } otelConfigReplicaset.Receivers.Prometheus.Config = map[string]interface{}{"global": ""} otelConfigReplicaset.Receivers.Prometheus.Config["global"] = globalSettingsFromMergedOtelConfig otelReplacedConfigYaml, _ := yaml.Marshal(otelConfigReplicaset) if err := os.WriteFile(collectorConfigReplicasetPath, otelReplacedConfigYaml, 0644); err != nil { - fmt.Printf("config-reader::Unable to write to: %s - %v\n", collectorConfigReplicasetPath, err) + fmt.Printf("Unable to write to: %s - %v\n", collectorConfigReplicasetPath, err) return } diff --git a/otelcollector/telegraf/telegraf-prometheus-collector-ds.conf b/otelcollector/telegraf/telegraf-prometheus-collector-ds.conf index 8163eb3a..917e2506 100644 --- a/otelcollector/telegraf/telegraf-prometheus-collector-ds.conf +++ b/otelcollector/telegraf/telegraf-prometheus-collector-ds.conf @@ -34,6 +34,8 @@ ostype = "$OS_TYPE" mip="$MINIMAL_INGESTION_PROFILE" daemonsetGlobalSettingsEnabled= "$AZMON_GLOBAL_SETTINGS_ENABLED_DAEMONSET_LINUX" + setGlobalSettings= "$AZMON_SET_GLOBAL_SETTINGS" + globalSettingsConfigured = "AZMON_GLOBAL_SETTINGS_CONFIGURED" # Configuration for telegraf agent [agent] diff --git a/otelcollector/telegraf/telegraf-prometheus-collector-ta-enabled.conf b/otelcollector/telegraf/telegraf-prometheus-collector-ta-enabled.conf index d5ee1048..addfef9e 100644 --- a/otelcollector/telegraf/telegraf-prometheus-collector-ta-enabled.conf +++ b/otelcollector/telegraf/telegraf-prometheus-collector-ta-enabled.conf @@ -37,7 +37,8 @@ operatormodelcfgmapsetting = "$AZMON_OPERATOR_ENABLED_CFG_MAP_SETTING" operatormodelchartsetting = "$AZMON_OPERATOR_ENABLED_CHART_SETTING" collectorHpaEnabled = "$AZMON_COLLECTOR_HPA_ENABLED" - replicasetGlobalSettingsEnabled= "$AZMON_GLOBAL_SETTINGS_ENABLED_REPLICASET" + setGlobalSettings= "$AZMON_SET_GLOBAL_SETTINGS" + globalSettingsConfigured = "AZMON_GLOBAL_SETTINGS_CONFIGURED" # Configuration for telegraf agent [agent] diff --git a/otelcollector/telegraf/telegraf-prometheus-collector-windows.conf b/otelcollector/telegraf/telegraf-prometheus-collector-windows.conf index d8533938..cfa6fa63 100644 --- a/otelcollector/telegraf/telegraf-prometheus-collector-windows.conf +++ b/otelcollector/telegraf/telegraf-prometheus-collector-windows.conf @@ -36,6 +36,8 @@ debugmodeenabled = "$DEBUG_MODE_ENABLED" windowsVersion = "$windowsVersion" windowsdaemonsetGlobalSettingsEnabled= "$AZMON_GLOBAL_SETTINGS_ENABLED_DAEMONSET_WINDOWS" + setGlobalSettings= "$AZMON_SET_GLOBAL_SETTINGS" + globalSettingsConfigured = "AZMON_GLOBAL_SETTINGS_CONFIGURED" # Configuration for telegraf agent