You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2018/10/18 22:38:58 UTC

[GitHub] merlimat closed pull request #2804: Export Jetty stats to Prometheus

merlimat closed pull request #2804: Export Jetty stats to Prometheus
URL: https://github.com/apache/pulsar/pull/2804
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/distribution/server/src/assemble/LICENSE.bin.txt b/distribution/server/src/assemble/LICENSE.bin.txt
index 970808cd2b..0daca02684 100644
--- a/distribution/server/src/assemble/LICENSE.bin.txt
+++ b/distribution/server/src/assemble/LICENSE.bin.txt
@@ -353,11 +353,12 @@ The Apache Software License, Version 2.0
     - io.netty-netty-all-4.1.22.Final.jar
     - io.netty-netty-tcnative-boringssl-static-2.0.7.Final.jar
  * Prometheus client
-    - io.prometheus-simpleclient-0.0.23.jar
-    - io.prometheus-simpleclient_common-0.0.23.jar
-    - io.prometheus-simpleclient_hotspot-0.0.23.jar
-    - io.prometheus-simpleclient_servlet-0.0.23.jar
-    - io.prometheus-simpleclient_log4j2-0.0.23.jar
+    - io.prometheus-simpleclient-0.5.0.jar
+    - io.prometheus-simpleclient_common-0.5.0.jar
+    - io.prometheus-simpleclient_hotspot-0.5.0.jar
+    - io.prometheus-simpleclient_servlet-0.5.0.jar
+    - io.prometheus-simpleclient_log4j2-0.5.0.jar
+    - io.prometheus-simpleclient_jetty-0.5.0.jar
  * Bean Validation API -- javax.validation-validation-api-1.1.0.Final.jar
  * Log4J
     - log4j-log4j-1.2.17.jar
diff --git a/pom.xml b/pom.xml
index 9d6ab79898..c751c9e6bf 100644
--- a/pom.xml
+++ b/pom.xml
@@ -147,7 +147,7 @@ flexible messaging model and an intuitive client API.</description>
     <jetty.version>9.3.11.v20160721</jetty.version>
     <jersey.version>2.25</jersey.version>
     <athenz.version>1.7.17</athenz.version>
-    <prometheus.version>0.0.23</prometheus.version>
+    <prometheus.version>0.5.0</prometheus.version>
     <aspectj.version>1.9.1</aspectj.version>
     <rocksdb.version>5.13.3</rocksdb.version>
     <slf4j.version>1.7.25</slf4j.version>
@@ -686,6 +686,12 @@ flexible messaging model and an intuitive client API.</description>
         <version>${prometheus.version}</version>
       </dependency>
 
+      <dependency>
+        <groupId>io.prometheus</groupId>
+        <artifactId>simpleclient_jetty</artifactId>
+        <version>${prometheus.version}</version>
+      </dependency>
+
       <dependency>
         <groupId>com.carrotsearch</groupId>
         <artifactId>hppc</artifactId>
diff --git a/pulsar-broker/pom.xml b/pulsar-broker/pom.xml
index 0457c79b2c..14e9e3019d 100644
--- a/pulsar-broker/pom.xml
+++ b/pulsar-broker/pom.xml
@@ -210,6 +210,12 @@
       <artifactId>simpleclient</artifactId>
     </dependency>
 
+    <dependency>
+      <groupId>io.prometheus</groupId>
+      <artifactId>simpleclient_jetty</artifactId>
+    </dependency>
+
+
     <dependency>
       <groupId>io.prometheus</groupId>
       <artifactId>simpleclient_hotspot</artifactId>
diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/web/WebService.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/web/WebService.java
index 34809b0f09..360c44eee0 100644
--- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/web/WebService.java
+++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/web/WebService.java
@@ -43,6 +43,7 @@
 import org.eclipse.jetty.server.handler.HandlerCollection;
 import org.eclipse.jetty.server.handler.RequestLogHandler;
 import org.eclipse.jetty.server.handler.ResourceHandler;
+import org.eclipse.jetty.server.handler.StatisticsHandler;
 import org.eclipse.jetty.servlet.FilterHolder;
 import org.eclipse.jetty.servlet.ServletContextHandler;
 import org.eclipse.jetty.servlet.ServletHolder;
@@ -59,6 +60,7 @@
 import com.google.common.collect.Lists;
 
 import io.netty.util.concurrent.DefaultThreadFactory;
