Skip to content

fix: base64-encode "." and ".." in Pushgateway URL path segments - #2633

Merged
zeitlinger merged 1 commit into
prometheus:mainfrom
sarankumar1325:fix/pushgateway-dot-segments
Nov 3, 2026
Merged

zeitlinger merged 1 commit into
prometheus:mainfrom
sarankumar1325:fix/pushgateway-dot-segments

Conversation

@sarankumar1325

Copy link
Copy Markdown
Contributor

PushGateway.makeUrl() appends a job name or grouping key value of . or .. to the path unchanged (URLEncoder leaves dots alone). After that, URI.normalize() removes it as a dot segment, so the request goes to a different path:

job / grouping key URL sent
j / {instance=".."} /metrics/job/j/
j / {instance="."} /metrics/job/j/instance/
.. / {instance="x"} /metrics/instance/x

In every case the push or delete misses the intended group. This change base64-encodes these values with the @base64 suffix, the same way values containing / are already handled, and client_golang does the same. Paths for all other values stay the same.

Tests:

  • Added PushGatewayTest#testPushWithDotSegmentJobAndGroupingKey, which expects /metrics/job@base64/Li4=/l@base64/Lg==/l2@base64/Li4=. It fails on main (the mock server gets an unmatched request and returns 404) and passes with this change.
  • ./mvnw -pl prometheus-metrics-exporter-pushgateway verify -Dcoverage.skip=true passes (31 tests, Error Prone included), and the changed lines are google-java-format clean.

I used an AI assistant while preparing this change. I reviewed and tested it myself.

A job name or grouping key value of "." or ".." was appended to the URL
as is, and URI.normalize() then removed it as a dot segment. For job "j"
with grouping key {instance=".."} the request went to /metrics/job/j/,
and with {instance="."} to /metrics/job/j/instance/, so the push or
delete never reaches the intended group. Base64-encode these values, as
client_golang does.

Signed-off-by: sarankumar1325 <120080287+sarankumar1325@users.noreply.github.com>
@zeitlinger
zeitlinger disabled auto-merge November 3, 2026 09:01
@zeitlinger
zeitlinger merged commit 7e30a7e into prometheus:main Nov 3, 2026
23 checks passed
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.

2 participants