-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
First shot at integrating mp-metrics. #3
Changes from 1 commit
7d064a2
dc74ede
7469ad3
03c3712
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
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.app.CounterImpl; | ||
import io.smallrye.metrics.interceptors.CountedInterceptor; | ||
import io.smallrye.metrics.interceptors.MeteredInterceptor; | ||
import io.smallrye.metrics.interceptors.MetricNameFactory; | ||
import io.smallrye.metrics.interceptors.MetricsInterceptor; | ||
import io.smallrye.metrics.interceptors.TimedInterceptor; | ||
import org.eclipse.microprofile.metrics.Metric; | ||
import org.eclipse.microprofile.metrics.annotation.Counted; | ||
import org.jboss.jandex.AnnotationInstance; | ||
import org.jboss.jandex.DotName; | ||
import org.jboss.jandex.Index; | ||
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); | ||
|
||
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(); | ||
} | ||
|
||
try (BytecodeRecorder recorder = processorContext.addDeploymentTask(RuntimePriority.WELD_DEPLOYMENT + 30 ) ) { | ||
MetricsDeploymentTemplate metrics = recorder.getRecordingProxy(MetricsDeploymentTemplate.class); | ||
|
||
Index index = archiveContext.getIndex(); | ||
List<AnnotationInstance> annos = index.getAnnotations(DotName.createSimple(Counted.class.getName())); | ||
|
||
for (AnnotationInstance anno : annos) { | ||
metrics.registerCounted(anno.target().toString()); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public int getPriority() { | ||
return 1; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
org.jboss.shamrock.metrics.MetricsProcessor |
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> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?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-runtime</artifactId> | ||
|
||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>io.smallrye</groupId> | ||
<artifactId>smallrye-metrics</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jboss.shamrock</groupId> | ||
<artifactId>shamrock-core-runtime</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jboss.shamrock</groupId> | ||
<artifactId>shamrock-undertow-runtime</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.glassfish</groupId> | ||
<artifactId>javax.json</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jboss.spec.javax.servlet</groupId> | ||
<artifactId>jboss-servlet-api_4.0_spec</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-dependency-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.jboss.shamrock.metrics.runtime; | ||
|
||
import javax.enterprise.inject.spi.CDI; | ||
|
||
import io.smallrye.metrics.MetricRegistries; | ||
import io.smallrye.metrics.app.CounterImpl; | ||
import org.eclipse.microprofile.metrics.Metric; | ||
import org.eclipse.microprofile.metrics.MetricRegistry; | ||
|
||
/** | ||
* Created by bob on 7/30/18. | ||
*/ | ||
public class MetricsDeploymentTemplate { | ||
|
||
public void registerCounted(String name) { | ||
System.err.println("register: " + name); | ||
MetricRegistry registry = MetricRegistries.get(MetricRegistry.Type.APPLICATION); | ||
registry.register(name, new CounterImpl()); | ||
} | ||
|
||
public void createRegistries() { | ||
System.err.println("creating registries"); | ||
MetricRegistries.get(MetricRegistry.Type.APPLICATION); | ||
MetricRegistries.get(MetricRegistry.Type.BASE); | ||
MetricRegistries.get(MetricRegistry.Type.VENDOR); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package org.jboss.shamrock.metrics.runtime; | ||
|
||
import java.io.IOException; | ||
import java.util.Collections; | ||
import java.util.stream.Stream; | ||
|
||
import javax.inject.Inject; | ||
import javax.servlet.annotation.WebServlet; | ||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
import io.smallrye.metrics.MetricsRequestHandler; | ||
|
||
/** | ||
* Created by bob on 7/30/18. | ||
*/ | ||
@WebServlet | ||
public class MetricsServlet extends HttpServlet { | ||
|
||
@Inject | ||
private MetricsRequestHandler metricsHandler; | ||
|
||
@Override | ||
protected void doOptions(HttpServletRequest req, HttpServletResponse resp) throws IOException { | ||
doGet(req, resp); | ||
} | ||
|
||
@Override | ||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { | ||
String requestPath = request.getRequestURI(); | ||
String method = request.getMethod(); | ||
Stream<String> acceptHeaders = Collections.list(request.getHeaders("Accept")).stream(); | ||
|
||
metricsHandler.handleRequest(requestPath, method, acceptHeaders, (status, message, headers) -> { | ||
headers.forEach(response::addHeader); | ||
response.setStatus(status); | ||
response.getWriter().write(message); | ||
}); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,6 +63,10 @@ public void addClass(SeContainerInitializer initializer, Class<?> clazz) { | |
initializer.addBeanClasses(clazz); | ||
} | ||
|
||
public void addInterceptor(SeContainerInitializer initialize, Class<?> interceptorClass) { | ||
initialize.enableInterceptors(interceptorClass); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
|
||
@ContextObject("weld.container") | ||
public SeContainer doBoot( SeContainerInitializer initializer) throws Exception { | ||
SeContainer container = initializer.initialize(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dunno, could this be moved to static instead of deployment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like the answer is "yes"