2424 * converting Dropwizard metrics to Prometheus metrics. Subclasses only need to implement {@link
2525 * #collectMetricSnapshots()} to handle version-specific registry APIs.
2626 *
27- * @param <TRegistry > The Dropwizard MetricRegistry type
28- * @param <TFilter > The Dropwizard MetricFilter type
29- * @param <TCounter > The Dropwizard Counter type
30- * @param <TGauge > The Dropwizard Gauge type
31- * @param <THistogram > The Dropwizard Histogram type
32- * @param <TTimer > The Dropwizard Timer type
33- * @param <TMeter > The Dropwizard Meter type
34- * @param <TMetric > The Dropwizard Metric base type
35- * @param <TSnapshot > The Dropwizard Snapshot type
27+ * @param <R > The Dropwizard MetricRegistry type
28+ * @param <F > The Dropwizard MetricFilter type
29+ * @param <C > The Dropwizard Counter type
30+ * @param <G > The Dropwizard Gauge type
31+ * @param <H > The Dropwizard Histogram type
32+ * @param <T > The Dropwizard Timer type
33+ * @param <M > The Dropwizard Meter type
34+ * @param <B > The Dropwizard Metric base type
35+ * @param <S > The Dropwizard Snapshot type
3636 */
37- public abstract class AbstractDropwizardExports <
38- TRegistry , TFilter , TCounter , TGauge , THistogram , TTimer , TMeter , TMetric , TSnapshot >
37+ public abstract class AbstractDropwizardExports <R , F , C , G , H , T , M , B , S >
3938 implements MultiCollector {
4039
4140 private static final Logger logger = Logger .getLogger (AbstractDropwizardExports .class .getName ());
4241
43- protected final TRegistry registry ;
44- protected final TFilter metricFilter ;
42+ protected final R registry ;
43+ protected final F metricFilter ;
4544 @ Nullable protected final CustomLabelMapper labelMapper ;
4645 protected final InvalidMetricHandler invalidMetricHandler ;
4746
4847 protected AbstractDropwizardExports (
49- TRegistry registry ,
50- TFilter metricFilter ,
48+ R registry ,
49+ F metricFilter ,
5150 @ Nullable CustomLabelMapper labelMapper ,
5251 InvalidMetricHandler invalidMetricHandler ) {
5352 this .registry = registry ;
@@ -62,7 +61,7 @@ protected static String getHelpMessage(String metricName, Object metric) {
6261 metricName , metric .getClass ().getName ());
6362 }
6463
65- protected MetricMetadata getMetricMetaData (String metricName , TMetric metric ) {
64+ protected MetricMetadata getMetricMetaData (String metricName , B metric ) {
6665 String name = labelMapper != null ? labelMapper .getName (metricName ) : metricName ;
6766 return new MetricMetadata (
6867 PrometheusNaming .sanitizeMetricName (name ), getHelpMessage (metricName , metric ));
@@ -73,9 +72,9 @@ protected MetricMetadata getMetricMetaData(String metricName, TMetric metric) {
7372 * href="https://prometheus.io/docs/concepts/metric_types/#gauge">Gauge</a>.
7473 */
7574 @ SuppressWarnings ("unchecked" )
76- protected MetricSnapshot fromCounter (String dropwizardName , TCounter counter ) {
75+ protected MetricSnapshot fromCounter (String dropwizardName , C counter ) {
7776 long count = getCounterCount (counter );
78- MetricMetadata metadata = getMetricMetaData (dropwizardName , (TMetric ) counter );
77+ MetricMetadata metadata = getMetricMetaData (dropwizardName , (B ) counter );
7978 CounterSnapshot .CounterDataPointSnapshot .Builder dataPointBuilder =
8079 CounterSnapshot .CounterDataPointSnapshot .builder ().value (Long .valueOf (count ).doubleValue ());
8180 if (labelMapper != null ) {
@@ -88,7 +87,7 @@ protected MetricSnapshot fromCounter(String dropwizardName, TCounter counter) {
8887 /** Export gauge as a prometheus gauge. */
8988 @ SuppressWarnings ("unchecked" )
9089 @ Nullable
91- protected MetricSnapshot fromGauge (String dropwizardName , TGauge gauge ) {
90+ protected MetricSnapshot fromGauge (String dropwizardName , G gauge ) {
9291 Object obj = getGaugeValue (gauge );
9392 double value ;
9493 if (obj instanceof Number ) {
@@ -104,7 +103,7 @@ protected MetricSnapshot fromGauge(String dropwizardName, TGauge gauge) {
104103 obj == null ? "null" : obj .getClass ().getName ()));
105104 return null ;
106105 }
107- MetricMetadata metadata = getMetricMetaData (dropwizardName , (TMetric ) gauge );
106+ MetricMetadata metadata = getMetricMetaData (dropwizardName , (B ) gauge );
108107 GaugeSnapshot .GaugeDataPointSnapshot .Builder dataPointBuilder =
109108 GaugeSnapshot .GaugeDataPointSnapshot .builder ().value (value );
110109 if (labelMapper != null ) {
@@ -123,7 +122,7 @@ protected MetricSnapshot fromGauge(String dropwizardName, TGauge gauge) {
123122 * @param factor a factor to apply to histogram values.
124123 */
125124 protected MetricSnapshot fromSnapshotAndCount (
126- String dropwizardName , TSnapshot snapshot , long count , double factor , String helpMessage ) {
125+ String dropwizardName , S snapshot , long count , double factor , String helpMessage ) {
127126 Quantiles quantiles =
128127 Quantiles .builder ()
129128 .quantile (0.5 , getMedian (snapshot ) * factor )
@@ -147,16 +146,16 @@ protected MetricSnapshot fromSnapshotAndCount(
147146 }
148147
149148 /** Convert histogram snapshot. */
150- protected MetricSnapshot fromHistogram (String dropwizardName , THistogram histogram ) {
151- TSnapshot snapshot = getHistogramSnapshot (histogram );
149+ protected MetricSnapshot fromHistogram (String dropwizardName , H histogram ) {
150+ S snapshot = getHistogramSnapshot (histogram );
152151 long count = getHistogramCount (histogram );
153152 return fromSnapshotAndCount (
154153 dropwizardName , snapshot , count , 1.0 , getHelpMessage (dropwizardName , histogram ));
155154 }
156155
157156 /** Export Dropwizard Timer as a histogram. Use TIME_UNIT as time unit. */
158- protected MetricSnapshot fromTimer (String dropwizardName , TTimer timer ) {
159- TSnapshot snapshot = getTimerSnapshot (timer );
157+ protected MetricSnapshot fromTimer (String dropwizardName , T timer ) {
158+ S snapshot = getTimerSnapshot (timer );
160159 long count = getTimerCount (timer );
161160 return fromSnapshotAndCount (
162161 dropwizardName ,
@@ -168,8 +167,8 @@ protected MetricSnapshot fromTimer(String dropwizardName, TTimer timer) {
168167
169168 /** Export a Meter as a prometheus COUNTER. */
170169 @ SuppressWarnings ("unchecked" )
171- protected MetricSnapshot fromMeter (String dropwizardName , TMeter meter ) {
172- MetricMetadata metadata = getMetricMetaData (dropwizardName + "_total" , (TMetric ) meter );
170+ protected MetricSnapshot fromMeter (String dropwizardName , M meter ) {
171+ MetricMetadata metadata = getMetricMetaData (dropwizardName + "_total" , (B ) meter );
173172 CounterSnapshot .CounterDataPointSnapshot .Builder dataPointBuilder =
174173 CounterSnapshot .CounterDataPointSnapshot .builder ().value (getMeterCount (meter ));
175174 if (labelMapper != null ) {
@@ -209,29 +208,29 @@ protected <K, V> void collectMetricKind(
209208 /** Collect all metric snapshots from the registry. */
210209 protected abstract MetricSnapshots collectMetricSnapshots ();
211210
212- protected abstract long getCounterCount (TCounter counter );
211+ protected abstract long getCounterCount (C counter );
213212
214- protected abstract Object getGaugeValue (TGauge gauge );
213+ protected abstract Object getGaugeValue (G gauge );
215214
216- protected abstract TSnapshot getHistogramSnapshot (THistogram histogram );
215+ protected abstract S getHistogramSnapshot (H histogram );
217216
218- protected abstract long getHistogramCount (THistogram histogram );
217+ protected abstract long getHistogramCount (H histogram );
219218
220- protected abstract TSnapshot getTimerSnapshot (TTimer timer );
219+ protected abstract S getTimerSnapshot (T timer );
221220
222- protected abstract long getTimerCount (TTimer timer );
221+ protected abstract long getTimerCount (T timer );
223222
224- protected abstract long getMeterCount (TMeter meter );
223+ protected abstract long getMeterCount (M meter );
225224
226- protected abstract double getMedian (TSnapshot snapshot );
225+ protected abstract double getMedian (S snapshot );
227226
228- protected abstract double get75thPercentile (TSnapshot snapshot );
227+ protected abstract double get75thPercentile (S snapshot );
229228
230- protected abstract double get95thPercentile (TSnapshot snapshot );
229+ protected abstract double get95thPercentile (S snapshot );
231230
232- protected abstract double get98thPercentile (TSnapshot snapshot );
231+ protected abstract double get98thPercentile (S snapshot );
233232
234- protected abstract double get99thPercentile (TSnapshot snapshot );
233+ protected abstract double get99thPercentile (S snapshot );
235234
236- protected abstract double get999thPercentile (TSnapshot snapshot );
235+ protected abstract double get999thPercentile (S snapshot );
237236}
0 commit comments