+import io.prometheus.client.jetty.JettyStatisticsCollector;
 
 /**
  * Web Service embedded into Pulsar
@@ -167,11 +169,21 @@ public void start() throws PulsarServerException {
             handlers.add(0, new ContextHandlerCollection());
             handlers.add(requestLogHandler);
 
+            // Metrics handler
+            StatisticsHandler stats = new StatisticsHandler();
+            stats.setHandler(server.getHandler());
+            try {
+                new JettyStatisticsCollector(stats).register();
+            } catch (IllegalArgumentException e) {
+                // Already registered. Eg: in unit tests
+            }
+            handlers.add(stats);
+
             ContextHandlerCollection contexts = new ContextHandlerCollection();
             contexts.setHandlers(handlers.toArray(new Handler[handlers.size()]));
 
             HandlerCollection handlerCollection = new HandlerCollection();
-            handlerCollection.setHandlers(new Handler[] { contexts, new DefaultHandler(), requestLogHandler });
+            handlerCollection.setHandlers(new Handler[] { contexts, new DefaultHandler(), requestLogHandler, stats });
             server.setHandler(handlerCollection);
 
             server.start();
diff --git a/pulsar-proxy/pom.xml b/pulsar-proxy/pom.xml
index b88a5a3a28..47955d3fe5 100644
--- a/pulsar-proxy/pom.xml
+++ b/pulsar-proxy/pom.xml
@@ -109,6 +109,11 @@
       <artifactId>simpleclient_servlet</artifactId>
     </dependency>
 
+    <dependency>
+      <groupId>io.prometheus</groupId>
+      <artifactId>simpleclient_jetty</artifactId>
+    </dependency>
+
     <dependency>
       <groupId>${project.groupId}</groupId>
       <artifactId>pulsar-broker</artifactId>
diff --git a/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/WebServer.java b/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/WebServer.java
index 97e457f110..b0bf612b30 100644
--- a/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/WebServer.java
+++ b/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/WebServer.java
@@ -22,6 +22,7 @@
 import com.google.common.collect.Lists;
 
 import io.netty.util.concurrent.DefaultThreadFactory;
+import io.prometheus.client.jetty.JettyStatisticsCollector;
 
 import java.io.IOException;
 import java.net.URI;
@@ -52,6 +53,7 @@
 import org.eclipse.jetty.server.handler.DefaultHandler;
 import org.eclipse.jetty.server.handler.HandlerCollection;
 import org.eclipse.jetty.server.handler.RequestLogHandler;
+import org.eclipse.jetty.server.handler.StatisticsHandler;
 import org.eclipse.jetty.servlet.FilterHolder;
 import org.eclipse.jetty.servlet.ServletContextHandler;
 import org.eclipse.jetty.servlet.ServletHolder;
@@ -174,8 +176,17 @@ public void start() throws Exception {
         ContextHandlerCollection contexts = new ContextHandlerCollection();
         contexts.setHandlers(handlers.toArray(new Handler[handlers.size()]));
 
+        // Metrics handler
+        StatisticsHandler stats = new StatisticsHandler();
+        stats.setHandler(server.getHandler());
+        try {
+            new JettyStatisticsCollector(stats).register();
+        } catch (IllegalArgumentException e) {
+            // Already registered. Eg: in unit tests
+        }
+
         HandlerCollection handlerCollection = new HandlerCollection();
-        handlerCollection.setHandlers(new Handler[] { contexts, new DefaultHandler(), requestLogHandler });
+        handlerCollection.setHandlers(new Handler[] { contexts, new DefaultHandler(), requestLogHandler, stats });
         server.setHandler(handlerCollection);
 
         try {
diff --git a/pulsar-sql/presto-distribution/LICENSE b/pulsar-sql/presto-distribution/LICENSE
index 4716e3cfb5..b5cd856c19 100644
--- a/pulsar-sql/presto-distribution/LICENSE
+++ b/pulsar-sql/presto-distribution/LICENSE
@@ -415,10 +415,10 @@ The Apache Software License, Version 2.0
     - metrics-graphite-3.1.0.jar
     - metrics-jvm-3.1.0.jar
   * Prometheus
-    - simpleclient-0.0.23.jar
-    - simpleclient_common-0.0.23.jar
-    - simpleclient_hotspot-0.0.23.jar
-    - simpleclient_servlet-0.0.23.jar
+    - simpleclient-0.5.0.jar
+    - simpleclient_common-0.5.0.jar
+    - simpleclient_hotspot-0.5.0.jar
+    - simpleclient_servlet-0.5.0.jar
   * LZ4
     - lz4-java-1.5.0.jar
   * Bookkeeper
@@ -530,4 +530,3 @@ Bouncy Castle License
  * Bouncy Castle -- licenses/LICENSE-bouncycastle.txt
     - bcpkix-jdk15on-1.55.jar
     - bcprov-jdk15on-1.55.jar
-


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services