Skip to content

Commit

Permalink
Add resteasy-observability module
Browse files Browse the repository at this point in the history
  • Loading branch information
ebullient authored and kenfinnigan committed Jun 9, 2021
1 parent f762885 commit fea9a08
Show file tree
Hide file tree
Showing 17 changed files with 400 additions and 3 deletions.
10 changes: 10 additions & 0 deletions bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2489,6 +2489,16 @@
<artifactId>quarkus-opentelemetry-exporter-otlp</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-observability-deployment</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-observability</artifactId>
<version>${project.version}</version>
</dependency>

<!-- Quarkus test dependencies -->
<dependency>
Expand Down
8 changes: 7 additions & 1 deletion extensions/micrometer/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-observability-deployment</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-undertow-deployment</artifactId>
Expand Down Expand Up @@ -113,7 +119,7 @@
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<quarkus.log.level>INFO</quarkus.log.level>
<quarkus.log.level>DEBUG</quarkus.log.level>
</systemPropertyVariables>
</configuration>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#quarkus.log.category."io.quarkus.micrometer".level=DEBUG
quarkus.log.category."io.quarkus.micrometer".level=DEBUG
quarkus.log.category."io.quarkus.resteasy.observability".level=DEBUG
quarkus.log.category."io.quarkus.bootstrap".level=INFO
#quarkus.log.category."io.quarkus.arc".level=DEBUG
quarkus.log.category."io.quarkus.arc".level=DEBUG
quarkus.log.category."io.netty".level=INFO
5 changes: 5 additions & 0 deletions extensions/micrometer/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@
<artifactId>quarkus-resteasy-reactive</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-observability</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>io.quarkus</groupId>
Expand Down
1 change: 1 addition & 0 deletions extensions/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<module>smallrye-opentracing</module>
<module>smallrye-fault-tolerance</module>
<module>jaeger</module>
<module>resteasy-observability</module>
<module>micrometer</module>
<module>micrometer-registry-prometheus</module>
<module>opentelemetry</module>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-undertow-spi</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-observability-spi</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
import io.quarkus.resteasy.common.deployment.ResteasyCommonProcessor.ResteasyCommonConfig;
import io.quarkus.resteasy.common.runtime.QuarkusInjectorFactory;
import io.quarkus.resteasy.common.spi.ResteasyDotNames;
import io.quarkus.resteasy.observability.spi.RestApplicationPathBuildItem;
import io.quarkus.resteasy.server.common.runtime.QuarkusResteasyDeployment;
import io.quarkus.resteasy.server.common.spi.AdditionalJaxRsResourceDefiningAnnotationBuildItem;
import io.quarkus.resteasy.server.common.spi.AdditionalJaxRsResourceMethodAnnotationsBuildItem;
Expand Down Expand Up @@ -182,6 +183,7 @@ public void build(
BuildProducer<NativeImageProxyDefinitionBuildItem> proxyDefinition,
BuildProducer<BytecodeTransformerBuildItem> transformers,
BuildProducer<ResteasyServerConfigBuildItem> resteasyServerConfig,
BuildProducer<RestApplicationPathBuildItem> resteasyApplicationPath,
BuildProducer<ResteasyDeploymentBuildItem> resteasyDeployment,
BuildProducer<UnremovableBeanBuildItem> unremovableBeans,
BuildProducer<AnnotationsTransformerBuildItem> annotationsTransformer,
Expand Down Expand Up @@ -398,6 +400,7 @@ public void build(
ArcUndeclaredThrowableException.class.getName());

resteasyServerConfig.produce(new ResteasyServerConfigBuildItem(rootPath, path, resteasyInitParameters));
resteasyApplicationPath.produce(new RestApplicationPathBuildItem(path));

Set<DotName> autoInjectAnnotationNames = autoInjectAnnotations.stream().flatMap(a -> a.getAnnotationNames().stream())
.collect(Collectors.toSet());
Expand Down
76 changes: 76 additions & 0 deletions extensions/resteasy-observability/deployment/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-observability-parent</artifactId>
<version>999-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>quarkus-resteasy-observability-deployment</artifactId>
<name>Quarkus - RESTEasy Observability - Deployment</name>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-core-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-observability</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-observability-spi</artifactId>
</dependency>

<!-- test -->

<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5-internal</artifactId>
<scope>test</scope>
</dependency>


<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<quarkus.log.level>INFO</quarkus.log.level>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-processor</artifactId>
<version>${project.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package io.quarkus.resteasy.observability.runtime.deployment;

import java.util.Optional;
import java.util.regex.Pattern;

import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationTarget;
import org.jboss.jandex.AnnotationValue;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.DotName;
import org.jboss.jandex.MethodInfo;

import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
import io.quarkus.arc.deployment.AnnotationsTransformerBuildItem;
import io.quarkus.arc.processor.AnnotationsTransformer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.resteasy.observability.runtime.QuarkusRestPathTemplate;
import io.quarkus.resteasy.observability.runtime.QuarkusRestPathTemplateInterceptor;
import io.quarkus.resteasy.observability.spi.RestApplicationPathBuildItem;

public class RestPathAnnotationProcessor {

static final DotName REST_PATH = DotName.createSimple("javax.ws.rs.Path");
static final DotName REGISTER_REST_CLIENT = DotName
.createSimple("org.eclipse.microprofile.rest.client.inject.RegisterRestClient");
static final DotName TEMPLATE_PATH = DotName.createSimple(QuarkusRestPathTemplate.class.getName());
static final DotName TEMPLATE_PATH_INTERCEPTOR = DotName.createSimple(QuarkusRestPathTemplateInterceptor.class.getName());

public static final Pattern MULTIPLE_SLASH_PATTERN = Pattern.compile("//+");

@BuildStep()
AdditionalBeanBuildItem registerBeanClasses() {
return AdditionalBeanBuildItem.builder()
.setUnremovable()
.addBeanClass(TEMPLATE_PATH.toString())
.addBeanClass(TEMPLATE_PATH_INTERCEPTOR.toString())
.build();
}

@BuildStep
AnnotationsTransformerBuildItem findRestPaths(
Optional<RestApplicationPathBuildItem> restApplicationPath) {

return new AnnotationsTransformerBuildItem(new AnnotationsTransformer() {
@Override
public boolean appliesTo(AnnotationTarget.Kind kind) {
return kind == AnnotationTarget.Kind.METHOD;
}

@Override
public void transform(TransformationContext ctx) {
AnnotationTarget target = ctx.getTarget();
MethodInfo methodInfo = target.asMethod();
ClassInfo classInfo = methodInfo.declaringClass();

AnnotationInstance annotation = methodInfo.annotation(REST_PATH);
if (annotation == null) {
return;
}
StringBuilder stringBuilder = new StringBuilder(slashify(annotation.value().asString()));

// Look for @Path annotation on the class
annotation = classInfo.classAnnotation(REST_PATH);
if (annotation != null) {
stringBuilder.insert(0, slashify(annotation.value().asString()));
}

// Add the @ApplicationPath (unless RestClient)
if (restApplicationPath.isPresent() && classInfo.classAnnotation(REGISTER_REST_CLIENT) == null) {
stringBuilder.insert(0, slashify(restApplicationPath.get().getApplicationPath()));
}

// Now make sure there is a leading path, and no duplicates
String templatePath = MULTIPLE_SLASH_PATTERN.matcher('/' + stringBuilder.toString()).replaceAll("/");

// resulting path (used as observability tags) should start with a '/'
ctx.transform()
.add(TEMPLATE_PATH, AnnotationValue.createStringValue("value", templatePath))
.done();
}
});
}

String slashify(String path) {
// avoid doubles later. Empty for now
if (path == null || path.isEmpty() || "/".equals(path)) {
return "";
}
// remove doubles
path = MULTIPLE_SLASH_PATTERN.matcher(path).replaceAll("/");
// Label value consistency: result should not end with a slash
if (path.endsWith("/")) {
path = path.substring(0, path.length() - 1);
}
if (path.isEmpty() || path.startsWith("/")) {
return path;
}
return '/' + path;
}
}
24 changes: 24 additions & 0 deletions extensions/resteasy-observability/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<artifactId>quarkus-extensions-parent</artifactId>
<groupId>io.quarkus</groupId>
<version>999-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<!-- This extension works with BOTH resteasy-classic AND resteasy-reactive extensions -->
<artifactId>quarkus-resteasy-observability-parent</artifactId>
<name>Quarkus - RESTEasy Observability</name>
<packaging>pom</packaging>

<modules>
<module>spi</module>
<module>runtime</module>
<module>deployment</module>
</modules>
</project>
51 changes: 51 additions & 0 deletions extensions/resteasy-observability/runtime/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-observability-parent</artifactId>
<version>999-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>quarkus-resteasy-observability</artifactId>
<name>Quarkus - RESTEasy Observability - Runtime</name>
<description>Telemetry for RESTEasy workloads</description>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-core</artifactId>
</dependency>

<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc</artifactId>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-bootstrap-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-processor</artifactId>
<version>${project.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package io.quarkus.resteasy.observability.runtime;

import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import javax.interceptor.InterceptorBinding;

@Inherited
@InterceptorBinding
@Target({ ElementType.ANNOTATION_TYPE, ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
public @interface QuarkusRestPathTemplate {
String value() default "";
}
Loading

0 comments on commit fea9a08

Please sign in to comment.