grafana / grafana/lambda-promtail

invalid relabel config: invalid relabel config: labelkeep action requires only 'regex', and no other fields

Open
#8 4 comments 1 reaction 0 assignees View on GitHub
bug
Dominant language
Go
Stars
11
Forks
42
PR merge metrics
No merged PRs in 30d

Description

https://github.com/grafana/loki/blob/42eed6ded5e96edde6831f3fc3a010efd9904e85/tools/lambda-promtail/lambda-promtail/relabel.go#L75-L88

I think there's an issue with how Lambda Promtail is setting up Relabelling configurations before they're validated, and it's resulting in the following errors:

```
invalid relabel config: invalid relabel config: labelkeep action requires only 'regex', and no other fields
```

A basic relabelling configuration that produces an error is:

```json
[
{
"regex": "(.*)",
"action": "labelkeep"
}
]
```

The issues appears to stem from how `SourceLabels` are being setup for `actions` that cannot have `source_labels` set, such as `labelkeep` & `labeldrop`:

```go
sourceLabels := make(model.LabelNames, 0, len(rc.SourceLabels))
for _, l := range rc.SourceLabels {
sourceLabels = append(sourceLabels, model.LabelName(l))
}

cfg := &relabel.Config{
SourceLabels: sourceLabels,
Separator: separator,
Regex: regex,
Modulus: rc.Modulus,
TargetLabel: rc.TargetLabel,
Replacement: replacement,
Action: action,
}
```

The issue arises when this go is hit in the [Validate function](https://github.com/prometheus/prometheus/blob/41744d6331f212205e7aca52fa48b5f8d7861f02/model/relabel/relabel.go), specifically the `c.SourceLabels != nil` conditional, that evaluates to `true` because `SourceLabels` are being set:

```go
if c.Action == LabelDrop || c.Action == LabelKeep {
if c.SourceLabels != nil ||
c.TargetLabel != DefaultRelabelConfig.TargetLabel ||
c.Modulus != DefaultRelabelConfig.Modulus ||
c.Separator != DefaultRelabelConfig.Separator ||
c.Replacement != DefaultRelabelConfig.Replacement {
return fmt.Errorf("%s action requires only 'regex', and no other fields", c.Action)
}
}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.