Skip to content

model: fix EscapeLabelName to not preserve colon in label names#907

Open
ogulcanaydogan wants to merge 1 commit into
prometheus:mainfrom
ogulcanaydogan:fix/escape-colon-in-label-names
Open

model: fix EscapeLabelName to not preserve colon in label names#907
ogulcanaydogan wants to merge 1 commit into
prometheus:mainfrom
ogulcanaydogan:fix/escape-colon-in-label-names

Conversation

@ogulcanaydogan
Copy link
Copy Markdown

Colons are reserved for metric names only per the Prometheus data model. EscapeMetricFamily and metricNeedsEscaping were using IsValidLegacyMetricName and EscapeName for label name contexts, causing colons to be preserved when they should be escaped.

Fixes prometheus/prometheus#18380

Changes

  • Add isValidLegacyLabelRune: same as isValidLegacyRune but excludes :
  • Add IsValidLegacyLabelName: uses the label-specific rune validator
  • Add EscapeLabelName: mirrors EscapeName but applies label name rules
  • Update EscapeMetricFamily to use IsValidLegacyLabelName and EscapeLabelName for label names
  • Update metricNeedsEscaping to use IsValidLegacyLabelName for label names

Behavior

Input Scheme Before After
app:instance-id underscores app:instance_id app_instance_id
http.status:sum underscores http_status:sum http_status_sum
app:instance-id values U__app:instance_2d_id U__app_3a_instance_2d_id
requests:total (metric name) underscores requests:total requests:total (unchanged)

Metric names with colons continue to work correctly. Only label name escaping is affected.

Builds on the approach discussed in #889.

Colons are reserved for metric names only per the Prometheus data model.
EscapeMetricFamily and metricNeedsEscaping were using IsValidLegacyMetricName
and EscapeName for label name contexts, causing colons to be preserved when
they should be escaped.

Add isValidLegacyLabelRune, IsValidLegacyLabelName, and EscapeLabelName
that exclude colons. Update EscapeMetricFamily and metricNeedsEscaping to
use the label-specific functions for label name contexts.

Builds on the approach discussed in prometheus#889.

Fixes prometheus/prometheus#18380

Signed-off-by: Ogulcan Aydogan <ogulcanaydogan@hotmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

EscapeMetricFamily incorrectly preserves : in label names

1 participant