@Test public void testCreateOrUpdateHistogram() { String eventLatency = "eventLatency"; String processLatency = "processLatency"; String fullKeylessMetricName = MetricRegistry.name(CLASS_NAME, eventLatency); _metricsManager.createOrUpdateHistogram(CLASS_NAME, eventLatency, 1); Histogram keylessHistogram = _metricsManager.getMetric(fullKeylessMetricName); Assert.assertEquals(keylessHistogram.getSnapshot().getMin(), 1); _metricsManager.createOrUpdateHistogram(CLASS_NAME, eventLatency, 5); Assert.assertEquals(keylessHistogram.getSnapshot().getMax(), 5); _metricsManager.createOrUpdateHistogram(CLASS_NAME, eventLatency, 10); String someKey = "someKey"; String fullMetricName = MetricRegistry.name(CLASS_NAME, someKey, eventLatency); _metricsManager.createOrUpdateHistogram(CLASS_NAME, someKey, eventLatency, 3); Histogram keyedHistogram = _metricsManager.getMetric(fullMetricName); Assert.assertEquals(keyedHistogram.getSnapshot().getMin(), 3); _metricsManager.createOrUpdateHistogram(CLASS_NAME, someKey, eventLatency, 6); Assert.assertEquals(keyedHistogram.getSnapshot().getMax(), 6); _metricsManager.createOrUpdateHistogram(CLASS_NAME, someKey, processLatency, 19); Histogram histogram = _metricsManager.getMetric(MetricRegistry.name(CLASS_NAME, someKey, processLatency)); Assert.assertEquals(histogram.getSnapshot().getMin(), 19); Assert.assertNotEquals(keyedHistogram, keylessHistogram); Assert.assertNotEquals(keyedHistogram, histogram); String anotherFullKeylessMetricName = MetricRegistry.name(CLASS_NAME, processLatency); _metricsManager.createOrUpdateHistogram(CLASS_NAME, processLatency, 11); Histogram anotherKeylessHistogram = _metricsManager.getMetric(anotherFullKeylessMetricName); Assert.assertEquals(anotherKeylessHistogram.getSnapshot().getMax(), 11); Assert.assertNotEquals(anotherKeylessHistogram, keylessHistogram); String anotherKey = "anotherKey"; String anotherFullKeyedMetricName = MetricRegistry.name(CLASS_NAME, anotherKey, processLatency); _metricsManager.createOrUpdateHistogram(CLASS_NAME, anotherKey, processLatency, 6); Histogram anotherKeyedHistogram = _metricsManager.getMetric(anotherFullKeyedMetricName); Assert.assertEquals(anotherKeyedHistogram.getSnapshot().getMin(), 6); Assert.assertNotEquals(anotherKeyedHistogram, keyedHistogram); Assert.assertTrue(_metricsManager.checkCache(CLASS_NAME, null, processLatency).isPresent()); _metricsManager.unregisterMetric(CLASS_NAME, processLatency); Assert.assertFalse(_metricsManager.checkCache(CLASS_NAME, null, processLatency).isPresent()); Assert.assertTrue(_metricsManager.checkCache(CLASS_NAME, anotherKey, processLatency).isPresent()); _metricsManager.unregisterMetric(CLASS_NAME, anotherKey, processLatency); Assert.assertFalse(_metricsManager.checkCache(CLASS_NAME, anotherKey, processLatency).isPresent()); Assert.assertTrue(_metricsManager.checkCache(CLASS_NAME, null, eventLatency).isPresent()); Assert.assertTrue(_metricsManager.checkCache(CLASS_NAME, someKey, eventLatency).isPresent()); }
public void createOrUpdateHistogram(String classSimpleName, String key, String metricName, long value) { validateArguments(classSimpleName, metricName); Histogram histogram = (Histogram) checkCache(classSimpleName, key, metricName).orElseGet(() -> { Histogram newHistogram = _metricRegistry.histogram(MetricRegistry.name(classSimpleName, key, metricName)); updateCache(classSimpleName, key, metricName, newHistogram); return newHistogram; }); histogram.update(value); }
DynamicMetricsManager { public void createOrUpdateHistogram(String classSimpleName, String key, String metricName, long value) { validateArguments(classSimpleName, metricName); Histogram histogram = (Histogram) checkCache(classSimpleName, key, metricName).orElseGet(() -> { Histogram newHistogram = _metricRegistry.histogram(MetricRegistry.name(classSimpleName, key, metricName)); updateCache(classSimpleName, key, metricName, newHistogram); return newHistogram; }); histogram.update(value); } }
DynamicMetricsManager { public void createOrUpdateHistogram(String classSimpleName, String key, String metricName, long value) { validateArguments(classSimpleName, metricName); Histogram histogram = (Histogram) checkCache(classSimpleName, key, metricName).orElseGet(() -> { Histogram newHistogram = _metricRegistry.histogram(MetricRegistry.name(classSimpleName, key, metricName)); updateCache(classSimpleName, key, metricName, newHistogram); return newHistogram; }); histogram.update(value); } private  DynamicMetricsManager(MetricRegistry metricRegistry); }
DynamicMetricsManager { public void createOrUpdateHistogram(String classSimpleName, String key, String metricName, long value) { validateArguments(classSimpleName, metricName); Histogram histogram = (Histogram) checkCache(classSimpleName, key, metricName).orElseGet(() -> { Histogram newHistogram = _metricRegistry.histogram(MetricRegistry.name(classSimpleName, key, metricName)); updateCache(classSimpleName, key, metricName, newHistogram); return newHistogram; }); histogram.update(value); } private  DynamicMetricsManager(MetricRegistry metricRegistry); static DynamicMetricsManager createInstance(MetricRegistry metricRegistry); static DynamicMetricsManager createInstance(MetricRegistry metricRegistry, @Nullable String testName); static DynamicMetricsManager getInstance(); @SuppressWarnings("unchecked") T registerMetric(String simpleName, String key, String metricName, Class<T> metricClass); T registerMetric(String classSimpleName, String metricName, Class<T> metricClass); @SuppressWarnings("unchecked") Gauge<T> registerGauge(String simpleName, String key, String metricName, Supplier<T> supplier); @SuppressWarnings("unchecked") Gauge<T> registerGauge(String simpleName, String metricName, Supplier<T> supplier); void unregisterMetric(String simpleName, String key, String metricName); void unregisterMetric(String simpleName, String metricName); void createOrUpdateCounter(String classSimpleName, String key, String metricName, long value); void createOrUpdateCounter(String classSimpleName, String metricName, long value); void createOrUpdateMeter(String classSimpleName, String key, String metricName, long value); void createOrUpdateMeter(String classSimpleName, String metricName, long value); void createOrUpdateSlidingWindowHistogram(String classSimpleName, String key, String metricName,
      long windowTimeMs, long value); void createOrUpdateHistogram(String classSimpleName, String key, String metricName, long value); void createOrUpdateHistogram(String classSimpleName, String metricName, long value); @SuppressWarnings("unchecked") T getMetric(String name); MetricRegistry getMetricRegistry(); }
