Repository navigation
fix(pushgateway): base64-encode empty and slash-containing path values - #871
Open
sarankumar1325 wants to merge 2 commits into
Open
sarankumar1325 wants to merge 2 commits into
sarankumar1325 wants to merge 2 commits into
Conversation
The Pushgateway cannot parse an empty grouping value (the path segment is dropped by its router) or a job name/grouping value containing `/`, even URI-encoded. For those it requires the label name to be suffixed with `@base64` and the value to be URL-safe base64, with `=` for the empty string. Encode those cases that way, like client_golang and client_python do. Signed-off-by: sarankumar1325 <120080287+sarankumar1325@users.noreply.github.com>
As plain path segments they are dot segments, and the Pushgateway redirects the request to the cleaned path, a different group. Signed-off-by: sarankumar1325 <120080287+sarankumar1325@users.noreply.github.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The Pushgateway can't take every job name or grouping value as a plain path segment. Its README says:
//or a trailing/, which its router strips, so/metrics/job/example/first_label//second_label/foobardoesn't work./in a job name or label value is read as a path separator, even when URI-encoded as%2F.For both cases the Pushgateway wants the name suffixed with
@base64and the value sent as URL-safe base64, with=for an empty value (/metrics/job/example/first_label@base64/=/...). The README adds "Ideally, client libraries take care of the suffixing and encoding", and client_golang and client_python both do. Here,generateGroupings()and the job segment always usedencodeURIComponent, sogroupings: { first_label: '' }or{ path: '/var/tmp' }produced a path the Pushgateway can't parse.This change adds a small
encodePathSegment()helper that both the job segment and the groupings use:/<name>@base64/=/→/<name>@base64/<base64url>.or..→/<name>@base64/<base64url>(as plain segments these are dot segments, and the Pushgateway answers with a 307 redirect to the cleaned path, which is a different group; client_golang encodes them too)/<name>/<encodeURIComponent(value)>, as beforeSo existing paths for normal values don't change.
Tests:
pushAddcases intest/pushgatewayTest.js: an empty grouping value (first@base64/=), and a job name plus grouping value that contain/(job@base64/YS9i/path@base64/L3Zhci90bXA). A third case covers a..job name and a.grouping value (job@base64/Li4/first@base64/Lg). Across the registry/content-type variants they fail on main and pass with this change.npm run lint,prettier --check,tsc --project .and the fulljestsuite (663 tests) pass.I found this while reading the code, with help from an AI assistant. I checked the change and the tests myself.