Percent-encode resource ids in URL paths - #152
Open
fivetime wants to merge 1 commit into
Open
Conversation
Resource ids are free-form strings server-side (anything that is not a UUID gets hashed into one), and real-world ids contain characters that are significant in a URL. Cinder reports storage pools as "<host>@<backend>#<pool>"; putting that id raw into the path turns everything from '#' on into a URL fragment, so resource show/update/ delete and metric-by-resource requests land on "<host>@<backend>" -- a different, usually nonexistent resource -- and fail with 404. The Ceilometer gnocchi publisher hits this on every polled volume.provider.pool.capacity.* sample that carries resource attributes: the initial creation works (the id travels in the batch body) but the attribute update never does. Add utils.encode_resource_id() (urllib.parse.quote with safe="") and apply it wherever a resource id is spliced into a path. Co-Authored-By: Claude Fable 5 <[email protected]>
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.
Problem
Resource ids are free-form strings on the server side (non-UUID ids get hashed into a UUID), and real-world ids contain characters that are significant in a URL. Cinder reports storage pools as
<host>@<backend>#<pool>; the client splices that id raw into the path, so everything from#on becomes a URL fragment and the server sees/v1/resource/volume_provider_pool/<host>@<backend>— a different, usually nonexistent resource → 404.Observed with Ceilometer's gnocchi publisher on
volume.provider.pool.capacity.*samples: creation works (the id travels in the batch body), but every attribute update is rejected:Fix
Add
utils.encode_resource_id()(urllib.parse.quote(..., safe="")) and apply it wherever a resource id is spliced into a path:ResourceManager.get/history/update/deleteand theMetricManagerresource-scoped paths (get,create,delete,get_measures,add_measures,set_measures). UUID ids are unchanged; the server decodes percent-encoding, verified against Gnocchi 4.7:Note
safe=""also encodes@(→%40); harmless for the server, but happy to switch tosafe="@"if you prefer minimal encoding.Tests
gnocchiclient/tests/unit/test_resource_id_encoding.pypins the encoding and the URLs produced by each affected method. Unit suite and flake8 (with the repo's ignore list) pass.Co-authored with Claude (Anthropic); reviewed and tested by a human.