Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(metrics): use sumologic.metrics.excludeNamespaceRegex instead of sumologic.logs.container.excludeNamespaceRegex #3428

Merged
merged 2 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .changelog/3428.fixed.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fix(metrics): use `sumologic.metrics.excludeNamespaceRegex` instead of `sumologic.logs.container.excludeNamespaceRegex`
1 change: 1 addition & 0 deletions deploy/helm/sumologic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ The following table lists the configurable parameters of the Sumo Logic chart an
| `sumologic.logs.additionalFields` | Additional Fields to be created in Sumo Logic. [Sumo Logic help](https://help.sumologic.com/docs/manage/fields/#manage-fields) | `[]` |
| `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/). | `otlp` |
| `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.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) | `false` |
| `sumologic.metrics.remoteWriteProxy.config.clientBodyBufferSize` | See the [nginx documentation](http://nginx.org/en/docs/http/ngx_http_core_module.html#client_body_buffer_size). Increase if you've also increased samples per send in Prometheus remote write. | `64k` |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,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.
Expand Down
19 changes: 19 additions & 0 deletions deploy/helm/sumologic/templates/_helpers/_metrics.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -309,3 +309,22 @@ Example Usage:
{{- define "metrics.collector.autoscaling.enabled" -}}
{{- template "is.autoscaling.enabled" (dict "autoscalingEnabled" .Values.sumologic.metrics.collector.otelcol.autoscaling.enabled "Values" .Values) -}}
{{- 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 -}}
andrzej-stencel marked this conversation as resolved.
Show resolved Hide resolved
{{- 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 -}}
4 changes: 4 additions & 0 deletions deploy/helm/sumologic/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,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.
Expand Down
77 changes: 77 additions & 0 deletions tests/helm/logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,3 +488,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)
}
74 changes: 74 additions & 0 deletions tests/helm/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,5 +332,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)
}