From b01b576a1607cdde5bd83ba81395a562aad45129 Mon Sep 17 00:00:00 2001 From: Juan Manuel Perez Date: Tue, 3 Sep 2024 16:26:16 +0200 Subject: [PATCH 1/3] honor the lowdatamode toogle at common-library level --- charts/nr-k8s-otel-collector/Chart.yaml | 2 +- .../templates/_low_data_mode.tpl | 27 ++++++ .../templates/daemonset-configmap.yaml | 4 +- .../templates/deployment-configmap.yaml | 4 +- .../tests/lowdatamode_test.yaml | 87 +++++++++++++++++++ charts/nr-k8s-otel-collector/values.yaml | 4 +- 6 files changed, 121 insertions(+), 7 deletions(-) create mode 100644 charts/nr-k8s-otel-collector/templates/_low_data_mode.tpl create mode 100644 charts/nr-k8s-otel-collector/tests/lowdatamode_test.yaml diff --git a/charts/nr-k8s-otel-collector/Chart.yaml b/charts/nr-k8s-otel-collector/Chart.yaml index e8da89632..8c865e81c 100644 --- a/charts/nr-k8s-otel-collector/Chart.yaml +++ b/charts/nr-k8s-otel-collector/Chart.yaml @@ -17,7 +17,7 @@ type: application # This is the chart version. This version number should be incremented each time you make changes # to the chart and its templates, including the app version. # Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 0.7.4 +version: 0.7.5 dependencies: - name: common-library diff --git a/charts/nr-k8s-otel-collector/templates/_low_data_mode.tpl b/charts/nr-k8s-otel-collector/templates/_low_data_mode.tpl new file mode 100644 index 000000000..8ee0ccee5 --- /dev/null +++ b/charts/nr-k8s-otel-collector/templates/_low_data_mode.tpl @@ -0,0 +1,27 @@ +{{- /* +This helper detect if the user set a value for the LowDataMode toogle and use it or defaults to `true`. +*/ -}} +{{- define "nrKubernetesOtel.lowDataMode" -}} +{{- $userSetAValue := false -}} +{{- $lowDataMode := "" -}} + +{{- $global := index .Values "global" | default dict -}} +{{- if get $global "lowDataMode" | kindIs "bool" -}} + {{- $userSetAValue = true -}} + {{- $lowDataMode = $global.lowDataMode -}} +{{- end -}} + +{{- if (get .Values "lowDataMode" | kindIs "bool") -}} + {{- $userSetAValue = true -}} + {{- $lowDataMode = .Values.lowDataMode -}} +{{- end -}} + +{{- if $userSetAValue -}} + {{- if $lowDataMode -}} + {{- $lowDataMode -}} + {{- end -}} +{{- else -}} + {{- /* This is the default we need for this chart */ -}} + true +{{- end -}} +{{- end -}} diff --git a/charts/nr-k8s-otel-collector/templates/daemonset-configmap.yaml b/charts/nr-k8s-otel-collector/templates/daemonset-configmap.yaml index ad55bf623..798f192e3 100644 --- a/charts/nr-k8s-otel-collector/templates/daemonset-configmap.yaml +++ b/charts/nr-k8s-otel-collector/templates/daemonset-configmap.yaml @@ -571,7 +571,7 @@ data: - prometheus {{- end }} processors: - {{- if include "newrelic.common.lowDataMode" . }} + {{- if include "nrKubernetesOtel.lowDataMode" . }} - metricstransform/ldm - metricstransform/kubeletstats - metricstransform/cadvisor @@ -594,7 +594,7 @@ data: - resourcedetection/env - resourcedetection/cloudproviders - resource - {{- if include "newrelic.common.lowDataMode" . }} + {{- if include "nrKubernetesOtel.lowDataMode" . }} - transform/low_data_mode_inator - resource/low_data_mode_inator {{- end }} diff --git a/charts/nr-k8s-otel-collector/templates/deployment-configmap.yaml b/charts/nr-k8s-otel-collector/templates/deployment-configmap.yaml index c59bcb5e4..951535bd8 100644 --- a/charts/nr-k8s-otel-collector/templates/deployment-configmap.yaml +++ b/charts/nr-k8s-otel-collector/templates/deployment-configmap.yaml @@ -526,7 +526,7 @@ data: - filter/exclude_zero_value_kube_persistentvolumeclaim_status_phase - filter/exclude_zero_value_kube_pod_status_phase - filter/exclude_zero_value_kube_pod_container_status - {{- if include "newrelic.common.lowDataMode" . }} + {{- if include "nrKubernetesOtel.lowDataMode" . }} - metricstransform/ldm - metricstransform/k8s_cluster_info_ldm - metricstransform/ksm @@ -549,7 +549,7 @@ data: - prometheus processors: - metricstransform/k8s_cluster_info - {{- if include "newrelic.common.lowDataMode" . }} + {{- if include "nrKubernetesOtel.lowDataMode" . }} - metricstransform/ldm - metricstransform/k8s_cluster_info_ldm - metricstransform/apiserver diff --git a/charts/nr-k8s-otel-collector/tests/lowdatamode_test.yaml b/charts/nr-k8s-otel-collector/tests/lowdatamode_test.yaml new file mode 100644 index 000000000..0d9e70e5f --- /dev/null +++ b/charts/nr-k8s-otel-collector/tests/lowdatamode_test.yaml @@ -0,0 +1,87 @@ +suite: lowdatamode +templates: + - templates/deployment-configmap.yaml + - templates/daemonset-configmap.yaml +release: + name: my-release + namespace: my-namespace +tests: + - it: lowDataMode is set by default + set: + cluster: test + global: + lowDataMode: ~ + lowDataMode: ~ + asserts: + - matchRegex: + path: data["deployment-config.yaml"] + pattern: " +- filter/exclude_metrics_low_data_mode" + template: templates/deployment-configmap.yaml + - matchRegex: + path: data["daemonset-config.yaml"] + pattern: " +- filter/exclude_metrics_low_data_mode" + template: templates/daemonset-configmap.yaml + + - it: lowDataMode set to true at global level is honored + set: + cluster: test + global: + lowDataMode: true + lowDataMode: ~ + asserts: + - matchRegex: + path: data["deployment-config.yaml"] + pattern: " +- filter/exclude_metrics_low_data_mode" + template: templates/deployment-configmap.yaml + - matchRegex: + path: data["daemonset-config.yaml"] + pattern: " +- filter/exclude_metrics_low_data_mode" + template: templates/daemonset-configmap.yaml + + - it: lowDataMode set to false at global level is honored + set: + cluster: test + global: + lowDataMode: false + lowDataMode: ~ + asserts: + - notMatchRegex: + path: data["deployment-config.yaml"] + pattern: " +- filter/exclude_metrics_low_data_mode" + template: templates/deployment-configmap.yaml + - notMatchRegex: + path: data["daemonset-config.yaml"] + pattern: " +- filter/exclude_metrics_low_data_mode" + template: templates/daemonset-configmap.yaml + + - it: lowDataMode set to true at local level is honored + set: + cluster: test + global: + lowDataMode: false + lowDataMode: true + asserts: + - matchRegex: + path: data["deployment-config.yaml"] + pattern: " +- filter/exclude_metrics_low_data_mode" + template: templates/deployment-configmap.yaml + - matchRegex: + path: data["daemonset-config.yaml"] + pattern: " +- filter/exclude_metrics_low_data_mode" + template: templates/daemonset-configmap.yaml + + - it: lowDataMode set to false at local level is honored + set: + cluster: test + global: + lowDataMode: true + lowDataMode: false + asserts: + - notMatchRegex: + path: data["deployment-config.yaml"] + pattern: " +- filter/exclude_metrics_low_data_mode" + template: templates/deployment-configmap.yaml + - notMatchRegex: + path: data["daemonset-config.yaml"] + pattern: " +- filter/exclude_metrics_low_data_mode" + template: templates/daemonset-configmap.yaml diff --git a/charts/nr-k8s-otel-collector/values.yaml b/charts/nr-k8s-otel-collector/values.yaml index a296909a4..5d35fdc32 100644 --- a/charts/nr-k8s-otel-collector/values.yaml +++ b/charts/nr-k8s-otel-collector/values.yaml @@ -153,5 +153,5 @@ receivers: enabled: true # -- (bool) Send only the [metrics required](https://github.com/newrelic/helm-charts/tree/master/charts/nr-k8s-otel-collector/docs/metrics-lowDataMode.md) to light up the NR kubernetes UI, this agent defaults to setting lowDataMode true, but if this setting is unset, lowDataMode will be set to false -# @default -- `false` -lowDataMode: true +# @default -- `true` +lowDataMode: From c4c05c30f4ee76c759716ac4d76aeee327ff9518 Mon Sep 17 00:00:00 2001 From: Juan Manuel Perez Date: Tue, 3 Sep 2024 16:29:35 +0200 Subject: [PATCH 2/3] update README --- charts/nr-k8s-otel-collector/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charts/nr-k8s-otel-collector/README.md b/charts/nr-k8s-otel-collector/README.md index 08c697d5d..170bc8d5d 100644 --- a/charts/nr-k8s-otel-collector/README.md +++ b/charts/nr-k8s-otel-collector/README.md @@ -109,7 +109,7 @@ daemonset: | kube-state-metrics.prometheusScrape | bool | `false` | Disable prometheus from auto-discovering KSM and potentially scraping duplicated data | | labels | object | `{}` | Additional labels for chart objects | | licenseKey | string | `""` | This set this license key to use. Can be configured also with `global.licenseKey` | -| lowDataMode | bool | `false` | Send only the [metrics required](https://github.com/newrelic/helm-charts/tree/master/charts/nr-k8s-otel-collector/docs/metrics-lowDataMode.md) to light up the NR kubernetes UI, this agent defaults to setting lowDataMode true, but if this setting is unset, lowDataMode will be set to false | +| lowDataMode | bool | `true` | Send only the [metrics required](https://github.com/newrelic/helm-charts/tree/master/charts/nr-k8s-otel-collector/docs/metrics-lowDataMode.md) to light up the NR kubernetes UI, this agent defaults to setting lowDataMode true, but if this setting is unset, lowDataMode will be set to false | | nodeSelector | object | `{}` | Sets all pods' node selector. Can be configured also with `global.nodeSelector` | | nrStaging | bool | `false` | Send the metrics to the staging backend. Requires a valid staging license key. Can be configured also with `global.nrStaging` | | podLabels | object | `{}` | Additional labels for chart pods | From 30ba798eb34d9179384934c9a455e15cc382548d Mon Sep 17 00:00:00 2001 From: Juan Manuel Perez Date: Tue, 3 Sep 2024 16:33:26 +0200 Subject: [PATCH 3/3] fix typos --- charts/nr-k8s-otel-collector/templates/_low_data_mode.tpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charts/nr-k8s-otel-collector/templates/_low_data_mode.tpl b/charts/nr-k8s-otel-collector/templates/_low_data_mode.tpl index 8ee0ccee5..0de459521 100644 --- a/charts/nr-k8s-otel-collector/templates/_low_data_mode.tpl +++ b/charts/nr-k8s-otel-collector/templates/_low_data_mode.tpl @@ -1,5 +1,5 @@ {{- /* -This helper detect if the user set a value for the LowDataMode toogle and use it or defaults to `true`. +This helper detect if the user set a value for the LowDataMode toggle and use it or defaults to `true`. */ -}} {{- define "nrKubernetesOtel.lowDataMode" -}} {{- $userSetAValue := false -}}