Skip to content

Fix Prometheus $digit escape for OTel expandconverter#2187

Open
Paamicky wants to merge 5 commits into
mainfrom
prometheus-dollar-escape
Open

Fix Prometheus $digit escape for OTel expandconverter#2187
Paamicky wants to merge 5 commits into
mainfrom
prometheus-dollar-escape

Conversation

@Paamicky

@Paamicky Paamicky commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Description of the issue

On EKS environments, Prometheus relabel_configs that use regex capture group references (e.g., $1, $2 in replacement fields) are silently corrupted. The OTel expandconverter treats bare $digit sequences as environment variable references and replaces them with empty strings, breaking label relabeling rules.

Description of changes

Added escapeDollarDigit to the OTel Prometheus receiver translator. Before the Prometheus config file is unmarshaled, bare $digit sequences are doubled to $$digit. The expandconverter interprets $$ as a literal $, so the values are correctly preserved as $1, $2, etc. when the collector starts.

The same pattern already existed in the Container Insights translator, this change brings Prometheus to parity.

Tests

  • TestEscapeDollarDigit: 11 unit test cases covering bare $1–$9, $0, multi-digit $10, already-escaped $$1, $ followed by non-digit, mixed text, empty string
  • TestPrometheusReceiverTranslatorDollarEscape: integration test using a real prometheus config with relabel_configs containing $1 and $1:$2, asserting the translator correctly escapes them to $$1 and $$1:$$2 before the expandconverter runs

License

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Requirements

Before commiting your code, please do the following steps.

  1. Run make fmt and make fmt-sh
  2. Run make lint

Integration Tests

To run integration tests against this PR, add the ready for testing label.

@Paamicky Paamicky self-assigned this Jul 8, 2026
@Paamicky Paamicky added the ready for testing Indicates this PR is ready for integration tests to run label Jul 8, 2026
@Paamicky Paamicky marked this pull request as ready for review July 8, 2026 16:10
@Paamicky Paamicky requested a review from a team as a code owner July 8, 2026 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready for testing Indicates this PR is ready for integration tests to run

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants