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](d10549e3ec)

---------

Co-authored-by: Michel Hollands <42814411+MichelHollands@users.noreply.github.com>
pull/10647/head^2
Rens Groothuijsen 2 years ago committed by GitHub
parent b2bfe53e35
commit f51ee849b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 6
      clients/pkg/logentry/stages/drop.go
  3. 4
      clients/pkg/logentry/stages/drop_test.go

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

@ -106,6 +106,12 @@ func validateDropConfig(cfg *DropConfig) error {
// unifySourceField unify Source into a slice of strings
func unifySourceField(s interface{}) ([]string, error) {
switch s := s.(type) {
case []interface{}:
r := make([]string, len(s))
for i := range s {
r[i] = s[i].(string)
}
return r, nil
case []string:
return s, nil
case string:

@ -23,7 +23,7 @@ pipeline_stages:
app:
msg:
- drop:
sources:
source:
- src
expression: ".*test.*"
older_than: 24h
@ -31,7 +31,7 @@ pipeline_stages:
- drop:
expression: ".*app1.*"
- drop:
sources:
source:
- app
expression: loki
- drop:

Loading…
Cancel
Save