Skip to content

Commit

Permalink
Moved Jakarta and latest Jakarta based dependencies
Browse files Browse the repository at this point in the history
created a separate micrometer-jakarta module and put all the latest deps there. That way we could instrument latest Tomcat, Jersey etc. without any classpath issues
  • Loading branch information
marcingrzejszczak committed Aug 22, 2023
1 parent 1e8f194 commit 77bd8b1
Show file tree
Hide file tree
Showing 44 changed files with 857 additions and 107 deletions.
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,8 @@ subprojects {

check.dependsOn("testModules")

if (!(project.name in ['micrometer-osgi-test'])) {
// TODO: Remove jakarta back once it's released at least once
if (!(project.name in ['micrometer-osgi-test', 'micrometer-jakarta'])) {
apply plugin: 'me.champeau.gradle.japicmp'
apply plugin: 'de.undercouch.download'

Expand Down
50 changes: 37 additions & 13 deletions micrometer-core/gradle.lockfile

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,21 @@
import io.micrometer.common.KeyValues;
import io.micrometer.common.lang.Nullable;
import io.micrometer.common.util.StringUtils;
import io.micrometer.core.annotation.Incubating;
import io.micrometer.core.instrument.binder.http.HttpObservationDocumentation.ClientLowCardinalityKeys;
import io.micrometer.core.instrument.binder.http.HttpObservationDocumentation.CommonHighCardinalityKeys;
import io.micrometer.core.instrument.binder.http.HttpObservationDocumentation.CommonLowCardinalityKeys;

class AbstractDefaultHttpClientRequestObservationConvention {
/**
* Abstract convention methods to share between javax and jakarta based implementations.
*
* For internal use, do not inherit.
*
* @author Marcin Grzejsczak
* @since 1.12.0
*/
@Incubating(since = "1.12.0")
public class AbstractDefaultHttpClientRequestObservationConvention {

private static final Pattern PATTERN_BEFORE_PATH = Pattern.compile("^https?://[^/]+/");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,20 @@
import io.micrometer.common.KeyValues;
import io.micrometer.common.lang.Nullable;
import io.micrometer.common.util.StringUtils;
import io.micrometer.core.annotation.Incubating;
import io.micrometer.core.instrument.binder.http.HttpObservationDocumentation.CommonHighCardinalityKeys;
import io.micrometer.core.instrument.binder.http.HttpObservationDocumentation.CommonLowCardinalityKeys;

class AbstractDefaultHttpServerRequestObservationConvention {
/**
* Abstract convention methods to share between javax and jakarta based implementations.
*
* For internal use, do not inherit.
*
* @author Marcin Grzejsczak
* @since 1.12.0
*/
@Incubating(since = "1.12.0")
public class AbstractDefaultHttpServerRequestObservationConvention {

protected static final String DEFAULT_NAME = "http.server.requests";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import io.micrometer.common.KeyValues;

/**
* Default {@link HttpJakartaServerRequestObservationConvention}.
* Default {@link HttpServerRequestObservationConvention}.
*
* @author Brian Clozel
* @since 1.12.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,48 +30,6 @@
*/
public enum HttpObservationDocumentation implements ObservationDocumentation {

/**
* Observation created when a request is sent out via Jakarta API.
*/
JAKARTA_CLIENT_OBSERVATION {
@Override
public Class<? extends ObservationConvention<? extends Context>> getDefaultConvention() {
return DefaultHttpJakartaClientRequestObservationConvention.class;
}

@Override
public KeyName[] getLowCardinalityKeyNames() {
return KeyName.merge(CommonLowCardinalityKeys.values(), ClientLowCardinalityKeys.values());
}

@Override
public KeyName[] getHighCardinalityKeyNames() {
return KeyName.merge(CommonHighCardinalityKeys.values(), ClientHighCardinalityKeys.values());
}
},

/**
* Observation created when a request is received with Jakarta Http.
*/
JAKARTA_SERVER_OBSERVATION {
@Override
public Class<? extends ObservationConvention<? extends Context>> getDefaultConvention() {
return DefaultHttpJakartaServerRequestObservationConvention.class;
}

@Override
public KeyName[] getLowCardinalityKeyNames() {

return KeyName.merge(CommonLowCardinalityKeys.values(), ServerLowCardinalityKeys.values());
}

@Override
public KeyName[] getHighCardinalityKeyNames() {
return CommonHighCardinalityKeys.values();
}

},

/**
* Observation created when a request is received with Javax Http.
*/
Expand All @@ -93,7 +51,7 @@ public KeyName[] getHighCardinalityKeyNames() {

};

enum CommonLowCardinalityKeys implements KeyName {
public enum CommonLowCardinalityKeys implements KeyName {

/**
* HTTP request method.
Expand Down Expand Up @@ -221,7 +179,7 @@ public String asString() {

}

enum ServerLowCardinalityKeys implements KeyName {
public enum ServerLowCardinalityKeys implements KeyName {

/**
* The matched route (path template in the format used by the respective server
Expand All @@ -241,7 +199,7 @@ public String asString() {

}

enum ClientLowCardinalityKeys implements KeyName {
public enum ClientLowCardinalityKeys implements KeyName {

/**
* Client name derived from the request URI host.
Expand All @@ -255,7 +213,7 @@ public String asString() {

}

enum CommonHighCardinalityKeys implements KeyName {
public enum CommonHighCardinalityKeys implements KeyName {

/**
* The size of the request payload body in bytes. This is the number of bytes
Expand Down Expand Up @@ -322,7 +280,7 @@ public String asString() {

}

enum ClientHighCardinalityKeys implements KeyName {
public enum ClientHighCardinalityKeys implements KeyName {

/**
* Absolute URL describing a network resource according to RFC3986
Expand Down
116 changes: 116 additions & 0 deletions micrometer-jakarta/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
plugins {
id 'me.champeau.mrjar' version "0.1.1"
}

description 'Module for Jakarta based instrumentations'

jar {
bundle {

bnd '''\
Import-Package: \
org.eclipse.jetty.*;resolution:=dynamic;version="${@}",\
org.glassfish.jersey.*;resolution:=dynamic;version="${@}",\
ch.qos.logback.*;resolution:=dynamic;version="${@}",\
org.apache.logging.log4j.*;resolution:=dynamic;version="${@}",\
jakarta.jms.*;resolution:=dynamic;version="${@}",\
jakarta.servlet.*;resolution:=dynamic;version="${@}",\
io.micrometer.context.*;resolution:=dynamic,\
io.micrometer.observation.*;resolution:=dynamic;version="${@}",\
*
'''.stripIndent()
}
}

dependencies {
api project(":micrometer-core")
api project(":micrometer-commons")
api project(":micrometer-observation")
optionalApi 'jakarta.ws.rs:jakarta.ws.rs-api:3.+' // jakarta

// Aspects
optionalApi 'org.aspectj:aspectjweaver'

optionalApi 'org.eclipse.jetty:jetty-server'
// jakarta servlet
optionalApi 'jakarta.servlet:jakarta.servlet-api:5.+'
optionalApi 'org.eclipse.jetty:jetty-client:12.0.+'
optionalApi 'org.apache.tomcat.embed:tomcat-embed-core:10.1.+'
optionalApi 'org.glassfish.jersey.core:jersey-server:3.1.+'
// jakarta JMS
optionalApi 'jakarta.jms:jakarta.jms-api'

// log monitoring
optionalApi 'ch.qos.logback:logback-classic'
optionalApi 'org.apache.logging.log4j:log4j-core'

optionalApi project(':micrometer-observation')
optionalApi 'io.micrometer:context-propagation'

testImplementation project(":micrometer-observation-test")

// JUnit 5
testImplementation 'org.junit.jupiter:junit-jupiter'
testImplementation 'com.tngtech.archunit:archunit-junit5'

testImplementation 'org.mockito:mockito-inline'

testImplementation 'org.assertj:assertj-core'
testImplementation 'org.awaitility:awaitility'

testImplementation 'org.glassfish.jersey.test-framework.providers:jersey-test-framework-provider-inmemory'
testRuntimeOnly 'org.glassfish.jersey.inject:jersey-hk2'

testImplementation 'ru.lanwen.wiremock:wiremock-junit5'
testImplementation 'com.github.tomakehurst:wiremock-jre8-standalone'

// Dependencies for @ClassPathExclusions
testImplementation("org.junit.platform:junit-platform-engine")
testImplementation("org.junit.platform:junit-platform-launcher")
testImplementation("javax.validation:validation-api")
testImplementation("org.jboss.resteasy:resteasy-netty4")
}

task shenandoahTest(type: Test) {
// set heap size for the test JVM(s)
maxHeapSize = "1500m"

useJUnitPlatform {
includeTags 'gc'
}

jvmArgs '-XX:+UseShenandoahGC'
}

task zgcTest(type: Test) {
// set heap size for the test JVM(s)
maxHeapSize = "1500m"

useJUnitPlatform {
includeTags 'gc'
}

jvmArgs '-XX:+UseZGC'
}

task openj9BalancedTest(type: Test) {
// set heap size for the test JVM(s)
maxHeapSize = "1500m"

useJUnitPlatform {
includeTags 'gc'
}

jvmArgs '-Xgcpolicy:balanced'
}

task openj9ConcurrentScavengeTest(type: Test) {
// set heap size for the test JVM(s)
maxHeapSize = "1500m"

useJUnitPlatform {
includeTags 'gc'
}

jvmArgs '-Xgc:concurrentScavenge'
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020 VMware, Inc.
* Copyright 2023 VMware, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -13,11 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.micrometer.core.instrument.binder.http;

import java.net.URI;
package io.micrometer.jakarta.instrument.binder.http;

import io.micrometer.common.KeyValues;
import io.micrometer.core.instrument.binder.http.AbstractDefaultHttpClientRequestObservationConvention;

import java.net.URI;

/**
* Default {@link HttpJakartaServerRequestObservationConvention}.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020 VMware, Inc.
* Copyright 2023 VMware, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -13,9 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.micrometer.core.instrument.binder.http;
package io.micrometer.jakarta.instrument.binder.http;

import io.micrometer.common.KeyValues;
import io.micrometer.core.instrument.binder.http.AbstractDefaultHttpServerRequestObservationConvention;

/**
* Default {@link HttpJakartaServerRequestObservationConvention}.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright 2023 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.jakarta.instrument.binder.http;

import io.micrometer.common.KeyValues;
import io.micrometer.core.instrument.binder.http.AbstractDefaultHttpServerRequestObservationConvention;

/**
* Default {@link HttpJakartaServerServletRequestObservationConvention}.
*
* @author Brian Clozel
* @author Marcin Grzejszczak
* @since 1.12.0
*/
public class DefaultHttpJakartaServerServletRequestObservationConvention
extends AbstractDefaultHttpServerRequestObservationConvention
implements HttpJakartaServerServletRequestObservationConvention {

private static final String DEFAULT_NAME = "http.server.requests";

private final String name;

/**
* Create a convention with the default name {@code "http.server.requests"}.
*/
public DefaultHttpJakartaServerServletRequestObservationConvention() {
this(DEFAULT_NAME);
}

/**
* Create a convention with a custom name.
* @param name the observation name
*/
public DefaultHttpJakartaServerServletRequestObservationConvention(String name) {
this.name = name;
}

@Override
public String getName() {
return this.name;
}

@Override
public String getContextualName(HttpJakartaServerServletRequestObservationContext context) {
String method = context.getCarrier().getMethod();
if (method == null) {
return null;
}
return getContextualName(method.toLowerCase(), context.getPathPattern());
}

@Override
public KeyValues getLowCardinalityKeyValues(HttpJakartaServerServletRequestObservationContext context) {
String method = context.getCarrier() != null ? context.getCarrier().getMethod() : null;
Integer status = context.getResponse() != null ? context.getResponse().getStatus() : null;
String pathPattern = context.getPathPattern();
String requestUri = context.getCarrier() != null ? context.getCarrier().getRequestURI() : null;
return getLowCardinalityKeyValues(context.getError(), method, status, pathPattern, requestUri);
}

@Override
public KeyValues getHighCardinalityKeyValues(HttpJakartaServerServletRequestObservationContext context) {
String requestUri = context.getCarrier() != null ? context.getCarrier().getRequestURI() : null;
return getHighCardinalityKeyValues(requestUri);
}

}
Loading

0 comments on commit 77bd8b1

Please sign in to comment.