Skip to content

Base64-encode . and .. in Pushgateway job and grouping values - #343

Open
sarankumar1325 wants to merge 1 commit into
prometheus:mainfrom
sarankumar1325:fix/push-dot-segments
Open

sarankumar1325 wants to merge 1 commit into
prometheus:mainfrom
sarankumar1325:fix/push-dot-segments

Conversation

@sarankumar1325

Copy link
Copy Markdown

Prometheus::Client::Push puts a job name or grouping key value of . or .. into the URL path unchanged. Those are dot segments. The Pushgateway answers with a 307 to the cleaned path, so the push fails with HttpRedirectError. A proxy that normalises the path can also send it to a different group. The Pushgateway README asks for base64 encoding in this case, and client_golang already does this (encodeComponent checks s == "." || s == "..").

This PR base64-encodes . and .. the same way values containing / are already encoded. Other values that just contain dots (for example ... or a.b) are unchanged.

Before (against a local pushgateway v1.x):

grouping_key: { instance: '..' }  -> HttpRedirectError: status: 307, message: Temporary Redirect

After: the push succeeds and the gateway stores the group {job="j", instance=".."}.

Tests: two new cases in spec/prometheus/client/push_spec.rb (job and grouping values). Both fail without the fix. The full bundle exec rspec run passes: 200 examples, 0 failures.

I used an AI assistant for this change. I reproduced the bug against a real Pushgateway and reviewed and tested the change myself.

A job name or grouping key value of `.` or `..` was put into the URL
path as-is. Those are dot segments, so the Pushgateway answers with a
307 redirect to the cleaned path and the push fails with
HttpRedirectError (proxies may also rewrite the path to a different
group). The Pushgateway docs ask for base64 encoding in this case, the
same way client_golang does it.

Encode these values with `@base64`, like values containing `/`.

Signed-off-by: sarankumar1325 <120080287+sarankumar1325@users.noreply.github.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.

1 participant