@Test public void shouldNotConvertMetricNamesWhenNoConverterIsProvided() { metricAdapterFactory = new MetricAdapterFactoryImpl(metricDescriptorLookup); assertThat(getFirstMonitorable(metricAdapterFactory.createMetricAdapterFor(NAME, counter)).getName(), is(NAME)); }
@Override @SuppressWarnings("unchecked") public MetricAdapter createMetricAdapterFor(String originalMetricName, Metric metric) { Preconditions.checkArgument(!(metric instanceof MetricSet), "Metric Sets cannot be adapted!!"); String translatedName = translate(originalMetricName); MetricDescriptor descriptor = metricDescriptorLookup.getDescriptorFor(translatedName); if (metric instanceof Timer) { return new TimerAdapter((Timer) metric, translatedName, descriptor.getDescription()); } if (metric instanceof Histogram) { return new HistogramAdapter((Histogram) metric, translatedName, descriptor.getDescription(), descriptor.getUnit()); } if (metric instanceof Counter) { return new CountingAdapter((Counter) metric, translatedName, descriptor.getDescription(), descriptor.getSemantics()); } if (metric instanceof Gauge) { return new GaugeAdapter<>((Gauge) metric, translatedName, descriptor.getDescription(), descriptor.getUnit(), descriptor.getSemantics()); } if (metric instanceof Metered) { return new MeteredAdapter((Metered) metric, translatedName, descriptor.getDescription()); } throw new UnsupportedOperationException(String.format("Unable to produce a monitorable adapter for metrics of class %s (%s)", metric.getClass().getName(), originalMetricName)); }
MetricAdapterFactoryImpl implements MetricAdapterFactory { @Override @SuppressWarnings("unchecked") public MetricAdapter createMetricAdapterFor(String originalMetricName, Metric metric) { Preconditions.checkArgument(!(metric instanceof MetricSet), "Metric Sets cannot be adapted!!"); String translatedName = translate(originalMetricName); MetricDescriptor descriptor = metricDescriptorLookup.getDescriptorFor(translatedName); if (metric instanceof Timer) { return new TimerAdapter((Timer) metric, translatedName, descriptor.getDescription()); } if (metric instanceof Histogram) { return new HistogramAdapter((Histogram) metric, translatedName, descriptor.getDescription(), descriptor.getUnit()); } if (metric instanceof Counter) { return new CountingAdapter((Counter) metric, translatedName, descriptor.getDescription(), descriptor.getSemantics()); } if (metric instanceof Gauge) { return new GaugeAdapter<>((Gauge) metric, translatedName, descriptor.getDescription(), descriptor.getUnit(), descriptor.getSemantics()); } if (metric instanceof Metered) { return new MeteredAdapter((Metered) metric, translatedName, descriptor.getDescription()); } throw new UnsupportedOperationException(String.format("Unable to produce a monitorable adapter for metrics of class %s (%s)", metric.getClass().getName(), originalMetricName)); } }
MetricAdapterFactoryImpl implements MetricAdapterFactory { @Override @SuppressWarnings("unchecked") public MetricAdapter createMetricAdapterFor(String originalMetricName, Metric metric) { Preconditions.checkArgument(!(metric instanceof MetricSet), "Metric Sets cannot be adapted!!"); String translatedName = translate(originalMetricName); MetricDescriptor descriptor = metricDescriptorLookup.getDescriptorFor(translatedName); if (metric instanceof Timer) { return new TimerAdapter((Timer) metric, translatedName, descriptor.getDescription()); } if (metric instanceof Histogram) { return new HistogramAdapter((Histogram) metric, translatedName, descriptor.getDescription(), descriptor.getUnit()); } if (metric instanceof Counter) { return new CountingAdapter((Counter) metric, translatedName, descriptor.getDescription(), descriptor.getSemantics()); } if (metric instanceof Gauge) { return new GaugeAdapter<>((Gauge) metric, translatedName, descriptor.getDescription(), descriptor.getUnit(), descriptor.getSemantics()); } if (metric instanceof Metered) { return new MeteredAdapter((Metered) metric, translatedName, descriptor.getDescription()); } throw new UnsupportedOperationException(String.format("Unable to produce a monitorable adapter for metrics of class %s (%s)", metric.getClass().getName(), originalMetricName)); } MetricAdapterFactoryImpl(MetricDescriptorLookup metricDescriptorLookup, MetricNameTranslator metricNameTranslator);  MetricAdapterFactoryImpl(MetricDescriptorLookup metricDescriptorLookup); }
MetricAdapterFactoryImpl implements MetricAdapterFactory { @Override @SuppressWarnings("unchecked") public MetricAdapter createMetricAdapterFor(String originalMetricName, Metric metric) { Preconditions.checkArgument(!(metric instanceof MetricSet), "Metric Sets cannot be adapted!!"); String translatedName = translate(originalMetricName); MetricDescriptor descriptor = metricDescriptorLookup.getDescriptorFor(translatedName); if (metric instanceof Timer) { return new TimerAdapter((Timer) metric, translatedName, descriptor.getDescription()); } if (metric instanceof Histogram) { return new HistogramAdapter((Histogram) metric, translatedName, descriptor.getDescription(), descriptor.getUnit()); } if (metric instanceof Counter) { return new CountingAdapter((Counter) metric, translatedName, descriptor.getDescription(), descriptor.getSemantics()); } if (metric instanceof Gauge) { return new GaugeAdapter<>((Gauge) metric, translatedName, descriptor.getDescription(), descriptor.getUnit(), descriptor.getSemantics()); } if (metric instanceof Metered) { return new MeteredAdapter((Metered) metric, translatedName, descriptor.getDescription()); } throw new UnsupportedOperationException(String.format("Unable to produce a monitorable adapter for metrics of class %s (%s)", metric.getClass().getName(), originalMetricName)); } MetricAdapterFactoryImpl(MetricDescriptorLookup metricDescriptorLookup, MetricNameTranslator metricNameTranslator);  MetricAdapterFactoryImpl(MetricDescriptorLookup metricDescriptorLookup); @Override @SuppressWarnings("unchecked") MetricAdapter createMetricAdapterFor(String originalMetricName, Metric metric); }
MetricAdapterFactoryImpl implements MetricAdapterFactory { @Override @SuppressWarnings("unchecked") public MetricAdapter createMetricAdapterFor(String originalMetricName, Metric metric) { Preconditions.checkArgument(!(metric instanceof MetricSet), "Metric Sets cannot be adapted!!"); String translatedName = translate(originalMetricName); MetricDescriptor descriptor = metricDescriptorLookup.getDescriptorFor(translatedName); if (metric instanceof Timer) { return new TimerAdapter((Timer) metric, translatedName, descriptor.getDescription()); } if (metric instanceof Histogram) { return new HistogramAdapter((Histogram) metric, translatedName, descriptor.getDescription(), descriptor.getUnit()); } if (metric instanceof Counter) { return new CountingAdapter((Counter) metric, translatedName, descriptor.getDescription(), descriptor.getSemantics()); } if (metric instanceof Gauge) { return new GaugeAdapter<>((Gauge) metric, translatedName, descriptor.getDescription(), descriptor.getUnit(), descriptor.getSemantics()); } if (metric instanceof Metered) { return new MeteredAdapter((Metered) metric, translatedName, descriptor.getDescription()); } throw new UnsupportedOperationException(String.format("Unable to produce a monitorable adapter for metrics of class %s (%s)", metric.getClass().getName(), originalMetricName)); } MetricAdapterFactoryImpl(MetricDescriptorLookup metricDescriptorLookup, MetricNameTranslator metricNameTranslator);  MetricAdapterFactoryImpl(MetricDescriptorLookup metricDescriptorLookup); @Override @SuppressWarnings("unchecked") MetricAdapter createMetricAdapterFor(String originalMetricName, Metric metric);  }