Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uri tag replaced with REDIRECTION on all HTTP redirect responses with Jersey server #3327

Closed
tinolazreg opened this issue Aug 2, 2022 · 8 comments · Fixed by #3332
Closed
Labels
bug A general bug module: micrometer-core An issue that is related to our core module
Milestone

Comments

@tinolazreg
Copy link
Contributor

Please describe the feature request.
It would be nice to be able to choose if you want the URI tag to be replaced with REDIRECTION or not. In many cases it is interesting to get metrics on redirects. "304 Not modified" for example is interesting to track, same for "303 See other", how long those the server actually use to fulfil the request.

This line is the reason for the uri tag being set to REDIRECTION: https://github.com/micrometer-metrics/micrometer/blob/main/micrometer-core/src/main/java/io/micrometer/core/instrument/binder/jersey/server/JerseyTags.java#L91.

Rationale
Uri tag replacement for redirect responses should be configureable. In many cases it is interesting to have metrics on redirections.

@shakuzen
Copy link
Member

shakuzen commented Aug 3, 2022

Thank you for the report.

Uri tag replacement for redirect responses should be configureable.

It is already configurable because you provide a JerseyTagsProvider instance. You don't have to use the DefaultJerseyTagsProvider. We could consider providing different behavior for specific redirection status codes in DefaultJerseyTagsProvider, but if you want to customize it for just your applications, that is already possible. Is that sufficient for your use case or would you like us to consider changing DefaultJerseyTagsProvider or am I missing something?

@shakuzen shakuzen added the waiting for feedback We need additional information before we can continue label Aug 3, 2022
@tinolazreg
Copy link
Contributor Author

Thank you for the report.

Uri tag replacement for redirect responses should be configureable.

It is already configurable because you provide a JerseyTagsProvider instance. You don't have to use the DefaultJerseyTagsProvider. We could consider providing different behavior for specific redirection status codes in DefaultJerseyTagsProvider, but if you want to customize it for just your applications, that is already possible. Is that sufficient for your use case or would you like us to consider changing DefaultJerseyTagsProvider or am I missing something?

That is what we have done, so it is solvable on our side, but would be nice to be able to use the JerseyTags.uri() method, so we don't have to handle that ourself. I just thought it seemed strange that the default URI jersey tag logic sets the URI to "REDIRECTION", when we already have the "OUTCOME"-tag that should give us that information.

@shakuzen
Copy link
Member

shakuzen commented Aug 3, 2022

I just thought it seemed strange that the default URI jersey tag logic sets the URI to "REDIRECTION", when we already have the "OUTCOME"-tag that should give us that information.

The point of setting the uri tag to REDIRECTION is to avoid a tag cardinality explosion that could be caused by an unbounded number of unique URIs that result in redirection and are a result of what is requested by a client (potentially an untrusted user). It's a security issue to allow a client to cause unbounded increases in memory in your application and increases in network traffic to publish metrics and increase in storage required for retaining those metrics. This is essentially the same reason unmapped routes that result in 404 have a static NOT_FOUND value for the uri tag. Only if we know reliably that the uri value is not unbounded client input, we can safely tag it.

It was probably out of an abundance of caution that we decided to treat all redirect status codes as unsafe to tag the URI. We can revisit that decision for specific redirect status codes, but it is something we would probably want to standardize across HTTP server instrumentation.

@shakuzen shakuzen added the waiting for team An issue we need members of the team to review label Aug 3, 2022
@tinolazreg
Copy link
Contributor Author

I just thought it seemed strange that the default URI jersey tag logic sets the URI to "REDIRECTION", when we already have the "OUTCOME"-tag that should give us that information.

The point of setting the uri tag to REDIRECTION is to avoid a tag cardinality explosion that could be caused by an unbounded number of unique URIs that result in redirection and are a result of what is requested by a client (potentially an untrusted user).

I understand the caution about tag cardinality explosion, but will that really happen when you are using URI templates? https://github.com/micrometer-metrics/micrometer/blob/main/micrometer-core/src/main/java/io/micrometer/core/instrument/binder/jersey/server/JerseyTags.java#L110

@shakuzen
Copy link
Member

shakuzen commented Aug 5, 2022

will that really happen when you are using URI templates?

As long as there is a matched resource, that assumption may hold true for Jersey server. I think filters could cause a response before the resource is matched, though. We added a check for 404 responses to tag the URI template if a resource was matched in #2587.

@tinolazreg
Copy link
Contributor Author

will that really happen when you are using URI templates?

As long as there is a matched resource, that assumption may hold true for Jersey server. I think filters could cause a response before the resource is matched, though. We added a check for 404 responses to tag the URI template if a resource was matched in #2587.

Would this work: #3332?
Basically just adding an extra check for matched resources, like what is done for 404 responses.

Still not sure if it will ever happen that you have a redirect response without a matching URI template, but it should at least avoid tag cardinality explosion if it can happen.

What do you think?

@shakuzen shakuzen added enhancement A general enhancement module: micrometer-core An issue that is related to our core module and removed waiting for team An issue we need members of the team to review waiting for feedback We need additional information before we can continue labels Aug 8, 2022
@shakuzen shakuzen added this to the 1.10 backlog milestone Aug 8, 2022
@shakuzen shakuzen changed the title Uri tag replaced with REDIRECTION on all HTTP redirect responses Uri tag replaced with REDIRECTION on all HTTP redirect responses with Jersey server Aug 8, 2022
@shakuzen
Copy link
Member

shakuzen commented Aug 8, 2022

Would this work: #3332?

Yes, I think so.
I was going to try to tackle this for all HTTP server instrumentation, but let's focus this issue on the Jersey server instrumentation, which I think is your primary concern. When we formalize the HTTP server instrumentation TCK, we should include a test for this kind of behavior.

@shakuzen shakuzen added bug A general bug and removed enhancement A general enhancement labels Aug 10, 2022
@shakuzen shakuzen modified the milestones: 1.10 backlog, 1.8.10 Aug 10, 2022
@shakuzen
Copy link
Member

I've merged your fix into the 1.8.x branch. Thank you for reporting and sending a fix. The fix will be in upcoming releases 1.8.10, 1.9.4, and 1.10.0-M5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A general bug module: micrometer-core An issue that is related to our core module
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants