-
Notifications
You must be signed in to change notification settings - Fork 867
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
Apache httpasyncclient 5.x #5697
Apache httpasyncclient 5.x #5697
Conversation
13caea9
to
9617509
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a couple of comments, but overall it looks really good 👍
Thanks!
@Override | ||
@Nullable | ||
public Integer statusCode(ApacheHttpClientRequest request, HttpResponse response) { | ||
return response != null ? response.getCode() : null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
response
will always be non-null here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
return uri != null ? uri.toString() : null; | ||
} | ||
|
||
public String getFlavor(HttpResponse response) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit
public String getFlavor(HttpResponse response) { | |
public String getFlavor(@Nullable HttpResponse response) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was actually done for interim purpose, actually if we see this is kind of a static method or more related to response and not the request, what do you suggest I should do here. This should ideally not be part of the AsyncHttpClientRequest now as it is now not a request property.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, that's true. You can inline this method into ApacheHttpAsyncClientHttpAttributesGetter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will need to add a logger separately in the AttributesGetter as well that should be fine right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, perfectly fine.
|
||
public final class ApacheHttpClientRequest { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(ApacheHttpClientRequest.class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Recently we've removed all slf4j usage from most of the agent code and switched to JUL -- can you rebase against a fresh main
and replace slf4j with java.util.logging
logger?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
...opentelemetry/javaagent/instrumentation/apachehttpasyncclient/ApacheHttpAsyncClientTest.java
Outdated
Show resolved
Hide resolved
Thanks @mateuszrzeszutek there are couple of things I would like to highlight with respect to the MR. Thus in test cases where we are having issues connecting with the server, my tests were failing and thus for the test cases I have removed the check for flavor, although it still comes in for the successful request cases. Suggest me if I can do something here, as far as I saw the library I couldn't think of anything else. |
Support for method
in So the instrumentation kind of doesn't cover all the cases but most of the cases for now. |
a2d70ff
to
35a427c
Compare
Third thing that I would want to highlight here is that HTTP client 5 by default in Negotiate mode which means if http endpoint is given it will do http 1.1 but if https is given then it will prefer http 2. Most of the tests were passed but For now I enforced the http client 5 to use |
return uri != null ? uri.toString() : null; | ||
} | ||
|
||
public String getFlavor(HttpResponse response) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, that's true. You can inline this method into ApacheHttpAsyncClientHttpAttributesGetter
...o/opentelemetry/javaagent/instrumentation/apachehttpasyncclient/ApacheHttpClientRequest.java
Outdated
Show resolved
Hide resolved
case "https": | ||
return 443; | ||
default: | ||
logger.log(FINE, "no default port mapping for scheme: {}", uri.getScheme()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logger.log(FINE, "no default port mapping for scheme: {}", uri.getScheme()); | |
logger.log(FINE, "no default port mapping for scheme: {0}", uri.getScheme()); |
The
It can always be added in a separate PR, I believe it is fine for now (as long as we don't lose that information).
We don't have any HTTP 2 test coverage yet (see #3227) -- for now you don't have to worry about, forcing HTTP/1.1 if perfectly fine. |
35a427c
to
3f3e49c
Compare
I have addressed all the comments, @mateuszrzeszutek you can check the updated code |
This is done as well, any other changes required? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thx @anuragagarwal561994!
instrumentation/apache-httpasyncclient-5.0/javaagent/build.gradle.kts
Outdated
Show resolved
Hide resolved
...aagent/instrumentation/apachehttpasyncclient/ApacheHttpAsyncClientInstrumentationModule.java
Outdated
Show resolved
Hide resolved
Sure @trask let me try doing the same and check if some other issues come up. How about I keep the package name separate and merge the modules? |
bca4ddc
to
a049d8c
Compare
@trask I tried merging the modules, there is just one issue httpclient-5.0 is having groovy test cases as of now and I am not able to get it running on my local, may be things are done correctly just that I was not able to test in my IDE. If you can suggest something it would be of help, it just either reports some imports missing or so. On running gradle build in terminal I get
this is irrespective of this change, just that I couldn't test it on my local. In IDE while building I keep getting javax.annotation.Nullable not found |
...lemetry/javaagent/instrumentation/apachehttpasyncclient/ApacheHttpAsyncClientSingletons.java
Outdated
Show resolved
Hide resolved
...y/javaagent/instrumentation/apachehttpclient/v5_0/ApacheHttpClientInstrumentationModule.java
Outdated
Show resolved
Hide resolved
checked out your PR locally, pushed one small change back to your PR, and tests are passing locally for me |
docs/supported-libraries.md
Outdated
| [Apache HttpAsyncClient](https://hc.apache.org/index.html) | 4.1+ | | ||
| [Apache HttpAsyncClient](https://hc.apache.org/index.html) | 4.1+ and 5.0+ | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think remove this change (5.0+ is covered by 4.1+ anyways)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -0,0 +1,15 @@ | |||
plugins { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can delete this file now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
||
@Override | ||
@Nullable | ||
public String flavor(ApacheHttpClientRequest request, @Nullable HttpResponse response) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if this is exactly the same as method in classic instrumentation, how about extracting common helper somewhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More or less it is same but the request type is different, I guess we will have to keep 2 classes.
} | ||
|
||
// minimize memory overhead by not using streams | ||
static List<String> headersToList(Header[] headers) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same with this method, if exactly the same as method in classic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The suggestions are good, but I guess it will involve more refactoring in both parts of the client support.
Like when I started this MR, I thought of just using HttpRequest only which is http client specific, but then I got a use-case of keeping the extra class AsyncHttpClientRequest which was to store the entity.
Both the async and the http client are kind of using different strategies. In async we are decorating, in classic we are replacing the request instance. So better way would be to have something in common and another way could be to have something like Request / Response adapters which operates on HttpRequest / HttpResponse. I see other methods which repeat like getFlavor
029873f
to
c55b453
Compare
c55b453
to
56e3ed6
Compare
@trask @mateuszrzeszutek I have done some rework on my pull request and now I guess it should look awesome 😄 Let me summarise the ChangeLog:
|
cfba6cd
to
5f6301d
Compare
@mateuszrzeszutek @trask did you get time to review this MR? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thx this is looking great! will do a more thorough review soon
...java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/ApacheHttpClientHelper.java
Outdated
Show resolved
Hide resolved
Co-authored-by: Mateusz Rzeszutek <[email protected]>
Co-authored-by: Mateusz Rzeszutek <[email protected]>
064fcbf
to
5923e66
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thx @anuragagarwal561994 💯
* Copies code for httpasyncclient-4.1 and creates instrumentation for 5.0 * Makes import changes for http client 5 * Decorate request channel and changes type in tests * Corrects test cases * Corrects most of the test cases * Forces http1 protocol to pass the test cases * Merge supported libraries for async client Co-authored-by: Mateusz Rzeszutek <[email protected]> * Remove http.sceme and http.target attr from test Co-authored-by: Mateusz Rzeszutek <[email protected]> * Removes not needed null check for status code * Replaces slf4j loggers with JUL * Inlined flavor extraction in attributes getter * Uses parameter placeholders for logging * Uses success endpoint to test flavor * Merges httpasyncclient and httpclient modules * Merges http client 5 modules * Update java-8 compatible changes Co-authored-by: Mateusz Rzeszutek <[email protected]> * Change instrumentation name Co-authored-by: Mateusz Rzeszutek <[email protected]> * Adds missing import statement * Rename packages * Java 8 * Reverts adding 5.0+ support from supporting libraries * Deleted hanging module * Uses seconds instead of ms in http test * Merges both classic and async client implementations * Moves http client all test cases to java tests * Uses abstract apache test class and moves boilerplate * Uses connection and read timeouts from ApacheHttpClientTest * Refactors remaining classes, shifts logic to HttpUtils * Renames HttpUtils to ApacheHttpClientUtils * Corrects failing code style error * Corrects build errors * Renames package to have http client version * Corrects package name * Uses instrumenter as static import * Inline utility methods Co-authored-by: Mateusz Rzeszutek <[email protected]> Co-authored-by: Trask Stalnaker <[email protected]>
Closes: #5631