Skip to content

Commit

Permalink
Provide defaults pre-sorted
Browse files Browse the repository at this point in the history
  • Loading branch information
xperimental committed Oct 14, 2024
1 parent 03a2236 commit 80c45e9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
30 changes: 17 additions & 13 deletions operator/internal/manifests/config_otlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,14 @@ func defaultOpenShiftLoggingAttributes(disableRecommended bool) config.OTLPAttri
"k8s.pod.uid",
"kubernetes.pod_name",
)
slices.Sort(result.DefaultIndexLabels)

result.Global = &config.OTLPTenantAttributeConfig{
ResourceAttributes: []config.OTLPAttribute{
{
Action: config.OTLPAttributeActionStreamLabel,
Regex: "openshift\\.labels\\..+",
},
{
Action: config.OTLPAttributeActionMetadata,
Regex: "k8s\\.pod\\.labels\\..+",
},
{
Action: config.OTLPAttributeActionMetadata,
Names: []string{
Expand All @@ -51,30 +48,34 @@ func defaultOpenShiftLoggingAttributes(disableRecommended bool) config.OTLPAttri
"k8s.job.name",
"k8s.replicaset.name",
"k8s.statefulset.name",
"process.command_line",
"process.executable.name",
"process.executable.path",
"process.command_line",
"process.pid",
"service.name",
},
},
{
Action: config.OTLPAttributeActionMetadata,
Regex: "k8s\\.pod\\.labels\\..+",
},
},
LogAttributes: []config.OTLPAttribute{
{
Action: config.OTLPAttributeActionMetadata,
Names: []string{
"log.iostream",
"k8s.event.level",
"k8s.event.stage",
"k8s.event.user_agent",
"k8s.event.request.uri",
"k8s.event.response.code",
"k8s.event.object_ref.resource",
"k8s.event.object_ref.name",
"k8s.event.object_ref.api.group",
"k8s.event.object_ref.api.version",
"k8s.user.username",
"k8s.event.object_ref.name",
"k8s.event.object_ref.resource",
"k8s.event.request.uri",
"k8s.event.response.code",
"k8s.event.stage",
"k8s.event.user_agent",
"k8s.user.groups",
"k8s.user.username",
"log.iostream",
},
},
{
Expand Down Expand Up @@ -204,6 +205,9 @@ func sortAndDeduplicateOTLPAttributes(attrs []config.OTLPAttribute) []config.OTL
continue
}

slices.Sort(a.Names)
attrs[i] = a

next := attrs[i+1]
if next.Regex != "" {
continue
Expand Down
4 changes: 2 additions & 2 deletions operator/internal/manifests/config_otlp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ func TestOtlpAttributeConfig(t *testing.T) {
Mode: lokiv1.OpenshiftLogging,
},
},
wantConfig: sortAndDeduplicateOTLPConfig(defaultOpenShiftLoggingAttributes(false)),
wantConfig: defaultOpenShiftLoggingAttributes(false),
},
{
desc: "openshift-logging defaults without recommended",
Expand All @@ -411,7 +411,7 @@ func TestOtlpAttributeConfig(t *testing.T) {
},
},
},
wantConfig: sortAndDeduplicateOTLPConfig(defaultOpenShiftLoggingAttributes(true)),
wantConfig: defaultOpenShiftLoggingAttributes(true),
},
{
desc: "openshift-logging defaults with additional custom attributes",
Expand Down

0 comments on commit 80c45e9

Please sign in to comment.