Skip to content

Base64-encode "." and ".." in Pushgateway URL path segments - #1251

Open
sarankumar1325 wants to merge 1 commit into
prometheus:masterfrom
sarankumar1325:fix/pushgateway-dot-segments
Open

sarankumar1325 wants to merge 1 commit into
prometheus:masterfrom
sarankumar1325:fix/pushgateway-dot-segments

Conversation

@sarankumar1325

Copy link
Copy Markdown

push_to_gateway, pushadd_to_gateway and delete_from_gateway put a job or grouping key value of . or .. into the URL path unchanged, for example /metrics/job/my_job/instance/... Those are dot segments. The Pushgateway router cleans the path and replies with a 307 redirect to a different group (.. points at the parent group), so the call fails with HTTP Error 307: Temporary Redirect.

This change base64-encodes these two values, the same way values with / or spaces are already handled. client_golang's push package does the same thing.

Reproduction against Pushgateway v1.11.5:

push_to_gateway("localhost:9091", job="j", grouping_key={"instance": ".."}, registry=r)
# before: urllib.error.HTTPError: HTTP Error 307: Temporary Redirect
# after:  stored as {"instance": "..", "job": "j"}

Tests:

  • Added test_push_with_groupingkey_dot_segments and test_push_with_dot_segment_job to tests/test_exposition.py. Both fail on master and pass with this change.
  • The full suite passes (451 passed, 3 skipped), and flake8 and isort are clean.
  • Checked by hand against a local Pushgateway v1.11.5: push and delete with . and .. values now succeed.

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

A job or grouping key value of "." or ".." was put into the URL path
as is. These are dot segments: the Pushgateway router cleans the path
and answers with a 307 redirect to a different group (".." points at
the parent), so push_to_gateway, pushadd_to_gateway and
delete_from_gateway fail with "HTTP Error 307". Encode such values
with base64, as client_golang does.

Signed-off-by: sarankumar1325 <120080287+sarankumar1325@users.noreply.github.com>

This branch has not been deployed

No deployments
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