Add the KPI metrics handler (with no qualifying path) exactly once to each routing #3255
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.
Resolves #3240
The extended KPI metrics implementation in
microprofile/server
adds a handler in the chain that places a "deferrable" KPI metrics context in the request context. (Later,JerseySupport
retrieves and updates the metrics context.)Previously, the code that added the handler would see if the
Application
had an explicit setting for the path/context and, if so, would use that in adding the handler which added the metrics context to the request.That was the problem--because the paths within that context would not match the routing for the handler, the KPI metrics context would (incorrectly) not be added to the request context.
The fix always adds this context-establishing handler to each routing so all requests will have the KPI metrics context set up and so all requests will update the metrics context (and the metrics it delegates to).
In fact, it was slightly inefficient to use the application path in the first place. In the rare (but possible) case of multiple JAX-RS apps, the old approach would have inserted the context-adding handler once for each application. This would not have caused the KPI metrics to be updated multiple times because the attempt to add the KPI context to the request context multiple times would have removed all the but last one, but we might as well avoid that inefficiency on each request.
To avoid this problem, the code makes sure to insert the context-adding handler only once to each named routing or the unnamed routing.
The PR also includes a test which configures the executor with 1 thread and blasts two concurrent requests to make sure the deferred metric is updated and will show a non-zero count.