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

Http client instrumentation TCK #3258

Merged

Conversation

shakuzen
Copy link
Member

@shakuzen shakuzen commented Jul 1, 2022

Introduce test suite for HTTP client instrumentations to check that all implementations have the naming and tags expected. This may also help instrumentors ensure backwards compatibility of the HTTP client instrumentation across changes to it.

@shakuzen shakuzen added module: micrometer-test An issue that is related to our TCK enhancement A general enhancement labels Jul 1, 2022
@shakuzen shakuzen added this to the 1.9.2 milestone Jul 1, 2022
@shakuzen shakuzen changed the base branch from main to 1.9.x July 1, 2022 05:34
@shakuzen shakuzen marked this pull request as ready for review July 4, 2022 14:53
@shakuzen shakuzen changed the title WIP Http client instrumentation TCK Http client instrumentation TCK Jul 4, 2022
* @return name of the meter timing http client requests
*/
protected String timerName() {
return "http.client.requests";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A future enhancement idea: We could inject the new naming convention mechanism here - that way if someone wants to see if they are compatible with a given standard they will be able to easily do it

Timer timer = getRegistry().get(timerName()).tags("method", "GET", "status", "404").timer();
// we should standardize on a value e.g. NOT_FOUND, but for backwards
// compatibility, assert is more lenient
assertThat(timer.getId().getTag("uri")).isNotEqualTo(templatedPath);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Apache HTTP client instrumentation is failing this assertion now. We should fix that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While we should definitely test and enforce this for HTTP server instrumentation, it's not the same situation for HTTP client instrumentation. Maybe relaxing this is better.

@Disabled("apache/jetty http client instrumentation currently fails this test")
void timedWhenServerIsMissing() throws IOException {
int unusedPort = 0;
try (ServerSocket server = new ServerSocket(0)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UNENCRYPTED_SERVER_SOCKET: Unencrypted server socket (instead of SSLServerSocket)

Reply with "@sonatype-lift help" for info about LiftBot commands.
Reply with "@sonatype-lift ignore" to tell LiftBot to leave out the above finding from this PR.
Reply with "@sonatype-lift ignoreall" to tell LiftBot to leave out all the findings from this PR and from the status bar in Github.

When talking to LiftBot, you need to refresh the page to see its response. Click here to get to know more about LiftBot commands.


Was this a good recommendation?
[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]

@shakuzen
Copy link
Member Author

The test coverage feels light still, but there is not so much shared behavior between our existing three HTTP clients' instrumentation. This brings up opportunities for improving the consistency and adding tests to the suite.

  • exception and outcome tags are not consistently applied.
  • requests to an address without a server running do not result in timing in all instrumentation
  • normalization of trailing slashes is not consistent

I'm sure there are more we can come up with. For now, I think this is a start and it was a good exercise.

There may be some differences in what is possible to instrument depending on the available API for instrumenting e.g. an HTTP client. If we want to adapt this to that, it may make sense in the future to add a feature to configure capabilities of an instrumentation that enables or disables tests for those capabilities.

Introduce test suite for HTTP client instrumentations to check that all implementations have the naming and tags expected. This may also help instrumentors ensure backwards compatibility of the HTTP client instrumentation across changes to it.
Avoids putting WireMock classes in the API that instrumentors need to implement for the test suite. Also makes it more versatile by passing a method, templated path, and variable substitutions. How templated paths are handled will vary from client to client.
Each implementation has been configured to tag with the URI pattern and that is checked now. Unmapped paths, on the other hand, should not be tagged as requested in the URI. This is currently failing for the Apache HTTP instrumentation.
Rename classes to be standard test class names. Minimize visibility. Remove 404 test, add a disabled test for requests to a down server. We will need to improve the existing instrumentations to add more tests of expected behavior such as that test.
We want to test more than the GET method, and some HTTP clients require a body for POST requests.
@shakuzen
Copy link
Member Author

Since we want to verify existing behavior is maintained, it makes more sense to me to merge this into the oldest supported branch. Rebasing to merge into 1.8.x instead of 1.9.x

@shakuzen shakuzen modified the milestones: 1.9.2, 1.8.8 Jul 11, 2022
@shakuzen shakuzen force-pushed the http-client-instrumentation-tck branch from fd51a2d to b5c3e49 Compare July 11, 2022 16:06
@shakuzen shakuzen changed the base branch from 1.9.x to 1.8.x July 11, 2022 16:06
@shakuzen shakuzen merged commit ab1227c into micrometer-metrics:1.8.x Jul 11, 2022
@shakuzen shakuzen deleted the http-client-instrumentation-tck branch July 11, 2022 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A general enhancement module: micrometer-test An issue that is related to our TCK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants