diff --git a/.changelog/3428.fixed.txt b/.changelog/3428.fixed.txt new file mode 100644 index 0000000000..4428fc1d24 --- /dev/null +++ b/.changelog/3428.fixed.txt @@ -0,0 +1 @@ +fix(metrics): use `sumologic.metrics.excludeNamespaceRegex` instead of `sumologic.logs.container.excludeNamespaceRegex` \ No newline at end of file diff --git a/deploy/helm/sumologic/README.md b/deploy/helm/sumologic/README.md index cbc703af21..7e7baed99d 100644 --- a/deploy/helm/sumologic/README.md +++ b/deploy/helm/sumologic/README.md @@ -99,6 +99,7 @@ The following table lists the configurable parameters of the Sumo Logic chart an | `sumologic.logs.metadata.provider` | Defines logs metadata enrichment provider - `otelcol` or `fluentd`. `otelcol` is the default and is recommended. `fluentd` is deprecated. | `otelcol` | | `sumologic.logs.sourceType` | The type of the Sumo Logic source being used for logs ingestion. Can be `http` for [HTTP Source](https://help.sumologic.com/docs/send-data/hosted-collectors/http-source/logs-metrics/) or `otlp` for [OTLP/HTTP Source](https://help.sumologic.com/docs/send-data/hosted-collectors/http-source/otlp/). | `http` | | `sumologic.metrics.enabled` | Set the enabled flag to false for disabling metrics ingestion altogether. | `true` | +| `sumologic.metrics.excludeNamespaceRegex` | A regular expression for Kubernetes namespace names. Metrics matching this namespace will not be sent to Sumo. | `""` | | `sumologic.metrics.metadata.provider` | Defines metrics metadata enrichment provider - `otelcol` or `fluentd`. `otelcol` is the default and is recommended. `fluentd` is deprecated. | `otelcol` | | `sumologic.metrics.otelcol.extraProcessors` | Extra processors configuration for metrics pipeline. See [/docs/collecting-application-metrics.md#metrics-modifications](/docs/collecting-application-metrics.md#metrics-modifications) for more information. | `[]` | | `sumologic.metrics.remoteWriteProxy.enabled` | Enable a load balancing proxy for Prometheus remote writes. [See docs for more information.](/docs/prometheus.md#using-a-load-balancing-proxy-for-prometheus-remote-write) | `true` | diff --git a/deploy/helm/sumologic/conf/metrics/otelcol/processors.yaml b/deploy/helm/sumologic/conf/metrics/otelcol/processors.yaml index cf5ae4ea5e..1238551461 100644 --- a/deploy/helm/sumologic/conf/metrics/otelcol/processors.yaml +++ b/deploy/helm/sumologic/conf/metrics/otelcol/processors.yaml @@ -171,7 +171,7 @@ routing: source: collector: {{ .Values.sumologic.collectorName | default .Values.sumologic.clusterName | quote }} exclude: - k8s.namespace.name: {{ include "logs.excludeNamespaces" . }} + k8s.namespace.name: {{ include "metrics.excludeNamespaces" . }} ## The Sumo Logic Schema processor modifies the metadata on logs, metrics and traces sent to Sumo Logic ## so that the Sumo Logic apps can make full use of the ingested data. diff --git a/deploy/helm/sumologic/templates/_helpers/_metrics.tpl b/deploy/helm/sumologic/templates/_helpers/_metrics.tpl index cf005e3e46..1aa704d92b 100644 --- a/deploy/helm/sumologic/templates/_helpers/_metrics.tpl +++ b/deploy/helm/sumologic/templates/_helpers/_metrics.tpl @@ -403,3 +403,22 @@ Example: {{- end -}} + +{{/* +Returns list of namespaces to exclude + +Example: + +{{ include "metrics.excludeNamespaces" . }} +*/}} +{{- define "metrics.excludeNamespaces" -}} +{{- $excludeNamespaceRegex := .Values.sumologic.metrics.excludeNamespaceRegex | quote -}} +{{- if eq .Values.sumologic.collectionMonitoring false -}} + {{- if .Values.sumologic.metrics.excludeNamespaceRegex -}} + {{- $excludeNamespaceRegex = printf "%s|%s" ( include "sumologic.namespace" . ) .Values.sumologic.metrics.excludeNamespaceRegex | quote -}} + {{- else -}} + {{- $excludeNamespaceRegex = printf "%s" ( include "sumologic.namespace" . ) | quote -}} + {{- end -}} +{{- end -}} +{{ print $excludeNamespaceRegex }} +{{- end -}} diff --git a/deploy/helm/sumologic/values.yaml b/deploy/helm/sumologic/values.yaml index 3077d08f63..718233ef80 100644 --- a/deploy/helm/sumologic/values.yaml +++ b/deploy/helm/sumologic/values.yaml @@ -578,6 +578,10 @@ sumologic: ## - kubelet_runtime_operations_duration_seconds dropHistogramBuckets: true + ## A regular expression for namespaces. + ## Metrics that match these namespaces will be excluded from Sumo. + excludeNamespaceRegex: "" + otelcol: ## Includes additional processors into pipelines. ## It can be used for filtering metrics, renaming, changing metadata and so on. diff --git a/tests/helm/logs_test.go b/tests/helm/logs_test.go index 6d9760190c..aa9d8dc660 100644 --- a/tests/helm/logs_test.go +++ b/tests/helm/logs_test.go @@ -563,3 +563,80 @@ sumologic: } require.True(t, keepTimeOperatorFound) } + +func TestLogsCollectionMonitoring(t *testing.T) { + t.Parallel() + templatePath := "templates/logs/otelcol/configmap.yaml" + valuesYaml := ` +sumologic: + collectionMonitoring: false +` + otelConfigYaml := GetOtelConfigYaml(t, valuesYaml, templatePath) + + var otelConfig struct { + Processors struct { + SourceContainers struct { + Exclude struct { + Namespace string + } + } `yaml:"source/containers"` + } + } + err := yaml.Unmarshal([]byte(otelConfigYaml), &otelConfig) + require.NoError(t, err) + + require.Equal(t, "sumologic", otelConfig.Processors.SourceContainers.Exclude.Namespace) +} + +func TestLogsExcludeNamespaceRegex(t *testing.T) { + t.Parallel() + templatePath := "templates/logs/otelcol/configmap.yaml" + valuesYaml := ` +sumologic: + logs: + container: + excludeNamespaceRegex: my_logs_namespace +` + otelConfigYaml := GetOtelConfigYaml(t, valuesYaml, templatePath) + + var otelConfig struct { + Processors struct { + SourceContainers struct { + Exclude struct { + Namespace string + } + } `yaml:"source/containers"` + } + } + err := yaml.Unmarshal([]byte(otelConfigYaml), &otelConfig) + require.NoError(t, err) + + require.Equal(t, "my_logs_namespace", otelConfig.Processors.SourceContainers.Exclude.Namespace) +} + +func TestLogsExcludeNamespaceRegexWithCollectionMonitoring(t *testing.T) { + t.Parallel() + templatePath := "templates/logs/otelcol/configmap.yaml" + valuesYaml := ` +sumologic: + collectionMonitoring: false + logs: + container: + excludeNamespaceRegex: my_logs_namespace +` + otelConfigYaml := GetOtelConfigYaml(t, valuesYaml, templatePath) + + var otelConfig struct { + Processors struct { + SourceContainers struct { + Exclude struct { + Namespace string + } + } `yaml:"source/containers"` + } + } + err := yaml.Unmarshal([]byte(otelConfigYaml), &otelConfig) + require.NoError(t, err) + + require.Equal(t, "sumologic|my_logs_namespace", otelConfig.Processors.SourceContainers.Exclude.Namespace) +} diff --git a/tests/helm/metrics_test.go b/tests/helm/metrics_test.go index 23508e4f14..4f8486b915 100644 --- a/tests/helm/metrics_test.go +++ b/tests/helm/metrics_test.go @@ -293,5 +293,79 @@ sumologic: assert.Equal(t, tt.ExpectedNames, names) }) } +} + +func TestMetricsCollectionMonitoring(t *testing.T) { + t.Parallel() + templatePath := "templates/metrics/otelcol/configmap.yaml" + valuesYaml := ` +sumologic: + collectionMonitoring: false +` + otelConfigYaml := GetOtelConfigYaml(t, valuesYaml, templatePath) + + var otelConfig struct { + Processors struct { + Source struct { + Exclude struct { + K8sNamespaceName string `yaml:"k8s.namespace.name"` + } + } + } + } + err := yaml.Unmarshal([]byte(otelConfigYaml), &otelConfig) + require.NoError(t, err) + + require.Equal(t, "sumologic", otelConfig.Processors.Source.Exclude.K8sNamespaceName) +} + +func TestMetricsExcludeNamespaceRegex(t *testing.T) { + t.Parallel() + templatePath := "templates/metrics/otelcol/configmap.yaml" + valuesYaml := ` +sumologic: + metrics: + excludeNamespaceRegex: my_metrics_namespace +` + otelConfigYaml := GetOtelConfigYaml(t, valuesYaml, templatePath) + + var otelConfig struct { + Processors struct { + Source struct { + Exclude struct { + K8sNamespaceName string `yaml:"k8s.namespace.name"` + } + } + } + } + err := yaml.Unmarshal([]byte(otelConfigYaml), &otelConfig) + require.NoError(t, err) + + require.Equal(t, "my_metrics_namespace", otelConfig.Processors.Source.Exclude.K8sNamespaceName) +} + +func TestMetricsExcludeNamespaceRegexWithCollectionMonitoring(t *testing.T) { + t.Parallel() + templatePath := "templates/metrics/otelcol/configmap.yaml" + valuesYaml := ` +sumologic: + collectionMonitoring: false + metrics: + excludeNamespaceRegex: my_metrics_namespace +` + otelConfigYaml := GetOtelConfigYaml(t, valuesYaml, templatePath) + + var otelConfig struct { + Processors struct { + Source struct { + Exclude struct { + K8sNamespaceName string `yaml:"k8s.namespace.name"` + } + } + } + } + err := yaml.Unmarshal([]byte(otelConfigYaml), &otelConfig) + require.NoError(t, err) + require.Equal(t, "sumologic|my_metrics_namespace", otelConfig.Processors.Source.Exclude.K8sNamespaceName) }