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(operator): Fix encoding of blocked query pattern in configuration #12097

Merged
merged 15 commits into from Mar 5, 2024
1 change: 1 addition & 0 deletions operator/CHANGELOG.md
@@ -1,5 +1,6 @@
## Main

- [12097](https://github.com/grafana/loki/pull/12097) **btaani**: Fix blocking query yaml block
- [12007](https://github.com/grafana/loki/pull/12007) **xperimental**: Extend Azure secret validation
- [12008](https://github.com/grafana/loki/pull/12008) **xperimental**: Support using multiple buckets with AWS STS
- [11964](https://github.com/grafana/loki/pull/11964) **xperimental**: Provide Azure region for managed credentials using environment variable
Expand Down
12 changes: 1 addition & 11 deletions operator/internal/manifests/internal/config/build.go
Expand Up @@ -4,8 +4,6 @@ import (
"bytes"
"embed"
"io"
"reflect"
"strings"
"text/template"

"github.com/ViaQ/logerr/v2/kverrors"
Expand All @@ -29,9 +27,7 @@ var (

lokiConfigYAMLTmpl = template.Must(template.ParseFS(lokiConfigYAMLTmplFile, "loki-config.yaml"))

lokiRuntimeConfigYAMLTmpl = template.Must(template.New("loki-runtime-config.yaml").Funcs(template.FuncMap{
"yamlBlock": yamlBlock,
}).ParseFS(lokiRuntimeConfigYAMLTmplFile, "loki-runtime-config.yaml"))
lokiRuntimeConfigYAMLTmpl = template.Must(template.New("loki-runtime-config.yaml").ParseFS(lokiRuntimeConfigYAMLTmplFile, "loki-runtime-config.yaml"))
)

// Build builds a loki stack configuration files
Expand All @@ -58,9 +54,3 @@ func Build(opts Options) ([]byte, []byte, error) {
}
return cfg, rcfg, nil
}

func yamlBlock(indent string, in reflect.Value) string {
inStr := in.String()
lines := strings.Split(strings.TrimRight(inStr, "\n"), "\n")
return strings.Join(lines, "\n"+indent)
}
13 changes: 9 additions & 4 deletions operator/internal/manifests/internal/config/build_test.go
Expand Up @@ -445,12 +445,11 @@ overrides:
blocked_queries:
- hash: 12345
types: metric,limited
- pattern: |
.*prod.*
- pattern: .*prod.*
regex: true
- types: metric
- pattern: |
sum(rate({env="prod"}[1m]))
- pattern: sum(rate({env="prod"}[1m]))
- pattern: '{kubernetes_namespace_name="my-app"}'
`
opts := Options{
Stack: lokiv1.LokiStackSpec{
Expand Down Expand Up @@ -505,6 +504,9 @@ overrides:
{
Pattern: `sum(rate({env="prod"}[1m]))`,
},
{
Pattern: `{kubernetes_namespace_name="my-app"}`,
},
},
},
},
Expand Down Expand Up @@ -538,6 +540,9 @@ overrides:
{
Pattern: `sum(rate({env="prod"}[1m]))`,
},
{
Pattern: `{kubernetes_namespace_name="my-app"}`,
},
},
},
},
Expand Down
Expand Up @@ -58,8 +58,7 @@ overrides:
blocked_queries:
{{- range $blockedQuery := . }}
- {{ with $blockedQuery.Pattern -}}
pattern: |
{{ . | yamlBlock " " }}
pattern: {{ . | printf "%q" }}
btaani marked this conversation as resolved.
Show resolved Hide resolved
{{ end -}}
{{- with $blockedQuery.Regex }}
regex: {{ . }}
Expand Down