advancedxy commented on code in PR #939:
URL: https://github.com/apache/incubator-uniffle/pull/939#discussion_r1251981102


##########
common/src/main/java/org/apache/uniffle/common/web/resource/PrometheusMetricResource.java:
##########
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ *
+ *    http://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 org.apache.uniffle.common.web.resource;
+
+import java.io.BufferedWriter;
+import java.io.IOException;
+import java.io.Writer;
+import java.util.Set;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletResponse;
+
+import io.prometheus.client.CollectorRegistry;
+import io.prometheus.client.exporter.common.TextFormat;
+import org.apache.hbase.thirdparty.javax.ws.rs.GET;
+import org.apache.hbase.thirdparty.javax.ws.rs.Path;
+import org.apache.hbase.thirdparty.javax.ws.rs.PathParam;
+import org.apache.hbase.thirdparty.javax.ws.rs.QueryParam;
+import org.apache.hbase.thirdparty.javax.ws.rs.core.Context;
+
+import org.apache.uniffle.common.exception.InvalidRequestException;
+
+@Path("/prometheus/metrics")
+public class PrometheusMetricResource {
+  @Context
+  private HttpServletResponse httpServletResponse;
+  @Context
+  protected ServletContext servletContext;
+
+  @GET
+  @Path("/{type}")
+  public String metrics(
+      @PathParam("type") String type,
+      @QueryParam("name[]") Set<String> names) throws IOException {
+    httpServletResponse.setStatus(200);
+    httpServletResponse.setContentType("text/plain; version=0.0.4; 
charset=utf-8");
+    Writer writer = new BufferedWriter(httpServletResponse.getWriter());
+
+    try {
+      TextFormat.write004(writer, 
getCollectorRegistry(type).filteredMetricFamilySamples(names));
+      writer.flush();
+    } finally {
+      writer.close();
+    }
+    return null;
+  }
+
+  private CollectorRegistry getCollectorRegistry(String type) {
+    CollectorRegistry registry = (CollectorRegistry) 
servletContext.getAttribute(
+        CollectorRegistry.class.getCanonicalName() + "#" + type);
+    if (registry == null) {
+      throw new InvalidRequestException(String.format("Metric type[%s] not 
supported", type));
+    }
+    return registry;
+  }

Review Comment:
   These code is duplicated with 
common/src/main/java/org/apache/uniffle/common/web/resource/MetricResource.java,
 would you mind to extract it and reuse it.



##########
common/src/main/java/org/apache/uniffle/common/web/JerseyAutoDiscoverable.java:
##########
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ *
+ *    http://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 org.apache.uniffle.common.web;
+
+import javax.annotation.Priority;
+
+import org.apache.hbase.thirdparty.javax.ws.rs.core.Configuration;
+import org.apache.hbase.thirdparty.javax.ws.rs.core.FeatureContext;
+import 
org.apache.hbase.thirdparty.org.glassfish.jersey.internal.spi.AutoDiscoverable;
+
+@Priority(AutoDiscoverable.DEFAULT_PRIORITY - 100)
+public class JerseyAutoDiscoverable implements AutoDiscoverable {

Review Comment:
   Do you have to implements this to register JsonConverter? 
   
   Is it possible to simply register it manually before starting jersey server?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to