Strip query string from uri low-cardinality key in DefaultClientRequestObservationConvention#36646
Closed
anuragg-saxenaa wants to merge 1 commit intospring-projects:mainfrom
Closed
Conversation
…RequestObservationConvention (spring-projects#36547) extractPath() stripped the scheme and authority from a URI template but preserved the query string. When HTTP Interface clients add @RequestParam parameters, Spring injects placeholders like {queryParam-category} into the URI template query string. Because these placeholders differ per combination of present/absent optional parameters and per list length, the uri low-cardinality tag inherits that cardinality — defeating the purpose of the low-cardinality key and causing metric explosion. Strip everything from '?' onward in extractPath() so the uri tag contains only the path portion. Path variables ({id}) continue to be preserved. The full URI (including query) is already captured in the http.url high-cardinality key, so no information is lost. Same fix applied to both spring-web and spring-webflux implementations. Tests updated to assert the new (correct) behaviour. Fixes spring-projects#36547 Signed-off-by: anuragg-saxenaa <anuragg.saxenaa@gmail.com>
Member
|
Declining because this would be breaking behavior. See #36547 (comment) |
Author
|
Thanks for the explanation @bclozel — you're right, stripping query params globally would break valid use cases like The cardinality issue is specific to |
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.
Summary
extractPath()inDefaultClientRequestObservationConventionstripped the scheme and host but preserved the query string. When HTTP Interface clients (@HttpExchange) use@RequestParamparameters, Spring injects URI template placeholders like{queryParam-category}into the query string. Because these differ per combination of present/absent optional parameters and per list length, theurilow-cardinality tag inherits combinatorial or even unbounded cardinality — defeating the purpose of the tag and causing Prometheus metric explosion.Changes
spring-webDefaultClientRequestObservationConvention.extractPath(): strip everything from?onwardspring-webfluxDefaultClientRequestObservationConvention.extractPath(): same fixPath template variables (
{id}) continue to be preserved since they identify distinct endpoint routes. The full URI (including query string) is already captured in thehttp.urlhigh-cardinality key, so no observability information is lost.Behavior change
Before:
After:
This is consistent with how server-side
@RequestMappingwith@RequestParamalready behaves (uri="/api/v1/items"regardless of query parameters).Fixes #36547