DynamicMetricsManager { public void createOrUpdateHistogram(String classSimpleName, String key, String metricName, long value) { validateArguments(classSimpleName, metricName); Histogram histogram = (Histogram) checkCache(classSimpleName, key, metricName).orElseGet(() -> { Histogram newHistogram = _metricRegistry.histogram(MetricRegistry.name(classSimpleName, key, metricName)); updateCache(classSimpleName, key, metricName, newHistogram); return newHistogram; }); histogram.update(value); } private  DynamicMetricsManager(MetricRegistry metricRegistry); static DynamicMetricsManager createInstance(MetricRegistry metricRegistry); static DynamicMetricsManager createInstance(MetricRegistry metricRegistry, @Nullable String testName); static DynamicMetricsManager getInstance(); @SuppressWarnings("unchecked") T registerMetric(String simpleName, String key, String metricName, Class<T> metricClass); T registerMetric(String classSimpleName, String metricName, Class<T> metricClass); @SuppressWarnings("unchecked") Gauge<T> registerGauge(String simpleName, String key, String metricName, Supplier<T> supplier); @SuppressWarnings("unchecked") Gauge<T> registerGauge(String simpleName, String metricName, Supplier<T> supplier); void unregisterMetric(String simpleName, String key, String metricName); void unregisterMetric(String simpleName, String metricName); void createOrUpdateCounter(String classSimpleName, String key, String metricName, long value); void createOrUpdateCounter(String classSimpleName, String metricName, long value); void createOrUpdateMeter(String classSimpleName, String key, String metricName, long value); void createOrUpdateMeter(String classSimpleName, String metricName, long value); void createOrUpdateSlidingWindowHistogram(String classSimpleName, String key, String metricName,
      long windowTimeMs, long value); void createOrUpdateHistogram(String classSimpleName, String key, String metricName, long value); void createOrUpdateHistogram(String classSimpleName, String metricName, long value); @SuppressWarnings("unchecked") T getMetric(String name); MetricRegistry getMetricRegistry();  }