From 09daa17a4a0fe847230508d7fdf68e74eeba74e9 Mon Sep 17 00:00:00 2001 From: Robert Jacob Date: Thu, 10 Oct 2024 14:05:40 +0200 Subject: [PATCH] Small refactor of default config --- operator/internal/manifests/config_otlp.go | 20 ++++++++++--------- .../internal/manifests/config_otlp_test.go | 9 +++++++++ 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/operator/internal/manifests/config_otlp.go b/operator/internal/manifests/config_otlp.go index 8d2a092f85ca6..563a1678fd7aa 100644 --- a/operator/internal/manifests/config_otlp.go +++ b/operator/internal/manifests/config_otlp.go @@ -5,14 +5,8 @@ import ( "github.com/grafana/loki/operator/internal/manifests/internal/config" ) -func defaultOTLPAttributeConfig(ts *lokiv1.TenantsSpec) config.OTLPAttributeConfig { - if ts == nil || ts.Mode != lokiv1.OpenshiftLogging { - return config.OTLPAttributeConfig{} - } - - // TODO decide which of these can be disabled by using "disableRecommendedAttributes" - // TODO decide whether we want to split the default configuration by tenant - result := config.OTLPAttributeConfig{ +func defaultOpenShiftLoggingAttributes() config.OTLPAttributeConfig { + return config.OTLPAttributeConfig{ DefaultIndexLabels: []string{ "openshift.cluster.uid", "openshift.log.source", @@ -90,8 +84,16 @@ func defaultOTLPAttributeConfig(ts *lokiv1.TenantsSpec) config.OTLPAttributeConf }, }, } +} + +func defaultOTLPAttributeConfig(ts *lokiv1.TenantsSpec) config.OTLPAttributeConfig { + if ts == nil || ts.Mode != lokiv1.OpenshiftLogging { + return config.OTLPAttributeConfig{} + } - return result + // TODO decide which of these can be disabled by using "disableRecommendedAttributes" + // TODO decide whether we want to split the default configuration by tenant + return defaultOpenShiftLoggingAttributes() } func collectAttributes(attrs []lokiv1.OTLPAttributeReference) (regularExpressions, names []string) { diff --git a/operator/internal/manifests/config_otlp_test.go b/operator/internal/manifests/config_otlp_test.go index 9a6d99d3a50d3..c658ecd7ae7dc 100644 --- a/operator/internal/manifests/config_otlp_test.go +++ b/operator/internal/manifests/config_otlp_test.go @@ -186,6 +186,15 @@ func TestOtlpAttributeConfig(t *testing.T) { }, }, }, + { + desc: "openshift-logging defaults", + spec: lokiv1.LokiStackSpec{ + Tenants: &lokiv1.TenantsSpec{ + Mode: lokiv1.OpenshiftLogging, + }, + }, + wantConfig: defaultOpenShiftLoggingAttributes(), + }, } for _, tc := range tt {