Add parameter to customize status codes mapped as 'NOT_FOUND' in OkHttpMetricsEventListener #4987
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 Description
In my project, I frequently request resources via URLs formatted as
/resource/{id}
. Some resources may not exist or may have expired, resulting in a404
response. It's crucial for me to monitor the proportion of such invalid (possibly expired) resources. Using theurlMapper
functionality ofOkHttpMetricsEventListener
, I convert these URLs from/resource/xxxxx
to a templated form/resource/{id}
for consistent metric collection. But the current implementation aggregates all404
responses under a genericNOT_FOUND
tag, which obfuscates the visibility of specific URLs or patterns contributing to these errors.As discussed in #2410, the
OkHttpMetricsEventListener
in Micrometer currently handles specific HTTP status codes, such as404
, by mapping them to aNOT_FOUND
tag to mitigate tag cardinality issues. However, this behavior is fixed and does not allow for customization based on user-specific needs or different application contexts.Proposed Solution
Introduce flexibility in the
OkHttpMetricsEventListener
that enables users to define custom sets of status codes that should be treated asNOT_FOUND
. Additionally, provide the option to configure whether to create URI tags for requests resulting in these status codes, which could include or exclude404
among others.Benefits
Customization: Users gain control over how status codes are handled, allowing them to adapt metrics collection to better suit their operational and monitoring needs.
Reduced Complexity: Provides a way to handle exceptions to general tagging rules without adding significant complexity to the monitoring setup.
Enhanced Usability: Makes the
OkHttpMetricsEventListener
more versatile and suitable for a wider range of use cases by accommodating different monitoring strategies.This change would make the
OkHttpMetricsEventListener
more adaptable to various monitoring needs, enhancing its overall utility and effectiveness in real-world scenarios.