Skip to content

Commit

Permalink
fix(promtail): correctly parse list of drop stage sources from YAML (#…
Browse files Browse the repository at this point in the history
…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>
  • Loading branch information
rgroothuijsen and MichelHollands committed Oct 12, 2023
1 parent b2bfe53 commit f51ee84
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions clients/pkg/logentry/stages/drop.go
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions clients/pkg/logentry/stages/drop_test.go
Expand Up @@ -23,15 +23,15 @@ pipeline_stages:
app:
msg:
- drop:
sources:
source:
- src
expression: ".*test.*"
older_than: 24h
longer_than: 8kb
- drop:
expression: ".*app1.*"
- drop:
sources:
source:
- app
expression: loki
- drop:
Expand Down

0 comments on commit f51ee84

Please sign in to comment.