Skip to content

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

@aglees

Description

@aglees

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:

[
    {
        "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:

	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, specifically the c.SourceLabels != nil conditional, that evaluates to true because SourceLabels are being set:

	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)
		}
	}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions