Skip to content

Commit 9fda943

Browse files
committed
Update DropwizardExportsTest.java
Signed-off-by: Kinshuk Bairagi <[email protected]>
1 parent 529676e commit 9fda943

File tree

1 file changed

+30
-57
lines changed
  • prometheus-metrics-instrumentation-dropwizard/src/test/java/io/prometheus/metrics/instrumentation/dropwizard

1 file changed

+30
-57
lines changed

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

Lines changed: 30 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@
33
import static org.assertj.core.api.Assertions.assertThat;
44
import static org.assertj.core.api.Assertions.assertThatCode;
55
import static org.assertj.core.api.Assertions.assertThatThrownBy;
6-
import static org.assertj.core.data.Offset.offset;
76

87
import com.codahale.metrics.*;
98
import io.prometheus.metrics.expositionformats.OpenMetricsTextFormatWriter;
109
import io.prometheus.metrics.model.registry.PrometheusRegistry;
11-
import io.prometheus.metrics.model.snapshots.MetricSnapshots;
12-
import io.prometheus.metrics.model.snapshots.Quantiles;
1310
import io.prometheus.metrics.model.snapshots.SummarySnapshot;
1411
import java.io.ByteArrayOutputStream;
1512
import java.io.IOException;
@@ -159,62 +156,38 @@ public void testHistogram() {
159156
}
160157

161158
// The result should look like this
162-
//
163-
// # TYPE hist summary
164-
// # HELP hist Generated from Dropwizard metric import (metric=hist,
165-
// type=com.codahale.metrics.Histogram)
166-
// hist{quantile="0.5"} 49.0
167-
// hist{quantile="0.75"} 74.0
168-
// hist{quantile="0.95"} 94.0
169-
// hist{quantile="0.98"} 97.0
170-
// hist{quantile="0.99"} 98.0
171-
// hist{quantile="0.999"} 99.0
172-
// hist_count 100
173-
// # EOF
174-
//
159+
String expected1 =
160+
"# TYPE hist summary\n"
161+
+ "# HELP hist Generated from Dropwizard metric import (metric=hist, type=com.codahale.metrics.Histogram)\n"
162+
+ "hist{quantile=\"0.5\"} 49.0\n"
163+
+ "hist{quantile=\"0.75\"} 74.0\n"
164+
+ "hist{quantile=\"0.95\"} 94.0\n"
165+
+ "hist{quantile=\"0.98\"} 97.0\n"
166+
+ "hist{quantile=\"0.99\"} 98.0\n"
167+
+ "hist{quantile=\"0.999\"} 99.0\n"
168+
+ "hist_count 100\n"
169+
+ "# EOF\n";
170+
175171
// However, Dropwizard uses a random reservoir sampling algorithm, so the values could as well
176172
// be off-by-one
177-
//
178-
// # TYPE hist summary
179-
// # HELP hist Generated from Dropwizard metric import (metric=hist,
180-
// type=com.codahale.metrics.Histogram)
181-
// hist{quantile="0.5"} 50.0
182-
// hist{quantile="0.75"} 75.0
183-
// hist{quantile="0.95"} 95.0
184-
// hist{quantile="0.98"} 98.0
185-
// hist{quantile="0.99"} 99.0
186-
// hist{quantile="0.999"} 99.0
187-
// hist_count 100
188-
// # EOF
189-
//
190-
// The following asserts the values, but allows an error of 1.0 for quantile values.
191-
192-
MetricSnapshots snapshots = pmRegistry.scrape(name -> name.equals("hist"));
193-
assertThat(snapshots.size()).isOne();
194-
SummarySnapshot snapshot = (SummarySnapshot) snapshots.get(0);
195-
assertThat(snapshot.getMetadata().getName()).isEqualTo("hist");
196-
assertThat(snapshot.getMetadata().getHelp())
197-
.isEqualTo(
198-
"Generated from Dropwizard metric import (metric=hist, type=com.codahale.metrics.Histogram)");
199-
assertThat(snapshot.getDataPoints().size()).isOne();
200-
SummarySnapshot.SummaryDataPointSnapshot dataPoint = snapshot.getDataPoints().get(0);
201-
assertThat(dataPoint.hasCount()).isTrue();
202-
assertThat(dataPoint.getCount()).isEqualTo(100);
203-
assertThat(dataPoint.hasSum()).isFalse();
204-
Quantiles quantiles = dataPoint.getQuantiles();
205-
assertThat(quantiles.size()).isEqualTo(6);
206-
assertThat(quantiles.get(0).getQuantile()).isEqualTo(0.5);
207-
assertThat(quantiles.get(0).getValue()).isCloseTo(49.0, offset(1.0));
208-
assertThat(quantiles.get(1).getQuantile()).isEqualTo(0.75);
209-
assertThat(quantiles.get(1).getValue()).isCloseTo(74.0, offset(1.0));
210-
assertThat(quantiles.get(2).getQuantile()).isEqualTo(0.95);
211-
assertThat(quantiles.get(2).getValue()).isCloseTo(94.0, offset(1.0));
212-
assertThat(quantiles.get(3).getQuantile()).isEqualTo(0.98);
213-
assertThat(quantiles.get(3).getValue()).isCloseTo(97.0, offset(1.0));
214-
assertThat(quantiles.get(4).getQuantile()).isEqualTo(0.99);
215-
assertThat(quantiles.get(4).getValue()).isCloseTo(98.0, offset(1.0));
216-
assertThat(quantiles.get(5).getQuantile()).isEqualTo(0.999);
217-
assertThat(quantiles.get(5).getValue()).isCloseTo(99.0, offset(1.0));
173+
String expected2 =
174+
"# TYPE hist summary\n"
175+
+ "# HELP hist Generated from Dropwizard metric import (metric=hist, type=com.codahale.metrics.Histogram)\n"
176+
+ "hist{quantile=\"0.5\"} 50.0\n"
177+
+ "hist{quantile=\"0.75\"} 75.0\n"
178+
+ "hist{quantile=\"0.95\"} 95.0\n"
179+
+ "hist{quantile=\"0.98\"} 98.0\n"
180+
+ "hist{quantile=\"0.99\"} 99.0\n"
181+
+ "hist{quantile=\"0.999\"} 99.0\n"
182+
+ "hist_count 100\n"
183+
+ "# EOF\n";
184+
185+
// The following asserts the values matches either of the expected value.
186+
String textFormat = convertToOpenMetricsFormat(pmRegistry);
187+
assertThat(textFormat)
188+
.satisfiesAnyOf(
189+
text -> assertThat(text).isEqualTo(expected1),
190+
text -> assertThat(text).isEqualTo(expected2));
218191
}
219192

220193
@Test

0 commit comments

Comments
 (0)