joshelser commented on a change in pull request #19: 
RATIS-549,RATIS-550,RATIS-552,RATIS-553 Metric Framework for Ratis
URL: https://github.com/apache/incubator-ratis/pull/19#discussion_r285749249
 
 

 ##########
 File path: 
ratis-server/src/main/java/org/apache/ratis/server/metrics/RatisMetricsRegistry.java
 ##########
 @@ -0,0 +1,52 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.ratis.server.metrics;
+
+import java.util.Optional;
+
+import com.codahale.metrics.JmxReporter;
+import com.codahale.metrics.MetricRegistry;
+import org.apache.ratis.metrics.MetricRegistries;
+import org.apache.ratis.metrics.MetricRegistryInfo;
+import org.apache.ratis.metrics.impl.RatisMetricRegistry;
+
+public class RatisMetricsRegistry {
+  public final static String RATIS_LOG_WORKER_METRICS_DESC = "Ratis Log worker 
metrics";
+  public final static String RATIS_LOG_WORKER_METRICS_CONTEXT = 
"RaftLogWorker";
+
+  public static RatisMetricRegistry createMetricRegistryForLogWorker(String 
name) {
+    return create(new MetricRegistryInfo(name, RATIS_LOG_WORKER_METRICS_DESC,
+        RATIS_LOG_WORKER_METRICS_CONTEXT));
+  }
+
+  public static RatisMetricRegistry getMetricRegistryForLogWorker(String name) 
{
+    return MetricRegistries.global().get(new MetricRegistryInfo(name, 
RATIS_LOG_WORKER_METRICS_DESC,
+        RATIS_LOG_WORKER_METRICS_CONTEXT)).get();
+  }
+
+  private static RatisMetricRegistry create(MetricRegistryInfo info) {
+    Optional<RatisMetricRegistry> metricRegistry = 
MetricRegistries.global().get(info);
+    if (metricRegistry.isPresent()) {
+      return metricRegistry.get();
+    }
+    RatisMetricRegistry registry = MetricRegistries.global().create(info);
+    JmxReporter.forRegistry(registry.getMetricRegistry()).build().start();
 
 Review comment:
   Hrmmm, good point. I can see how this doesn't lend itself well to what we 
want to do.
   
   If we are going to center on the Dropwizard metrics API, then I think the 
clearest thing to do is make it crystal clear how a user gets the 
`MetricsRegistry` object that they need to pass to any converter. Maybe that is 
more documentation than just code? e.g. If I wrote my own state machine, what 
method do I call to set up custom reporters?
   
   We could consider a utility method to wrap the common reporters (e.g. file, 
ganglia, JMX), but I think those are more of ourselves to reduce code 
duplication. An end-user could create their method just as easy to configure 
the reporters.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to