Skip to content

Commit

Permalink
Simplify OTLPAttributeAction helper
Browse files Browse the repository at this point in the history
  • Loading branch information
periklis committed Sep 6, 2024
1 parent 2825a14 commit fe70fbe
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
16 changes: 11 additions & 5 deletions operator/apis/loki/v1/lokistack_types.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package v1

import (
"regexp"
"strings"

corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -1465,8 +1464,15 @@ func (t BlockedQueryTypes) String() string {
return strings.Join(res, ",")
}

func (a OTLPAttributeAction) CfgString() string {
re := regexp.MustCompile("([a-z0-9])([A-Z])")
str := re.ReplaceAllString(string(a), "${1}_${2}")
return strings.ToLower(str)
func (a OTLPAttributeAction) Value() string {
switch a {
case OTLPAttributeActionIndexLabel:
return "index_label"
case OTLPAttributeActionStructuredMetadata:
return "structured_metadata"
case OTLPAttributeActionDrop:
return "drop"
default:
return string(a)
}
}
6 changes: 3 additions & 3 deletions operator/internal/manifests/internal/config/loki-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ limits_config:
{{- with .Attributes}}
attributes_config:
{{- range . }}
- action: {{ .Action.CfgString }}
- action: {{ .Action.Value }}
{{- with .Regex }}
regex: {{ . }}
{{- end }}
Expand All @@ -257,7 +257,7 @@ limits_config:
{{- with .ScopeAttributes }}
scope_attributes:
{{- range . }}
- action: {{ .Action.CfgString }}
- action: {{ .Action.Value }}
{{- with .Regex }}
regex: {{ . }}
{{- end }}
Expand All @@ -272,7 +272,7 @@ limits_config:
{{- with .LogAttributes }}
log_attributes:
{{- range . }}
- action: {{ .Action.CfgString }}
- action: {{ .Action.Value }}
{{- with .Regex }}
regex: {{ . }}
{{- end }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ overrides:
{{- with .Attributes}}
attributes_config:
{{- range . }}
- action: {{ .Action.CfgString }}
- action: {{ .Action.Value }}
{{- with .Regex }}
regex: {{ . }}
{{- end }}
Expand All @@ -97,7 +97,7 @@ overrides:
{{- with $l.ScopeAttributes }}
scope_attributes:
{{- range . }}
- action: {{ .Action.CfgString }}
- action: {{ .Action.Value }}
{{- with .Regex }}
regex: {{ . }}
{{- end }}
Expand All @@ -112,7 +112,7 @@ overrides:
{{- with $l.LogAttributes }}
log_attributes:
{{- range . }}
- action: {{ .Action.CfgString }}
- action: {{ .Action.Value }}
{{- with .Regex }}
regex: {{ . }}
{{- end }}
Expand Down

0 comments on commit fe70fbe

Please sign in to comment.