Fix spaces in grouping key values for push_to_gateway #1156
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the handling of spaces in grouping key values when using
push_to_gateway. Previously, spaces were converted to+signs, which resulted in incorrect label values in Prometheus Pushgateway.Problem
When pushing metrics with grouping keys containing spaces, the
quote_plusfunction converts spaces to+signs in the URL. The Pushgateway interprets these as literal+characters rather than spaces.Example:
Before fix: Label value becomes
value+with+spacesAfter fix: Label value is correctly
value with spacesSolution
Use base64 encoding for grouping key values containing spaces, similar to how values with slashes are already handled. This ensures the value is transmitted accurately to the Pushgateway.
Changes
_escape_grouping_key()to check for spaces in addition to slashestest_push_with_groupingkey_with_spaces()to verify the fixTest Plan
test_push_with_groupingkey_with_spacesthat verifies:@base64suffixManual verification:
The fix can be verified by running the reproduction script from the issue:
After this change, the Pushgateway will correctly show
label="value with spaces"instead oflabel="value+with+spaces".Fixes #1064