[
https://issues.apache.org/jira/browse/CAMEL-24505?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18110644#comment-18110644
]
Federico Mariani commented on CAMEL-24505:
------------------------------------------
PR opened: https://github.com/apache/camel-spring-boot/pull/1933
The uri tag of requests that do not resolve to a Camel HTTP consumer now keeps
the value computed by Spring's own DefaultServerRequestObservationConvention
(the mapped pattern for a Spring MVC endpoint, or a constant such as UNKNOWN /
NOT_FOUND), instead of the requested path, so the meters no longer grow with
the number of distinct paths requested. Requests that do resolve to a Camel
consumer are unchanged. With uriTagDynamic the requested path is still used,
but only for requests that resolve to a Camel consumer, and the value is capped
and stripped of control characters.
While testing this it turned out that the auto-configuration was conditional on
camel.metrics.uriTagEnabled, a camelCase spelling that Spring Boot cannot
resolve from a relaxed binding source, so the documented
camel.metrics.uri-tag-enabled property never enabled the uri tag. The condition
now uses the kebab-case name and both spellings work.
New tests in components-starter/camel-micrometer-starter/src/test (the starter
had none) assert that 10 requests to 10 distinct unmatched paths produce a
single meter, and that a matched servlet route still yields its consumer path.
They fail against the previous logic with 10 meters.
_Comment added by Claude Code on behalf of Federico Mariani._
> camel-micrometer-starter - uri metric tag falls back to the raw request path,
> giving unbounded tag cardinality
> --------------------------------------------------------------------------------------------------------------
>
> Key: CAMEL-24505
> URL: https://issues.apache.org/jira/browse/CAMEL-24505
> Project: Camel
> Issue Type: Improvement
> Components: camel-micrometer, camel-spring-boot-starters
> Reporter: Andrea Cosentino
> Assignee: Federico Mariani
> Priority: Major
> Fix For: 4.23.0
>
>
> {{MicrometerTagsAutoConfiguration.custom()}} builds the {{uri}} tag for the
> servlet observation:
> {code:java}
> if (servlet.isPresent() && !configuration.isUriTagDynamic()) {
> HttpConsumer consumer =
> servlet.get().getServletResolveConsumerStrategy().resolve(request,
> servlet.get().getConsumers());
> if (consumer != null) {
> uri = consumer.getPath();
> }
> }
> // the request may not be for camel servlet, so we need to capture uri from
> request
> if (uri == null || uri.isEmpty()) {
> uri = request.getServletPath();
> if (uri == null || uri.isEmpty()) {
> uri = request.getPathInfo();
> } else {
> String p = request.getPathInfo();
> if (p != null) {
> uri = uri + p;
> }
> }
> }
> {code}
> (MicrometerTagsAutoConfiguration:70)
> When the request does not resolve to a Camel consumer - any 404, any request
> to a non-Camel path - the tag value becomes the request path verbatim.
> Micrometer creates one meter per distinct tag value and keeps them for the
> process lifetime, so the number of meters follows the number of distinct
> paths requested rather than the number of routes.
> Spring's own convention for this case is a constant {{UNKNOWN}} tag,
> precisely because the value is client-supplied. Only the resolved consumer
> path template is a bounded, route-author-authored value.
> *Proposal*
> - Replace the raw {{servletPath}}/{{pathInfo}} fallback with a constant such
> as {{UNKNOWN}}.
> - Keep the raw path only behind the existing {{uriTagDynamic}} opt-in, and
> normalise or cap it there.
> - Add a test asserting that N requests to N distinct unmatched paths produce
> one meter, not N.
> ----
> _This issue was drafted by Claude Code on behalf of Andrea Cosentino._
--
This message was sent by Atlassian Jira
(v8.20.10#820010)