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_r285211275
########## 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: I think having a "default" set of reporters we report the metrics to is fine (e.g. JMX is pretty safe), but it would be nice to have a public method which we can call that lets the caller provide a list of Reporters they have configured (gives flexibility to folks downstream like HBase, via LogService, and Ozone). ---------------------------------------------------------------- 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
