-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding support for global settings (#1003)
[comment]: # (Note that your PR title should follow the conventional commit format: https://conventionalcommits.org/en/v1.0.0/#summary) # PR Description Adding support for global settings [comment]: # (The below checklist is for PRs adding new features. If a box is not checked, add a reason why it's not needed.) # New Feature Checklist - [ ] List telemetry added about the feature. - [ ] Link to the one-pager about the feature. - [ ] List any tasks necessary for release (3P docs, AKS RP chart changes, etc.) after merging the PR. - [ ] Attach results of scale and perf testing. [comment]: # (The below checklist is for code changes. Not all boxes necessarily need to be checked. Build, doc, and template changes do not need to fill out the checklist.) # Tests Checklist - [ ] Have end-to-end Ginkgo tests been run on your cluster and passed? To bootstrap your cluster to run the tests, follow [these instructions](/otelcollector/test/README.md#bootstrap-a-dev-cluster-to-run-ginkgo-tests). - Labels used when running the tests on your cluster: - [ ] `operator` - [ ] `windows` - [ ] `arm64` - [ ] `arc-extension` - [ ] `fips` - [ ] Have new tests been added? For features, have tests been added for this feature? For fixes, is there a test that could have caught this issue and could validate that the fix works? - [ ] Is a new scrape job needed? - [ ] The scrape job was added to the folder [test-cluster-yamls](/otelcollector/test/test-cluster-yamls/) in the correct configmap or as a CR. - [ ] Was a new test label added? - [ ] A string constant for the label was added to [constants.go](/otelcollector/test/utils/constants.go). - [ ] The label and description was added to the [test README](/otelcollector/test/README.md). - [ ] The label was added to this [PR checklist](/.github/pull_request_template). - [ ] The label was added as needed to [testkube-test-crs.yaml](/otelcollector/test/testkube/testkube-test-crs.yaml). - [ ] Are additional API server permissions needed for the new tests? - [ ] These permissions have been added to [api-server-permissions.yaml](/otelcollector/test/testkube/api-server-permissions.yaml). - [ ] Was a new test suite (a new folder under `/tests`) added? - [ ] The new test suite is included in [testkube-test-crs.yaml](/otelcollector/test/testkube/testkube-test-crs.yaml).
- Loading branch information
1 parent
20ec5bd
commit dc1cb99
Showing
7 changed files
with
125 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
otelcollector/shared/configmap/mp/tomlparser-set-global-config.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package configmapsettings | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
|
||
yaml "gopkg.in/yaml.v2" | ||
) | ||
|
||
type OtelConfig struct { | ||
Exporters interface{} `yaml:"exporters"` | ||
Processors interface{} `yaml:"processors"` | ||
Extensions interface{} `yaml:"extensions"` | ||
Receivers struct { | ||
Prometheus struct { | ||
Config map[string]interface{} `yaml:"config"` | ||
TargetAllocator interface{} `yaml:"target_allocator"` | ||
} `yaml:"prometheus"` | ||
} `yaml:"receivers"` | ||
Service struct { | ||
Extensions interface{} `yaml:"extensions"` | ||
Pipelines struct { | ||
Metrics struct { | ||
Exporters interface{} `yaml:"exporters"` | ||
Processors interface{} `yaml:"processors"` | ||
Receivers interface{} `yaml:"receivers"` | ||
} `yaml:"metrics"` | ||
} `yaml:"pipelines"` | ||
Telemetry struct { | ||
Logs struct { | ||
Level interface{} `yaml:"level"` | ||
Encoding interface{} `yaml:"encoding"` | ||
} `yaml:"logs"` | ||
} `yaml:"telemetry"` | ||
} `yaml:"service"` | ||
} | ||
|
||
func SetGlobalSettingsInCollectorConfig() { | ||
azmonSetGlobalSettings := os.Getenv("AZMON_SET_GLOBAL_SETTINGS") | ||
|
||
if azmonSetGlobalSettings == "true" { | ||
mergedCollectorConfigPath := "/opt/microsoft/otelcollector/collector-config.yml" | ||
mergedCollectorConfigFileContents, err := os.ReadFile(mergedCollectorConfigPath) | ||
if err != nil { | ||
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("Unable to unmarshal merged otel configuration from: %s - %v\n", mergedCollectorConfigFileContents, err) | ||
return | ||
} | ||
|
||
promScrapeConfig = otelConfig.Receivers.Prometheus.Config | ||
globalSettingsFromMergedOtelConfig := promScrapeConfig["global"] | ||
|
||
if globalSettingsFromMergedOtelConfig != nil { | ||
fmt.Println("Found global settings in merged otel config, triyng to replace replicaset collector config") | ||
collectorConfigReplicasetPath := "/opt/microsoft/otelcollector/collector-config-replicaset.yml" | ||
replicasetCollectorConfigFileContents, err := os.ReadFile(collectorConfigReplicasetPath) | ||
if err != nil { | ||
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("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("Unable to write to: %s - %v\n", collectorConfigReplicasetPath, err) | ||
return | ||
} | ||
|
||
log.Println("Updated file with global settings", collectorConfigReplicasetPath) | ||
return | ||
} | ||
fmt.Println("Global settings are empty in custom config map, making no replacement") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters