Skip to content

Commit

Permalink
fix(logs): use longer fingerprint only on K8s <1.24
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikołaj Świątek committed May 29, 2023
1 parent a6f2eb3 commit 335ba4b
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions .changelog/3070.fixed.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fix(logs): use longer fingerprint only on K8s <1.24
3 changes: 3 additions & 0 deletions deploy/helm/sumologic/conf/logs/collector/otelcol/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,12 @@ receivers:
{{- if .Values.sumologic.logs.container.enabled }}
## ref: https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/v0.76.1/receiver/filelogreceiver
filelog/containers:
{{ if lt (int .Capabilities.KubeVersion.Minor) 24 }}
## sets fingerprint_size to 17kb in order to match the longest possible docker line (which by default is 16kb)
## we want to include timestamp, which is at the end of the line
## Not necessary in 1.24 and later, as docker-shim is not present anymore
fingerprint_size: 17408
{{ end }}
include:
- /var/log/pods/*/*/*.log
include_file_name: false
Expand Down
1 change: 1 addition & 0 deletions tests/helm/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const (
chartName = "sumologic"
releaseName = "collection-test"
defaultNamespace = "sumologic"
defaultK8sVersion = "1.22.0"
testDataDirectory = "./testdata"
otelConfigFileName = "config.yaml"
otelImageFIPSSuffix = "-fips"
Expand Down
2 changes: 2 additions & 0 deletions tests/helm/goldenfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ func runGoldenFileTest(t *testing.T, valuesFileName string, outputFileName strin
true,
"--namespace",
defaultNamespace,
"--kube-version",
defaultK8sVersion,
)

// render the actual and expected yaml strings and fix them up
Expand Down
38 changes: 38 additions & 0 deletions tests/helm/logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"
"testing"

"github.com/gruntwork-io/terratest/modules/helm"
"github.com/gruntwork-io/terratest/modules/logger"
"github.com/stretchr/testify/require"
"gopkg.in/yaml.v3"
)
Expand Down Expand Up @@ -363,6 +365,42 @@ sumologic:
}
}

func TestCollectorOtelConfigNoDockerShim(t *testing.T) {
t.Parallel()
templatePath := "templates/logs/collector/otelcol/configmap.yaml"
renderedYamlString := RenderTemplate(
t,
&helm.Options{
ValuesFiles: []string{},
SetStrValues: map[string]string{
"sumologic.accessId": "accessId",
"sumologic.accessKey": "accessKey",
},
Logger: logger.Discard, // the log output is noisy and doesn't help much
},
chartDirectory,
releaseName,
[]string{templatePath},
true,
"--namespace",
defaultNamespace,
"--kube-version",
"1.24.3",
)
otelConfigYaml := GetOtelConfigFromTemplate(t, renderedYamlString)

var otelConfig struct {
Receivers struct {
Filelog struct {
FingerprintSize string `yaml:"fingerprint_size"`
} `yaml:"filelog/containers"`
}
}
err := yaml.Unmarshal([]byte(otelConfigYaml), &otelConfig)
require.NoError(t, err)
require.Empty(t, otelConfig.Receivers.Filelog.FingerprintSize)
}

func TestCollectorOtelConfigSystemdUnits(t *testing.T) {
t.Parallel()
templatePath := "templates/logs/collector/otelcol/configmap.yaml"
Expand Down

0 comments on commit 335ba4b

Please sign in to comment.