Skip to content

Commit f51ee84

Browse files
fix(promtail): correctly parse list of drop stage sources from YAML (#10848)
**What this PR does / why we need it**: This PR fixes YAML parsing of the `source` field in the drop stage when said field is a list of strings. Because this list is not being recognized in the code as a list of strings, but rather as a list of generic `interface{}` elements, it fails a type check and throws an error. In order to fix this, an `interface{}` list is manually converted to a `string` list. The problem was already reproducible with existing tests, but the test YAML mistakenly referred to the field as `sources` rather than `source`. **Which issue(s) this PR fixes**: Fixes #10095 **Special notes for your reviewer**: **Checklist** - [x] Reviewed the [`CONTRIBUTING.md`](https://github.com/grafana/loki/blob/main/CONTRIBUTING.md) guide (**required**) - [ ] Documentation added - [x] Tests updated - [ ] `CHANGELOG.md` updated - [ ] If the change is worth mentioning in the release notes, add `add-to-release-notes` label - [ ] Changes that require user attention or interaction to upgrade are documented in `docs/sources/setup/upgrade/_index.md` - [ ] For Helm chart changes bump the Helm chart version in `production/helm/loki/Chart.yaml` and update `production/helm/loki/CHANGELOG.md` and `production/helm/loki/README.md`. [Example PR](d10549e) --------- Co-authored-by: Michel Hollands <42814411+MichelHollands@users.noreply.github.com>
1 parent b2bfe53 commit f51ee84

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

‎CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151

5252
* [10631](https://github.com/grafana/loki/pull/10631) **thampiotr**: Fix race condition in cleaning up metrics when stopping to tail files.
5353
* [10798](https://github.com/grafana/loki/pull/10798) **hainenber**: Fix agent panicking after reloaded due to duplicate metric collector registration.
54+
* [10848](https://github.com/grafana/loki/pull/10848) **rgroothuijsen**: Correctly parse list of drop stage sources from YAML.
5455

5556
#### LogCLI
5657

‎clients/pkg/logentry/stages/drop.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ func validateDropConfig(cfg *DropConfig) error {
106106
// unifySourceField unify Source into a slice of strings
107107
func unifySourceField(s interface{}) ([]string, error) {
108108
switch s := s.(type) {
109+
case []interface{}:
110+
r := make([]string, len(s))
111+
for i := range s {
112+
r[i] = s[i].(string)
113+
}
114+
return r, nil
109115
case []string:
110116
return s, nil
111117
case string:

‎clients/pkg/logentry/stages/drop_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ pipeline_stages:
2323
app:
2424
msg:
2525
- drop:
26-
sources:
26+
source:
2727
- src
2828
expression: ".*test.*"
2929
older_than: 24h
3030
longer_than: 8kb
3131
- drop:
3232
expression: ".*app1.*"
3333
- drop:
34-
sources:
34+
source:
3535
- app
3636
expression: loki
3737
- drop:

0 commit comments

Comments
 (0)