From fc69021f469df27f32ef10d00caae076a30e655c Mon Sep 17 00:00:00 2001 From: Tommy Ludwig <8924140+shakuzen@users.noreply.github.com> Date: Tue, 8 Oct 2024 17:41:45 +0900 Subject: [PATCH 1/3] InstrumentationVerificationTests for JDK 11 client This was not copied over when the micrometer-java11 module was made. --- micrometer-java11/build.gradle | 1 + ...imingInstrumentationVerificationTests.java | 74 +++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 micrometer-java11/src/test/java/io/micrometer/java11/instrument/binder/jdk/JdkHttpClientTimingInstrumentationVerificationTests.java diff --git a/micrometer-java11/build.gradle b/micrometer-java11/build.gradle index 2549a4af83..7e5a1f786a 100644 --- a/micrometer-java11/build.gradle +++ b/micrometer-java11/build.gradle @@ -3,6 +3,7 @@ description 'Micrometer core classes that require Java 11' dependencies { api project(":micrometer-core") + testImplementation project(":micrometer-test") testImplementation 'ru.lanwen.wiremock:wiremock-junit5' testImplementation 'com.github.tomakehurst:wiremock-jre8-standalone' testImplementation project(":micrometer-observation-test") diff --git a/micrometer-java11/src/test/java/io/micrometer/java11/instrument/binder/jdk/JdkHttpClientTimingInstrumentationVerificationTests.java b/micrometer-java11/src/test/java/io/micrometer/java11/instrument/binder/jdk/JdkHttpClientTimingInstrumentationVerificationTests.java new file mode 100644 index 0000000000..59c3bb690a --- /dev/null +++ b/micrometer-java11/src/test/java/io/micrometer/java11/instrument/binder/jdk/JdkHttpClientTimingInstrumentationVerificationTests.java @@ -0,0 +1,74 @@ +/* + * Copyright 2024 VMware, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.micrometer.java11.instrument.binder.jdk; + +import io.micrometer.common.lang.Nullable; +import io.micrometer.core.instrument.HttpClientTimingInstrumentationVerificationTests; +import io.micrometer.observation.docs.ObservationDocumentation; + +import java.net.URI; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; +import java.time.Duration; + +class JdkHttpClientTimingInstrumentationVerificationTests + extends HttpClientTimingInstrumentationVerificationTests { + + @Override + protected HttpClient clientInstrumentedWithMetrics() { + return getInstrumentationBuilder().build(); + } + + @Nullable + @Override + protected HttpClient clientInstrumentedWithObservations() { + return getInstrumentationBuilder().observationRegistry(getObservationRegistry()).build(); + } + + private MicrometerHttpClient.InstrumentationBuilder getInstrumentationBuilder() { + return MicrometerHttpClient.instrumentationBuilder( + HttpClient.newBuilder().connectTimeout(Duration.ofMillis(100)).build(), getRegistry()); + } + + @Override + protected void sendHttpRequest(HttpClient instrumentedClient, HttpMethod method, @Nullable byte[] body, URI baseUri, + String templatedPath, String... pathVariables) { + try { + instrumentedClient.send(makeRequest(method, body, baseUri, templatedPath, pathVariables), + HttpResponse.BodyHandlers.ofString()); + } + catch (Exception e) { + throw new RuntimeException(e); + } + } + + @Override + protected ObservationDocumentation observationDocumentation() { + return HttpClientObservationDocumentation.HTTP_CALL; + } + + private HttpRequest makeRequest(HttpMethod method, @Nullable byte[] body, URI baseUri, String templatedPath, + String... pathVariables) { + return HttpRequest.newBuilder() + .method(method.name(), + body != null ? HttpRequest.BodyPublishers.ofByteArray(body) : HttpRequest.BodyPublishers.noBody()) + .uri(URI.create(baseUri + substitutePathVariables(templatedPath, pathVariables))) + .setHeader(MicrometerHttpClient.URI_PATTERN_HEADER, templatedPath) + .build(); + } + +} From 1fbb8bada5c5e33aadfdfb702813f461ae7c7381 Mon Sep 17 00:00:00 2001 From: Tommy Ludwig <8924140+shakuzen@users.noreply.github.com> Date: Tue, 8 Oct 2024 19:13:47 +0900 Subject: [PATCH 2/3] Polish --- .../binder/jdk/HttpClientObservationDocumentation.java | 1 - 1 file changed, 1 deletion(-) diff --git a/micrometer-java11/src/main/java/io/micrometer/java11/instrument/binder/jdk/HttpClientObservationDocumentation.java b/micrometer-java11/src/main/java/io/micrometer/java11/instrument/binder/jdk/HttpClientObservationDocumentation.java index 77ebef4be6..4843677fc6 100644 --- a/micrometer-java11/src/main/java/io/micrometer/java11/instrument/binder/jdk/HttpClientObservationDocumentation.java +++ b/micrometer-java11/src/main/java/io/micrometer/java11/instrument/binder/jdk/HttpClientObservationDocumentation.java @@ -62,7 +62,6 @@ public String asString() { /** * Key name for outcome. - * @since 1.11.0 */ OUTCOME { @Override From 44fdcbe5009d098b40fdeedd019efc269b2ad936 Mon Sep 17 00:00:00 2001 From: Francois Staudt Date: Tue, 8 Oct 2024 22:39:27 +0200 Subject: [PATCH 3/3] Do not include formerly removed micrometer-samples-jetty12 subproject Closes gh-5554 Closes gh-5555 --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index 3d4915b815..85e0d3e139 100644 --- a/settings.gradle +++ b/settings.gradle @@ -26,7 +26,7 @@ buildCache { include 'micrometer-commons', 'micrometer-core', 'micrometer-observation' -['core', 'boot2', 'boot2-reactive', 'spring-integration', 'hazelcast', 'hazelcast3', 'javalin', 'jersey3', 'jetty12', 'jooq', 'kotlin'].each { sample -> +['core', 'boot2', 'boot2-reactive', 'spring-integration', 'hazelcast', 'hazelcast3', 'javalin', 'jersey3', 'jooq', 'kotlin'].each { sample -> include "micrometer-samples-$sample" project(":micrometer-samples-$sample").projectDir = new File(rootProject.projectDir, "samples/micrometer-samples-$sample") }