-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from bobmcwhirter/metrics
First shot at integrating mp-metrics.
- Loading branch information
Showing
22 changed files
with
599 additions
and
3 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
Binary file not shown.
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 |
---|---|---|
|
@@ -39,4 +39,4 @@ | |
</plugin> | ||
</plugins> | ||
</build> | ||
</project> | ||
</project> |
16 changes: 16 additions & 0 deletions
16
jaxrs/runtime/src/main/java/org/jboss/shamrock/jaxrs/runtime/graal/JaxrsTemplate.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,16 @@ | ||
package org.jboss.shamrock.jaxrs.runtime.graal; | ||
|
||
import javax.enterprise.inject.se.SeContainer; | ||
|
||
import org.jboss.shamrock.runtime.ContextObject; | ||
|
||
/** | ||
* Created by bob on 7/31/18. | ||
*/ | ||
public class JaxrsTemplate { | ||
|
||
public void setupIntegration(@ContextObject("weld.container")SeContainer container) { | ||
ShamrockInjectorFactory.CONTAINER = container; | ||
} | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
...ime/src/main/java/org/jboss/shamrock/jaxrs/runtime/graal/ShamrockConstructorInjector.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,53 @@ | ||
package org.jboss.shamrock.jaxrs.runtime.graal; | ||
|
||
import java.lang.reflect.Constructor; | ||
|
||
import javax.enterprise.inject.Instance; | ||
import javax.enterprise.inject.spi.CDI; | ||
import javax.ws.rs.WebApplicationException; | ||
|
||
import org.jboss.resteasy.spi.ApplicationException; | ||
import org.jboss.resteasy.spi.ConstructorInjector; | ||
import org.jboss.resteasy.spi.Failure; | ||
import org.jboss.resteasy.spi.HttpRequest; | ||
import org.jboss.resteasy.spi.HttpResponse; | ||
import sun.security.provider.SHA; | ||
|
||
/** | ||
* Created by bob on 7/31/18. | ||
*/ | ||
public class ShamrockConstructorInjector implements ConstructorInjector { | ||
public ShamrockConstructorInjector(Constructor ctor, ConstructorInjector delegate) { | ||
this.ctor = ctor; | ||
this.delegate = delegate; | ||
} | ||
|
||
@Override | ||
public Object construct() { | ||
System.err.println( "construct() " + this.ctor ); | ||
return this.delegate.construct(); | ||
} | ||
|
||
@Override | ||
public Object construct(HttpRequest request, HttpResponse response) throws Failure, WebApplicationException, ApplicationException { | ||
System.err.println( "construct(req,resp) " + this.ctor ); | ||
System.err.println( "CAN WE CDI? " + ShamrockInjectorFactory.CONTAINER); | ||
Instance object = ShamrockInjectorFactory.CONTAINER.select(this.ctor.getDeclaringClass()); | ||
//return this.delegate.construct(request, response); | ||
return object.get(); | ||
} | ||
|
||
@Override | ||
public Object[] injectableArguments() { | ||
return this.delegate.injectableArguments(); | ||
} | ||
|
||
@Override | ||
public Object[] injectableArguments(HttpRequest request, HttpResponse response) throws Failure { | ||
return this.delegate.injectableArguments(request, response); | ||
} | ||
|
||
private final ConstructorInjector delegate; | ||
|
||
private final Constructor ctor; | ||
} |
30 changes: 30 additions & 0 deletions
30
...runtime/src/main/java/org/jboss/shamrock/jaxrs/runtime/graal/ShamrockInjectorFactory.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,30 @@ | ||
package org.jboss.shamrock.jaxrs.runtime.graal; | ||
|
||
import java.lang.reflect.Constructor; | ||
|
||
import javax.enterprise.inject.se.SeContainer; | ||
|
||
import org.jboss.resteasy.core.InjectorFactoryImpl; | ||
import org.jboss.resteasy.spi.ConstructorInjector; | ||
import org.jboss.resteasy.spi.ResteasyProviderFactory; | ||
import org.jboss.resteasy.spi.metadata.ResourceConstructor; | ||
|
||
/** | ||
* Created by bob on 7/31/18. | ||
*/ | ||
public class ShamrockInjectorFactory extends InjectorFactoryImpl { | ||
|
||
public static SeContainer CONTAINER = null; | ||
|
||
@Override | ||
public ConstructorInjector createConstructor(Constructor constructor, ResteasyProviderFactory providerFactory) { | ||
System.err.println( "create constructor: " + constructor ); | ||
return super.createConstructor(constructor, providerFactory); | ||
} | ||
|
||
@Override | ||
public ConstructorInjector createConstructor(ResourceConstructor constructor, ResteasyProviderFactory providerFactory) { | ||
System.err.println( "create resource constructor: " + constructor.getConstructor() ); | ||
return new ShamrockConstructorInjector(constructor.getConstructor(), super.createConstructor(constructor, providerFactory)); | ||
} | ||
} |
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,35 @@ | ||
<?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"> | ||
<parent> | ||
<artifactId>shamrock-metrics</artifactId> | ||
<groupId>org.jboss.shamrock</groupId> | ||
<version>1.0.0.Alpha1-SNAPSHOT</version> | ||
<relativePath>../</relativePath> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>shamrock-metrics-deployment</artifactId> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.jboss.shamrock</groupId> | ||
<artifactId>shamrock-core-deployment</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jboss.shamrock</groupId> | ||
<artifactId>shamrock-weld-deployment</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jboss.shamrock</groupId> | ||
<artifactId>shamrock-undertow-deployment</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jboss.shamrock</groupId> | ||
<artifactId>shamrock-metrics-runtime</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
|
||
</project> |
108 changes: 108 additions & 0 deletions
108
metrics/deployment/src/main/java/org/jboss/shamrock/metrics/MetricsProcessor.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,108 @@ | ||
package org.jboss.shamrock.metrics; | ||
|
||
import java.util.List; | ||
|
||
import javax.inject.Inject; | ||
|
||
import io.smallrye.metrics.MetricProducer; | ||
import io.smallrye.metrics.MetricRegistries; | ||
import io.smallrye.metrics.MetricsRequestHandler; | ||
import io.smallrye.metrics.interceptors.CountedInterceptor; | ||
import io.smallrye.metrics.interceptors.MeteredInterceptor; | ||
import io.smallrye.metrics.interceptors.MetricNameFactory; | ||
import io.smallrye.metrics.interceptors.MetricsBinding; | ||
import io.smallrye.metrics.interceptors.MetricsInterceptor; | ||
import io.smallrye.metrics.interceptors.TimedInterceptor; | ||
import org.eclipse.microprofile.metrics.annotation.Counted; | ||
import org.jboss.jandex.AnnotationInstance; | ||
import org.jboss.jandex.AnnotationTarget; | ||
import org.jboss.jandex.ClassInfo; | ||
import org.jboss.jandex.DotName; | ||
import org.jboss.jandex.Index; | ||
import org.jboss.jandex.MethodInfo; | ||
import org.jboss.shamrock.deployment.ArchiveContext; | ||
import org.jboss.shamrock.deployment.ProcessorContext; | ||
import org.jboss.shamrock.deployment.ResourceProcessor; | ||
import org.jboss.shamrock.deployment.RuntimePriority; | ||
import org.jboss.shamrock.deployment.ShamrockConfig; | ||
import org.jboss.shamrock.deployment.codegen.BytecodeRecorder; | ||
import org.jboss.shamrock.metrics.runtime.MetricsDeploymentTemplate; | ||
import org.jboss.shamrock.metrics.runtime.MetricsServlet; | ||
import org.jboss.shamrock.undertow.ServletData; | ||
import org.jboss.shamrock.undertow.ServletDeployment; | ||
import org.jboss.shamrock.weld.deployment.WeldDeployment; | ||
|
||
//import io.smallrye.health.SmallRyeHealthReporter; | ||
|
||
public class MetricsProcessor implements ResourceProcessor { | ||
|
||
|
||
@Inject | ||
private WeldDeployment weldDeployment; | ||
|
||
@Inject | ||
private ShamrockConfig config; | ||
|
||
@Inject | ||
private ServletDeployment servletDeployment; | ||
|
||
@Override | ||
public void process(ArchiveContext archiveContext, ProcessorContext processorContext) throws Exception { | ||
System.err.println("PROCESSING METRICS"); | ||
ServletData servletData = new ServletData("metrics", MetricsServlet.class.getName()); | ||
servletData.getMapings().add(config.getConfig("metrics.path", "/metrics")); | ||
servletDeployment.addServlet(servletData); | ||
|
||
weldDeployment.addAdditionalBean(MetricProducer.class); | ||
weldDeployment.addAdditionalBean(MetricNameFactory.class); | ||
weldDeployment.addAdditionalBean(MetricRegistries.class); | ||
|
||
weldDeployment.addAdditionalBean(MetricsInterceptor.class); | ||
weldDeployment.addAdditionalBean(MeteredInterceptor.class); | ||
weldDeployment.addAdditionalBean(CountedInterceptor.class); | ||
weldDeployment.addAdditionalBean(TimedInterceptor.class); | ||
|
||
//weldDeployment.addInterceptor(MetricsInterceptor.class); | ||
//weldDeployment.addInterceptor(MeteredInterceptor.class); | ||
//weldDeployment.addInterceptor(CountedInterceptor.class); | ||
//weldDeployment.addInterceptor(TimedInterceptor.class); | ||
|
||
processorContext.addReflectiveClass(Counted.class.getName()); | ||
processorContext.addReflectiveClass(MetricsBinding.class.getName()); | ||
|
||
weldDeployment.addAdditionalBean(MetricsRequestHandler.class); | ||
weldDeployment.addAdditionalBean(MetricsServlet.class); | ||
|
||
try (BytecodeRecorder recorder = processorContext.addStaticInitTask(RuntimePriority.WELD_DEPLOYMENT + 30)) { | ||
MetricsDeploymentTemplate metrics = recorder.getRecordingProxy(MetricsDeploymentTemplate.class); | ||
|
||
metrics.createRegistries(); | ||
|
||
Index index = archiveContext.getIndex(); | ||
List<AnnotationInstance> annos = index.getAnnotations(DotName.createSimple(Counted.class.getName())); | ||
|
||
for (AnnotationInstance anno : annos) { | ||
AnnotationTarget target = anno.target(); | ||
|
||
MethodInfo methodInfo = target.asMethod(); | ||
ClassInfo classInfo = methodInfo.declaringClass(); | ||
|
||
metrics.registerCounted(classInfo.name().toString(), | ||
methodInfo.name().toString()); | ||
|
||
processorContext.addReflectiveClass(classInfo.name().toString()); | ||
} | ||
|
||
} | ||
try (BytecodeRecorder recorder = processorContext.addDeploymentTask(RuntimePriority.WELD_DEPLOYMENT + 30)) { | ||
MetricsDeploymentTemplate metrics = recorder.getRecordingProxy(MetricsDeploymentTemplate.class); | ||
metrics.registerBaseMetrics(); | ||
metrics.registerVendorMetrics(); | ||
} | ||
} | ||
|
||
@Override | ||
public int getPriority() { | ||
return 1; | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...ment/src/main/resources/META-INF/services/org.jboss.shamrock.deployment.ResourceProcessor
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 @@ | ||
org.jboss.shamrock.metrics.MetricsProcessor |
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,18 @@ | ||
<?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"> | ||
<parent> | ||
<artifactId>shamrock-parent</artifactId> | ||
<groupId>org.jboss.shamrock</groupId> | ||
<version>1.0.0.Alpha1-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>shamrock-metrics</artifactId> | ||
<packaging>pom</packaging> | ||
<modules> | ||
<module>deployment</module> | ||
<module>runtime</module> | ||
</modules> | ||
</project> |
Oops, something went wrong.