Skip to content

Commit

Permalink
fix: ccp minimal ingestion profile setting and respecting the keep li…
Browse files Browse the repository at this point in the history
…st regex values (#886)

[comment]: # (Note that your PR title should follow the conventional
commit format: https://conventionalcommits.org/en/v1.0.0/#summary)
# PR Description

[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`
- [ ] 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
bragi92 authored May 17, 2024
1 parent 6713266 commit e2fdc6a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 32 deletions.
1 change: 0 additions & 1 deletion otelcollector/shared/definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ type RegexValues struct {
ControlplaneApiserver string
ControlplaneClusterAutoscaler string
ControlplaneEtcd string
MinimalIngestionProfile string
}

// FilesystemConfigLoader implements ConfigLoader for file-based configuration loading.
Expand Down
2 changes: 1 addition & 1 deletion otelcollector/shared/prometheus-ccp-config-merger.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func appendMetricRelabelConfig(yamlConfigFile, keepListRegex string) {

if scrapeConfigs, ok := config["scrape_configs"].([]interface{}); ok {
for _, scfg := range scrapeConfigs {
if scfgMap, ok := scfg.(map[string]interface{}); ok {
if scfgMap, ok := scfg.(map[interface{}]interface{}); ok {
if metricRelabelCfgs, ok := scfgMap["metric_relabel_configs"].([]interface{}); ok {
scfgMap["metric_relabel_configs"] = append(metricRelabelCfgs, keepListMetricRelabelConfig)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

var (
configMapMountPath = "/etc/config/settings/default-targets-metrics-keep-list"
configSchemaVersion, minimalIngestionProfile string
configSchemaVersion string
controlplaneApiserverRegex, controlplaneClusterAutoscalerRegex string
controlplaneKubeSchedulerRegex, controlplaneKubeControllerManagerRegex string
controlplaneEtcdRegex string
Expand Down Expand Up @@ -61,7 +61,6 @@ func parseConfigMapForKeepListRegex() map[string]interface{} {
configMap["controlplane-apiserver"] = getStringValue(tree.Get("controlplane-apiserver"))
configMap["controlplane-cluster-autoscaler"] = getStringValue(tree.Get("controlplane-cluster-autoscaler"))
configMap["controlplane-etcd"] = getStringValue(tree.Get("controlplane-etcd"))
configMap["minimalingestionprofile"] = getStringValue(tree.Get("minimalingestionprofile"))

return configMap
}
Expand All @@ -78,7 +77,6 @@ func populateSettingValuesFromConfigMap(parsedConfig map[string]interface{}) (Re
ControlplaneApiserver: getStringValue(parsedConfig["controlplane-apiserver"]),
ControlplaneClusterAutoscaler: getStringValue(parsedConfig["controlplane-cluster-autoscaler"]),
ControlplaneEtcd: getStringValue(parsedConfig["controlplane-etcd"]),
MinimalIngestionProfile: getStringValue(parsedConfig["minimalingestionprofile"]),
}

// Validate regex values
Expand All @@ -97,40 +95,33 @@ func populateSettingValuesFromConfigMap(parsedConfig map[string]interface{}) (Re
if regexValues.ControlplaneEtcd != "" && !isValidRegex(regexValues.ControlplaneEtcd) {
return regexValues, fmt.Errorf("invalid regex for controlplane-etcd: %s", regexValues.ControlplaneEtcd)
}
if regexValues.MinimalIngestionProfile != "" && !isValidRegex(regexValues.MinimalIngestionProfile) {
return regexValues, fmt.Errorf("invalid regex for MinimalIngestionProfile: %s", regexValues.MinimalIngestionProfile)
}

// Logging the values being set
fmt.Printf("controlplaneKubeControllerManagerRegex: %s\n", regexValues.ControlplaneKubeControllerManager)
fmt.Printf("controlplaneKubeSchedulerRegex: %s\n", regexValues.ControlplaneKubeScheduler)
fmt.Printf("controlplaneApiserverRegex: %s\n", regexValues.ControlplaneApiserver)
fmt.Printf("controlplaneClusterAutoscalerRegex: %s\n", regexValues.ControlplaneClusterAutoscaler)
fmt.Printf("controlplaneEtcdRegex: %s\n", regexValues.ControlplaneEtcd)
fmt.Printf("minimalIngestionProfile: %s\n", regexValues.MinimalIngestionProfile)
fmt.Printf("populateSettingValuesFromConfigMap::controlplaneKubeControllerManagerRegex: %s\n", regexValues.ControlplaneKubeControllerManager)
fmt.Printf("populateSettingValuesFromConfigMap::controlplaneKubeSchedulerRegex: %s\n", regexValues.ControlplaneKubeScheduler)
fmt.Printf("populateSettingValuesFromConfigMap::controlplaneApiserverRegex: %s\n", regexValues.ControlplaneApiserver)
fmt.Printf("populateSettingValuesFromConfigMap::controlplaneClusterAutoscalerRegex: %s\n", regexValues.ControlplaneClusterAutoscaler)
fmt.Printf("populateSettingValuesFromConfigMap::controlplaneEtcdRegex: %s\n", regexValues.ControlplaneEtcd)

return regexValues, nil // Return regex values and nil error if everything is valid
}

func populateRegexValuesWithMinimalIngestionProfile(regexValues RegexValues) {
if regexValues.MinimalIngestionProfile == "true" {
controlplaneKubeControllerManagerRegex += regexValues.ControlplaneKubeControllerManager + "|" + controlplaneKubeControllerManagerMinMac
controlplaneKubeSchedulerRegex += regexValues.ControlplaneKubeScheduler + "|" + controlplaneKubeSchedulerMinMac
controlplaneApiserverRegex += regexValues.ControlplaneApiserver + "|" + controlplaneApiserverMinMac
controlplaneClusterAutoscalerRegex += regexValues.ControlplaneClusterAutoscaler + "|" + controlplaneClusterAutoscalerMinMac
controlplaneEtcdRegex += regexValues.ControlplaneEtcd + "|" + controlplaneEtcdMinMac

// Print the updated regex strings after appending values
// Only log this in debug mode
// fmt.Println("Updated Regex Strings After Appending:")
// fmt.Println("ControlplaneKubeControllerManagerRegex:", controlplaneKubeControllerManagerRegex)
// fmt.Println("ControlplaneKubeSchedulerRegex:", controlplaneKubeSchedulerRegex)
// fmt.Println("ControlplaneApiserverRegex:", controlplaneApiserverRegex)
// fmt.Println("ControlplaneClusterAutoscalerRegex:", controlplaneClusterAutoscalerRegex)
// fmt.Println("ControlplaneEtcdRegex:", controlplaneEtcdRegex)
} else {
fmt.Println("minimalIngestionProfile:", regexValues.MinimalIngestionProfile)
}
controlplaneKubeControllerManagerRegex += regexValues.ControlplaneKubeControllerManager + "|" + controlplaneKubeControllerManagerMinMac
controlplaneKubeSchedulerRegex += regexValues.ControlplaneKubeScheduler + "|" + controlplaneKubeSchedulerMinMac
controlplaneApiserverRegex += regexValues.ControlplaneApiserver + "|" + controlplaneApiserverMinMac
controlplaneClusterAutoscalerRegex += regexValues.ControlplaneClusterAutoscaler + "|" + controlplaneClusterAutoscalerMinMac
controlplaneEtcdRegex += regexValues.ControlplaneEtcd + "|" + controlplaneEtcdMinMac

// Print the updated regex strings after appending values
// Only log this in debug mode
// fmt.Println("Updated Regex Strings After Appending:")
// fmt.Println("ControlplaneKubeControllerManagerRegex:", controlplaneKubeControllerManagerRegex)
// fmt.Println("ControlplaneKubeSchedulerRegex:", controlplaneKubeSchedulerRegex)
// fmt.Println("ControlplaneApiserverRegex:", controlplaneApiserverRegex)
// fmt.Println("ControlplaneClusterAutoscalerRegex:", controlplaneClusterAutoscalerRegex)
// fmt.Println("ControlplaneEtcdRegex:", controlplaneEtcdRegex)

}

func tomlparserCCPTargetsMetricsKeepList() {
Expand Down

0 comments on commit e2fdc6a

Please sign in to comment.