Skip to content

Commit 9975375

Browse files
committed
Update DropwizardExportsTest.java
Signed-off-by: Kinshuk Bairagi <[email protected]>
1 parent 3c302e1 commit 9975375

File tree

1 file changed

+100
-97
lines changed
  • prometheus-metrics-instrumentation-dropwizard/src/test/java/io/prometheus/metrics/instrumentation/dropwizard

1 file changed

+100
-97
lines changed

prometheus-metrics-instrumentation-dropwizard/src/test/java/io/prometheus/metrics/instrumentation/dropwizard/DropwizardExportsTest.java

Lines changed: 100 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import static org.assertj.core.api.Assertions.assertThat;
44
import static org.assertj.core.data.Offset.offset;
5-
import static org.junit.Assert.assertEquals;
6-
import static org.junit.Assert.assertTrue;
75

86
import com.codahale.metrics.*;
97
import io.prometheus.metrics.expositionformats.OpenMetricsTextFormatWriter;
@@ -26,17 +24,19 @@ class DropwizardExportsTest {
2624
@BeforeEach
2725
public void setUp() {
2826
metricRegistry = new MetricRegistry();
29-
io.prometheus.metrics.instrumentation.dropwizard.DropwizardExports.builder().dropwizardRegistry(metricRegistry).register(registry);
27+
io.prometheus.metrics.instrumentation.dropwizard.DropwizardExports.builder()
28+
.dropwizardRegistry(metricRegistry)
29+
.register(registry);
3030
}
3131

3232
@org.junit.jupiter.api.Test
3333
public void testCounter() {
3434
metricRegistry.counter("foo.bar").inc(1);
3535
String expected =
36-
"# TYPE foo_bar counter\n"
37-
+ "# HELP foo_bar Generated from Dropwizard metric import (metric=foo.bar, type=com.codahale.metrics.Counter)\n"
38-
+ "foo_bar_total 1.0\n"
39-
+ "# EOF\n";
36+
"# TYPE foo_bar counter\n"
37+
+ "# HELP foo_bar Generated from Dropwizard metric import (metric=foo.bar, type=com.codahale.metrics.Counter)\n"
38+
+ "foo_bar_total 1.0\n"
39+
+ "# EOF\n";
4040

4141
assertThat(convertToOpenMetricsFormat()).isEqualTo(expected);
4242
}
@@ -45,40 +45,40 @@ public void testCounter() {
4545
public void testGauge() {
4646
// don't convert to lambda, as we need to test the type
4747
Gauge<Integer> integerGauge =
48-
new Gauge<Integer>() {
49-
@Override
50-
public Integer getValue() {
51-
return 1234;
52-
}
53-
};
48+
new Gauge<Integer>() {
49+
@Override
50+
public Integer getValue() {
51+
return 1234;
52+
}
53+
};
5454
Gauge<Double> doubleGauge =
55-
new Gauge<Double>() {
56-
@Override
57-
public Double getValue() {
58-
return 1.234D;
59-
}
60-
};
55+
new Gauge<Double>() {
56+
@Override
57+
public Double getValue() {
58+
return 1.234D;
59+
}
60+
};
6161
Gauge<Long> longGauge =
62-
new Gauge<Long>() {
63-
@Override
64-
public Long getValue() {
65-
return 1234L;
66-
}
67-
};
62+
new Gauge<Long>() {
63+
@Override
64+
public Long getValue() {
65+
return 1234L;
66+
}
67+
};
6868
Gauge<Float> floatGauge =
69-
new Gauge<Float>() {
70-
@Override
71-
public Float getValue() {
72-
return 0.1234F;
73-
}
74-
};
69+
new Gauge<Float>() {
70+
@Override
71+
public Float getValue() {
72+
return 0.1234F;
73+
}
74+
};
7575
Gauge<Boolean> booleanGauge =
76-
new Gauge<Boolean>() {
77-
@Override
78-
public Boolean getValue() {
79-
return true;
80-
}
81-
};
76+
new Gauge<Boolean>() {
77+
@Override
78+
public Boolean getValue() {
79+
return true;
80+
}
81+
};
8282

8383
metricRegistry.register("double.gauge", doubleGauge);
8484
metricRegistry.register("long.gauge", longGauge);
@@ -87,22 +87,22 @@ public Boolean getValue() {
8787
metricRegistry.register("boolean.gauge", booleanGauge);
8888

8989
String expected =
90-
"# TYPE boolean_gauge gauge\n"
91-
+ "# HELP boolean_gauge Generated from Dropwizard metric import (metric=boolean.gauge, type=io.prometheus.metrics.instrumentation.dropwizard.DropwizardExportsTest$5)\n"
92-
+ "boolean_gauge 1.0\n"
93-
+ "# TYPE double_gauge gauge\n"
94-
+ "# HELP double_gauge Generated from Dropwizard metric import (metric=double.gauge, type=io.prometheus.metrics.instrumentation.dropwizard.DropwizardExportsTest$2)\n"
95-
+ "double_gauge 1.234\n"
96-
+ "# TYPE float_gauge gauge\n"
97-
+ "# HELP float_gauge Generated from Dropwizard metric import (metric=float.gauge, type=io.prometheus.metrics.instrumentation.dropwizard.DropwizardExportsTest$4)\n"
98-
+ "float_gauge 0.1234000027179718\n"
99-
+ "# TYPE integer_gauge gauge\n"
100-
+ "# HELP integer_gauge Generated from Dropwizard metric import (metric=integer.gauge, type=io.prometheus.metrics.instrumentation.dropwizard.DropwizardExportsTest$1)\n"
101-
+ "integer_gauge 1234.0\n"
102-
+ "# TYPE long_gauge gauge\n"
103-
+ "# HELP long_gauge Generated from Dropwizard metric import (metric=long.gauge, type=io.prometheus.metrics.instrumentation.dropwizard.DropwizardExportsTest$3)\n"
104-
+ "long_gauge 1234.0\n"
105-
+ "# EOF\n";
90+
"# TYPE boolean_gauge gauge\n"
91+
+ "# HELP boolean_gauge Generated from Dropwizard metric import (metric=boolean.gauge, type=io.prometheus.metrics.instrumentation.dropwizard.DropwizardExportsTest$5)\n"
92+
+ "boolean_gauge 1.0\n"
93+
+ "# TYPE double_gauge gauge\n"
94+
+ "# HELP double_gauge Generated from Dropwizard metric import (metric=double.gauge, type=io.prometheus.metrics.instrumentation.dropwizard.DropwizardExportsTest$2)\n"
95+
+ "double_gauge 1.234\n"
96+
+ "# TYPE float_gauge gauge\n"
97+
+ "# HELP float_gauge Generated from Dropwizard metric import (metric=float.gauge, type=io.prometheus.metrics.instrumentation.dropwizard.DropwizardExportsTest$4)\n"
98+
+ "float_gauge 0.1234000027179718\n"
99+
+ "# TYPE integer_gauge gauge\n"
100+
+ "# HELP integer_gauge Generated from Dropwizard metric import (metric=integer.gauge, type=io.prometheus.metrics.instrumentation.dropwizard.DropwizardExportsTest$1)\n"
101+
+ "integer_gauge 1234.0\n"
102+
+ "# TYPE long_gauge gauge\n"
103+
+ "# HELP long_gauge Generated from Dropwizard metric import (metric=long.gauge, type=io.prometheus.metrics.instrumentation.dropwizard.DropwizardExportsTest$3)\n"
104+
+ "long_gauge 1234.0\n"
105+
+ "# EOF\n";
106106

107107
assertThat(convertToOpenMetricsFormat()).isEqualTo(expected);
108108
}
@@ -130,7 +130,9 @@ public void testHistogram() {
130130
// just test the standard mapper
131131
final MetricRegistry metricRegistry = new MetricRegistry();
132132
PrometheusRegistry pmRegistry = new PrometheusRegistry();
133-
io.prometheus.metrics.instrumentation.dropwizard.DropwizardExports.builder().dropwizardRegistry(metricRegistry).register(pmRegistry);
133+
io.prometheus.metrics.instrumentation.dropwizard.DropwizardExports.builder()
134+
.dropwizardRegistry(metricRegistry)
135+
.register(pmRegistry);
134136

135137
Histogram hist = metricRegistry.histogram("hist");
136138
int i = 0;
@@ -175,8 +177,8 @@ public void testHistogram() {
175177
SummarySnapshot snapshot = (SummarySnapshot) snapshots.get(0);
176178
assertThat(snapshot.getMetadata().getName()).isEqualTo("hist");
177179
assertThat(snapshot.getMetadata().getHelp())
178-
.isEqualTo(
179-
"Generated from Dropwizard metric import (metric=hist, type=com.codahale.metrics.Histogram)");
180+
.isEqualTo(
181+
"Generated from Dropwizard metric import (metric=hist, type=com.codahale.metrics.Histogram)");
180182
assertThat(snapshot.getDataPoints().size()).isOne();
181183
SummarySnapshot.SummaryDataPointSnapshot dataPoint = snapshot.getDataPoints().get(0);
182184
assertThat(dataPoint.hasCount()).isTrue();
@@ -205,17 +207,18 @@ public void testMeter() {
205207
meter.mark();
206208

207209
String expected =
208-
"# TYPE meter counter\n"
209-
+ "# HELP meter Generated from Dropwizard metric import (metric=meter_total, type=com.codahale.metrics.Meter)\n"
210-
+ "meter_total 2.0\n"
211-
+ "# EOF\n";
210+
"# TYPE meter counter\n"
211+
+ "# HELP meter Generated from Dropwizard metric import (metric=meter_total, type=com.codahale.metrics.Meter)\n"
212+
+ "meter_total 2.0\n"
213+
+ "# EOF\n";
212214
assertThat(convertToOpenMetricsFormat()).isEqualTo(expected);
213215
}
214216

215217
@org.junit.jupiter.api.Test
216218
public void testTimer() throws InterruptedException {
217219
final MetricRegistry metricRegistry = new MetricRegistry();
218-
io.prometheus.metrics.instrumentation.dropwizard.DropwizardExports exports = new DropwizardExports(metricRegistry);
220+
io.prometheus.metrics.instrumentation.dropwizard.DropwizardExports exports =
221+
new DropwizardExports(metricRegistry);
219222
Timer t = metricRegistry.timer("timer");
220223
Timer.Context time = t.time();
221224
Thread.sleep(100L);
@@ -224,17 +227,17 @@ public void testTimer() throws InterruptedException {
224227
System.out.println(timeSpentMillis);
225228

226229
SummarySnapshot.SummaryDataPointSnapshot dataPointSnapshot =
227-
(SummarySnapshot.SummaryDataPointSnapshot)
228-
exports.collect().stream().flatMap(i -> i.getDataPoints().stream()).findFirst().get();
230+
(SummarySnapshot.SummaryDataPointSnapshot)
231+
exports.collect().stream().flatMap(i -> i.getDataPoints().stream()).findFirst().get();
229232
// We slept for 1Ms so we ensure that all timers are above 1ms:
230233
assertThat(dataPointSnapshot.getQuantiles().size()).isGreaterThan(1);
231234
dataPointSnapshot
232-
.getQuantiles()
233-
.forEach(
234-
i -> {
235-
System.out.println(i.getQuantile() + " : " + i.getValue());
236-
assertThat(i.getValue()).isGreaterThan(timeSpentMillis / 1000d);
237-
});
235+
.getQuantiles()
236+
.forEach(
237+
i -> {
238+
System.out.println(i.getQuantile() + " : " + i.getValue());
239+
assertThat(i.getValue()).isGreaterThan(timeSpentMillis / 1000d);
240+
});
238241
assertThat(dataPointSnapshot.getCount()).isOne();
239242
}
240243

@@ -248,34 +251,34 @@ public void testThatMetricHelpUsesOriginalDropwizardName() {
248251
metricRegistry.register("my.application.namedGauge1", new ExampleDoubleGauge());
249252

250253
String expected =
251-
"# TYPE my_application_namedCounter1 counter\n"
252-
+ "# HELP my_application_namedCounter1 Generated from Dropwizard metric import (metric=my.application.namedCounter1, type=com.codahale.metrics.Counter)\n"
253-
+ "my_application_namedCounter1_total 0.0\n"
254-
+ "# TYPE my_application_namedGauge1 gauge\n"
255-
+ "# HELP my_application_namedGauge1 Generated from Dropwizard metric import (metric=my.application.namedGauge1, type=io.prometheus.metrics.instrumentation.dropwizard.DropwizardExportsTest$ExampleDoubleGauge)\n"
256-
+ "my_application_namedGauge1 0.0\n"
257-
+ "# TYPE my_application_namedHistogram1 summary\n"
258-
+ "# HELP my_application_namedHistogram1 Generated from Dropwizard metric import (metric=my.application.namedHistogram1, type=com.codahale.metrics.Histogram)\n"
259-
+ "my_application_namedHistogram1{quantile=\"0.5\"} 0.0\n"
260-
+ "my_application_namedHistogram1{quantile=\"0.75\"} 0.0\n"
261-
+ "my_application_namedHistogram1{quantile=\"0.95\"} 0.0\n"
262-
+ "my_application_namedHistogram1{quantile=\"0.98\"} 0.0\n"
263-
+ "my_application_namedHistogram1{quantile=\"0.99\"} 0.0\n"
264-
+ "my_application_namedHistogram1{quantile=\"0.999\"} 0.0\n"
265-
+ "my_application_namedHistogram1_count 0\n"
266-
+ "# TYPE my_application_namedMeter1 counter\n"
267-
+ "# HELP my_application_namedMeter1 Generated from Dropwizard metric import (metric=my.application.namedMeter1_total, type=com.codahale.metrics.Meter)\n"
268-
+ "my_application_namedMeter1_total 0.0\n"
269-
+ "# TYPE my_application_namedTimer1 summary\n"
270-
+ "# HELP my_application_namedTimer1 Generated from Dropwizard metric import (metric=my.application.namedTimer1, type=com.codahale.metrics.Timer)\n"
271-
+ "my_application_namedTimer1{quantile=\"0.5\"} 0.0\n"
272-
+ "my_application_namedTimer1{quantile=\"0.75\"} 0.0\n"
273-
+ "my_application_namedTimer1{quantile=\"0.95\"} 0.0\n"
274-
+ "my_application_namedTimer1{quantile=\"0.98\"} 0.0\n"
275-
+ "my_application_namedTimer1{quantile=\"0.99\"} 0.0\n"
276-
+ "my_application_namedTimer1{quantile=\"0.999\"} 0.0\n"
277-
+ "my_application_namedTimer1_count 0\n"
278-
+ "# EOF\n";
254+
"# TYPE my_application_namedCounter1 counter\n"
255+
+ "# HELP my_application_namedCounter1 Generated from Dropwizard metric import (metric=my.application.namedCounter1, type=com.codahale.metrics.Counter)\n"
256+
+ "my_application_namedCounter1_total 0.0\n"
257+
+ "# TYPE my_application_namedGauge1 gauge\n"
258+
+ "# HELP my_application_namedGauge1 Generated from Dropwizard metric import (metric=my.application.namedGauge1, type=io.prometheus.metrics.instrumentation.dropwizard.DropwizardExportsTest$ExampleDoubleGauge)\n"
259+
+ "my_application_namedGauge1 0.0\n"
260+
+ "# TYPE my_application_namedHistogram1 summary\n"
261+
+ "# HELP my_application_namedHistogram1 Generated from Dropwizard metric import (metric=my.application.namedHistogram1, type=com.codahale.metrics.Histogram)\n"
262+
+ "my_application_namedHistogram1{quantile=\"0.5\"} 0.0\n"
263+
+ "my_application_namedHistogram1{quantile=\"0.75\"} 0.0\n"
264+
+ "my_application_namedHistogram1{quantile=\"0.95\"} 0.0\n"
265+
+ "my_application_namedHistogram1{quantile=\"0.98\"} 0.0\n"
266+
+ "my_application_namedHistogram1{quantile=\"0.99\"} 0.0\n"
267+
+ "my_application_namedHistogram1{quantile=\"0.999\"} 0.0\n"
268+
+ "my_application_namedHistogram1_count 0\n"
269+
+ "# TYPE my_application_namedMeter1 counter\n"
270+
+ "# HELP my_application_namedMeter1 Generated from Dropwizard metric import (metric=my.application.namedMeter1_total, type=com.codahale.metrics.Meter)\n"
271+
+ "my_application_namedMeter1_total 0.0\n"
272+
+ "# TYPE my_application_namedTimer1 summary\n"
273+
+ "# HELP my_application_namedTimer1 Generated from Dropwizard metric import (metric=my.application.namedTimer1, type=com.codahale.metrics.Timer)\n"
274+
+ "my_application_namedTimer1{quantile=\"0.5\"} 0.0\n"
275+
+ "my_application_namedTimer1{quantile=\"0.75\"} 0.0\n"
276+
+ "my_application_namedTimer1{quantile=\"0.95\"} 0.0\n"
277+
+ "my_application_namedTimer1{quantile=\"0.98\"} 0.0\n"
278+
+ "my_application_namedTimer1{quantile=\"0.99\"} 0.0\n"
279+
+ "my_application_namedTimer1{quantile=\"0.999\"} 0.0\n"
280+
+ "my_application_namedTimer1_count 0\n"
281+
+ "# EOF\n";
279282
assertThat(convertToOpenMetricsFormat()).isEqualTo(expected);
280283
}
281284

0 commit comments

Comments
 (0)