forked from micrometer-metrics/micrometer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Publish a separate module with jdk11 classes (micrometer-metrics#4728)
Introduces a new module named micrometer-java11 with a copy of the classes for the JDK http client instrumentation currently in micrometer-core as multi-release jar classes for Java 11. This also deprecates the corresponding classes in micrometer-core and directs users to the new module. Fixes micrometer-metricsgh-3577 --------- Co-authored-by: Tommy Ludwig <[email protected]>
- Loading branch information
Showing
19 changed files
with
758 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
description 'Micrometer core classes that require Java 11' | ||
|
||
dependencies { | ||
api project(":micrometer-core") | ||
|
||
testImplementation 'org.junit.jupiter:junit-jupiter' | ||
testImplementation 'org.assertj:assertj-core' | ||
} | ||
|
||
java { | ||
targetCompatibility = 11 | ||
} | ||
|
||
tasks.withType(JavaCompile).configureEach { | ||
sourceCompatibility = JavaVersion.VERSION_11 | ||
targetCompatibility = JavaVersion.VERSION_11 | ||
options.release = 11 | ||
} | ||
|
||
dependencies { | ||
testImplementation 'ru.lanwen.wiremock:wiremock-junit5' | ||
testImplementation 'com.github.tomakehurst:wiremock-jre8-standalone' | ||
testImplementation project(":micrometer-observation-test") | ||
} |
84 changes: 84 additions & 0 deletions
84
...va/io/micrometer/java11/instrument/binder/jdk/DefaultHttpClientObservationConvention.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* 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.KeyValues; | ||
import io.micrometer.common.lang.NonNull; | ||
import io.micrometer.common.lang.Nullable; | ||
import io.micrometer.core.instrument.binder.http.Outcome; | ||
|
||
import java.net.http.HttpRequest; | ||
import java.net.http.HttpResponse; | ||
import java.util.function.Function; | ||
|
||
/** | ||
* Default implementation of {@link HttpClientObservationConvention}. | ||
* | ||
* @author Marcin Grzejszczak | ||
* @since 1.13.0 | ||
*/ | ||
public class DefaultHttpClientObservationConvention implements HttpClientObservationConvention { | ||
|
||
/** | ||
* Instance of this {@link DefaultHttpClientObservationConvention}. | ||
*/ | ||
public static DefaultHttpClientObservationConvention INSTANCE = new DefaultHttpClientObservationConvention(); | ||
|
||
@Override | ||
public KeyValues getLowCardinalityKeyValues(HttpClientContext context) { | ||
if (context.getCarrier() == null) { | ||
return KeyValues.empty(); | ||
} | ||
HttpRequest httpRequest = context.getCarrier().build(); | ||
KeyValues keyValues = KeyValues.of( | ||
HttpClientObservationDocumentation.LowCardinalityKeys.METHOD.withValue(httpRequest.method()), | ||
HttpClientObservationDocumentation.LowCardinalityKeys.URI | ||
.withValue(getUriTag(httpRequest, context.getResponse(), context.getUriMapper()))); | ||
if (context.getResponse() != null) { | ||
keyValues = keyValues | ||
.and(HttpClientObservationDocumentation.LowCardinalityKeys.STATUS | ||
.withValue(String.valueOf(context.getResponse().statusCode()))) | ||
.and(HttpClientObservationDocumentation.LowCardinalityKeys.OUTCOME | ||
.withValue(Outcome.forStatus(context.getResponse().statusCode()).name())); | ||
} | ||
return keyValues; | ||
} | ||
|
||
String getUriTag(@Nullable HttpRequest request, @Nullable HttpResponse<?> httpResponse, | ||
Function<HttpRequest, String> uriMapper) { | ||
if (request == null) { | ||
return null; | ||
} | ||
return httpResponse != null && (httpResponse.statusCode() == 404 || httpResponse.statusCode() == 301) | ||
? "NOT_FOUND" : uriMapper.apply(request); | ||
} | ||
|
||
@Override | ||
@NonNull | ||
public String getName() { | ||
return "http.client.requests"; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public String getContextualName(HttpClientContext context) { | ||
if (context.getCarrier() == null) { | ||
return null; | ||
} | ||
return "HTTP " + context.getCarrier().build().method(); | ||
} | ||
|
||
} |
45 changes: 45 additions & 0 deletions
45
...er-java11/src/main/java/io/micrometer/java11/instrument/binder/jdk/HttpClientContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* 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.observation.transport.RequestReplySenderContext; | ||
|
||
import java.net.http.HttpClient; | ||
import java.net.http.HttpRequest; | ||
import java.net.http.HttpResponse; | ||
import java.util.Objects; | ||
import java.util.function.Function; | ||
|
||
/** | ||
* A {@link RequestReplySenderContext} for an {@link HttpClient}. | ||
* | ||
* @author Marcin Grzejszczak | ||
* @since 1.13.0 | ||
*/ | ||
public class HttpClientContext extends RequestReplySenderContext<HttpRequest.Builder, HttpResponse<?>> { | ||
|
||
private final Function<HttpRequest, String> uriMapper; | ||
|
||
public HttpClientContext(Function<HttpRequest, String> uriMapper) { | ||
super((carrier, key, value) -> Objects.requireNonNull(carrier).header(key, value)); | ||
this.uriMapper = uriMapper; | ||
} | ||
|
||
public Function<HttpRequest, String> getUriMapper() { | ||
return uriMapper; | ||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
...main/java/io/micrometer/java11/instrument/binder/jdk/HttpClientObservationConvention.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* 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.observation.Observation; | ||
import io.micrometer.observation.ObservationConvention; | ||
|
||
import java.net.http.HttpClient; | ||
|
||
/** | ||
* An {@link ObservationConvention} for an {@link HttpClient}. | ||
* | ||
* @author Marcin Grzejszczak | ||
* @since 1.13.0 | ||
*/ | ||
public interface HttpClientObservationConvention extends ObservationConvention<HttpClientContext> { | ||
|
||
@Override | ||
default boolean supportsContext(Observation.Context context) { | ||
return context instanceof HttpClientContext; | ||
} | ||
|
||
} |
86 changes: 86 additions & 0 deletions
86
...n/java/io/micrometer/java11/instrument/binder/jdk/HttpClientObservationDocumentation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* 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.docs.KeyName; | ||
import io.micrometer.observation.Observation; | ||
import io.micrometer.observation.ObservationConvention; | ||
import io.micrometer.observation.docs.ObservationDocumentation; | ||
|
||
enum HttpClientObservationDocumentation implements ObservationDocumentation { | ||
|
||
/** | ||
* Observation when an HTTP call is being made. | ||
*/ | ||
HTTP_CALL { | ||
@Override | ||
public Class<? extends ObservationConvention<? extends Observation.Context>> getDefaultConvention() { | ||
return DefaultHttpClientObservationConvention.class; | ||
} | ||
|
||
@Override | ||
public KeyName[] getLowCardinalityKeyNames() { | ||
return LowCardinalityKeys.values(); | ||
} | ||
|
||
}; | ||
|
||
enum LowCardinalityKeys implements KeyName { | ||
|
||
/** | ||
* HTTP Method. | ||
*/ | ||
METHOD { | ||
@Override | ||
public String asString() { | ||
return "method"; | ||
} | ||
}, | ||
|
||
/** | ||
* HTTP Status. | ||
*/ | ||
STATUS { | ||
@Override | ||
public String asString() { | ||
return "status"; | ||
} | ||
}, | ||
|
||
/** | ||
* Key name for outcome. | ||
* @since 1.11.0 | ||
*/ | ||
OUTCOME { | ||
@Override | ||
public String asString() { | ||
return "outcome"; | ||
} | ||
}, | ||
|
||
/** | ||
* HTTP URI. | ||
*/ | ||
URI { | ||
@Override | ||
public String asString() { | ||
return "uri"; | ||
} | ||
} | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.