-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Use (Async) ExecChainHandler to measure IOExceptions (#3800) #3801
Conversation
The only solution I could find to measure errors in |
Unfortunately there are cases when the Basically when errors happen before the actual http request, the possibly cause of #3797? |
This is becoming something bigger then expected. The current implementation for both async (MicrometerHttpClientInterceptor) and classic (MicrometerHttpRequestExecutor) is implemented in a way that
Some experimentation using a So I checked with the HttpClient Team on their advise how to instrument HttpClient (async and classic). They recommend that we should use (Async) ExecChainHandler to capture execution time metrics. I update this PR for (currently hc5 only) and implemented the suggested instrumentation. |
HttpClient has a Feature to execute automatic retries in case of special return codes (503) or retrieable IO exceptions. Default setup ( It is possible to meter the http transaction combined or individually. combined means
individual means
|
...io/micrometer/core/instrument/binder/httpcomponents/hc5/MicrometerHttpClientInterceptor.java
Outdated
Show resolved
Hide resolved
- Support ObservationRegistry in AsyncExecChainHandler - Configurable meterName - Introduce ApacheHttpClientMetricsBinder
...a/io/micrometer/core/instrument/binder/httpcomponents/hc5/MeteringAsyncExecChainHandler.java
Outdated
Show resolved
Hide resolved
...a/io/micrometer/core/instrument/binder/httpcomponents/hc5/ApacheHttpClientMetricsBinder.java
Outdated
Show resolved
Hide resolved
🛠 Lift Auto-fixSome of the Lift findings in this PR can be automatically fixed. You can download and apply these changes in your local project directory of your branch to review the suggestions before committing.1 # Download the patch
curl https://lift.sonatype.com/api/patch/github.com/micrometer-metrics/micrometer/3801.diff -o lift-autofixes.diff
# Apply the patch with git
git apply lift-autofixes.diff
# Review the changes
git diff Want it all in a single command? Open a terminal in your project's directory and copy and paste the following command: curl https://lift.sonatype.com/api/patch/github.com/micrometer-metrics/micrometer/3801.diff | git apply Once you're satisfied, commit and push your changes in your project. Footnotes |
# Conflicts: # micrometer-core/src/test/java/io/micrometer/core/instrument/binder/httpcomponents/hc5/MicrometerHttpClientInterceptorTest.java
# Conflicts: # micrometer-core/src/test/java/io/micrometer/core/instrument/binder/httpcomponents/hc5/MicrometerHttpClientInterceptorTest.java
Superseded by #3800 and merged with cb86bc2. Thanks so much for your contribution @cachescrubber ! |
Hi @bclozel I just took the time to review your changes. Nice to see the I think you missed on important aspect of my original PR. I introduced support to |
Hey @cachescrubber - I left this out on purpose, because the behavior is inconsistent between the "classic" and "async" flavours and I'm afraid there's nothing we can do about it. The Also, setting up the micrometer
Because of this, I don't think we can consistently produce information as |
Hi @bclozel - you are right - instrumentation is a bit different between classic and async. This is why I introduced
this way, the actual placement of the handler inside the handler-chain becomes an implementation detail, an no longer the responsibility of the user. Also, the I'm pretty sure I covered the retry scenarios with integration tests showing consistent behavior for both async and classic. Please see (in my last version)
I actually think the tests would show that specially the async meters are not correct like they are right now. Next to the placement within the handler-chain, I think I could submit a new PR starting with a new Integration Test showing/demonstrating the issue. Did you removed the Wiremock based tests on purpose? Because I'm not sure how to mock the required behaviour. |
I'd rather not tie our instrumentation to implementations details of another ExecChain implementation. Given the inconsistencies and the lack of support for cancellation overall, I don't think this would be wise.
I don't think your initial PR was supporting cancellations and the implementation was still leaking observations. With this in place, I think that the micrometer ExecChain must be configured before the retry one because of internal lifecycle issues with the connection resources. Maybe that's something we should document on the
I think they would be consistent with the behavior of the library: in the async case retries trigger the entire chain, whereas in the classic case this happens internally.
I see where you're coming from, but this merely hides the fact that several separate requests were made. If I understand correctly, if retries are not metered, there is a single observation that does not cover all retries in the async mode. Depending on how the setup is made, this could be the opposite for the classic case. With all that in mind, I don't think we should try to compensate for the inconsistencies in the library itself. |
Yes, my initial PR did not support cancellations. I created another PR reinstating my meterRetries support over your much improved HandlerChain implementation. It would be great if you could have a look at #3941. Is it still leaking observations or does your async cancellation support also kicks in here? |
Use
HttpRequestRetryStrategy
to measure IOExceptions.Fixes #3800, #3797, #3706