Skip to content

Commit

Permalink
adding telemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
rashmichandrashekar committed Nov 5, 2024
1 parent 12abd1b commit 5f15308
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 13 deletions.
21 changes: 14 additions & 7 deletions otelcollector/prom-config-validator-builder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}

Expand Down
2 changes: 2 additions & 0 deletions otelcollector/telegraf/telegraf-prometheus-collector-ds.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5f15308

Please sign in to comment.