Github user Ethanlm commented on a diff in the pull request:

    https://github.com/apache/storm/pull/2763#discussion_r205500685
  
    --- Diff: 
storm-server/src/main/java/org/apache/storm/metric/StormMetricsRegistry.java ---
    @@ -27,52 +28,63 @@
     
     @SuppressWarnings("unchecked")
     public class StormMetricsRegistry {
    -    public static final MetricRegistry DEFAULT_REGISTRY = new 
MetricRegistry();
    +    private static final MetricRegistry DEFAULT_REGISTRY = new 
MetricRegistry();
         private static final Logger LOG = 
LoggerFactory.getLogger(StormMetricsRegistry.class);
     
    -    public static Meter registerMeter(String name) {
    -        Meter meter = new Meter();
    -        return register(name, meter);
    +    public static Meter registerMeter(final String name) {
    +        return register(name, new Meter());
         }
     
    -    // TODO: should replace Callable to Gauge<Integer> when nimbus.clj is 
translated to java
    -    public static Gauge<Integer> registerGauge(final String name, final 
Callable fn) {
    -        Gauge<Integer> gauge = new Gauge<Integer>() {
    -            @Override
    -            public Integer getValue() {
    -                try {
    -                    return (Integer) fn.call();
    -                } catch (Exception e) {
    -                    LOG.error("Error getting gauge value for {}", name, e);
    -                }
    -                return 0;
    +    /**
    +     * Register a gauge with provided callback.
    +     * @param name name of the gauge
    +     * @param fn callback that measures
    +     * @param <V> type of measurement the callback returns, also the type 
of gauge
    +     * @return registered gauge
    +     */
    +    public static <V> Gauge<V> registerGauge(final String name, final 
Callable<V> fn) {
    +        return register(name, () -> {
    +            try {
    +                return fn.call();
    +            } catch (Exception e) {
    +                LOG.error("Error getting gauge value for {}", name, e);
                 }
    -        };
    -        return register(name, gauge);
    +            return null;
    +        });
         }
     
    -    public static void registerProvidedGauge(final String name, Gauge 
gauge) {
    +    /**
    +     * Register a provided gauge. Use this method if custom gauges is 
needed or
    +     * no checked exceptions should be handled.
    +     * @param name name of the gauge
    +     * @param gauge gauge
    +     * @param <V> type of value the gauge measures
    +     */
    +    public static <V> void registerProvidedGauge(final String name, final 
Gauge<V> gauge) {
             register(name, gauge);
         }
     
         public static Histogram registerHistogram(String name, Reservoir 
reservoir) {
    -        Histogram histogram = new Histogram(reservoir);
    -        return register(name, histogram);
    +        return register(name, new Histogram(reservoir));
    +    }
    +
    +    public static void registerAll(final String prefix, MetricSet metrics) 
{
    --- End diff --
    
    I like the idea of having `registerMetricSet` and `unregisterMetricSet` in 
#2771 better. 
    
    But to make the commit history easier to understand, I would suggest one of 
the following options:
    1.  put the changes to the patch where is using these methods
    2. Port the changes  in #2771 about `registerMetricSet` and 
`unregisterMetricSet` here. This is to avoid to change the same methods 
multiple times.
    
    I prefer option 1.


---

Reply via email to