Skip to content

receive: fix relabel config NameValidationScheme panic#8840

Open
Chaithanya5gif wants to merge 6 commits into
thanos-io:mainfrom
Chaithanya5gif:fix/receive-relabel-validation
Open

receive: fix relabel config NameValidationScheme panic#8840
Chaithanya5gif wants to merge 6 commits into
thanos-io:mainfrom
Chaithanya5gif:fix/receive-relabel-validation

Conversation

@Chaithanya5gif

Copy link
Copy Markdown

Description

This PR fixes a critical bug where the receive component panics when processing metrics that match rules in a provided --receive.relabel-config YAML file.

Motivation / Root Cause

In Prometheus's relabel.Config struct, the NameValidationScheme field is tagged with yaml:"-". When Thanos parses the relabeling configuration from a YAML file, this field defaults to 0 (model.UnsetValidation).

Later in the pipeline, if a metric actually matches the source_labels defined in the config, relabel.Process() attempts to process the replacement. Because the NameValidationScheme is left unset, it hits the default case in the validation switch statement inside the Prometheus relabel package, causing an immediate panic.

(Note: Prior to this PR, existing tests for this functionality passed vacuously because they did not send metrics that successfully matched the regex to trigger the replacement path).

Changes

  • cmd/thanos/receive.go: After unmarshalling the relabel configs, we now explicitly iterate through them and invoke cfg.Validate(model.LegacyValidation). This mirrors standard Prometheus behavior and safely initializes the NameValidationScheme before the config is ever passed to the router/TSDB.

Testing

  • E2E Smoke Test: Added TestReceiveWithRelabelConfigSmoke in test/e2e/receive_test.go. This test injects a relabel config containing source_labels and actively pushes a metric that matches those labels. This forces the receiver to exercise the relabel.Process() replacement path, ensuring the validation panic is caught and prevented in the future.

@Chaithanya5gif Chaithanya5gif force-pushed the fix/receive-relabel-validation branch from 58f42c3 to 2675a8e Compare June 2, 2026 10:08
When Thanos parses --receive.relabel-config from YAML, the NameValidationScheme
field defaults to UnsetValidation (0) because it has the yaml:"-" tag. If a
metric matches the relabel rules, relabel.Process() will panic on this unset scheme.

This calls Validate(model.LegacyValidation) on each config after unmarshalling
to properly initialize NameValidationScheme.

Added e2e test TestReceiveWithRelabelConfigSmoke to trigger relabeling with a metric.

Signed-off-by: chaithanya <chaithanyyal55@gmail.com>
@Chaithanya5gif Chaithanya5gif force-pushed the fix/receive-relabel-validation branch from 59d0dd2 to 405ff6a Compare June 2, 2026 10:50
@Chaithanya5gif Chaithanya5gif marked this pull request as draft June 3, 2026 17:21
@GiedriusS

Copy link
Copy Markdown
Member

@Chaithanya5gif why is this a draft?

Docker network names must be <= 16 characters.
receive-relabel-smoke (21 chars) -> recv-relabel (12 chars)

Signed-off-by: chaithanya <chaithanyyal55@gmail.com>
@Chaithanya5gif Chaithanya5gif force-pushed the fix/receive-relabel-validation branch from f60234d to 5d4a695 Compare June 9, 2026 06:33
@Chaithanya5gif Chaithanya5gif marked this pull request as ready for review June 9, 2026 06:55
@Chaithanya5gif

Copy link
Copy Markdown
Author

@Chaithanya5gif why is this a draft?

@GiedriusS I marked it as draft because the e2e test was failing due to a Docker network name constraint (the test name was too long). I've fixed that now shortened receive-relabel-smoke to recv-relabel. All checks are passing. Should I mark it ready for review?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants