FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix flaky DropWizardExportsTest · prometheus/client_java@fca49ff · GitHub

Commit fca49ff

Browse files
committed
Fix flaky DropWizardExportsTest
Signed-off-by: Fabian Stäber <fabian@fstab.de>
1 parent 96e4d5a commit fca49ff

1 file changed

Lines changed: 55 additions & 12 deletions

File tree

  • prometheus-metrics-instrumentation-dropwizard5/src/test/java/io/prometheus/metrics/instrumentation/dropwizard5

‎prometheus-metrics-instrumentation-dropwizard5/src/test/java/io/prometheus/metrics/instrumentation/dropwizard5/DropwizardExportsTest.java‎

Lines changed: 55 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
import io.dropwizard.metrics5.*;
44
import io.prometheus.metrics.expositionformats.OpenMetricsTextFormatWriter;
5-
import io.prometheus.metrics.instrumentation.dropwizard5.DropwizardExports;
65
import io.prometheus.metrics.model.registry.PrometheusRegistry;
6+
import io.prometheus.metrics.model.snapshots.MetricSnapshots;
7+
import io.prometheus.metrics.model.snapshots.Quantiles;
78
import io.prometheus.metrics.model.snapshots.SummarySnapshot;
9+
import org.junit.Assert;
810
import org.junit.Before;
911
import org.junit.Test;
1012

@@ -142,17 +144,58 @@ public void testHistogram() throws IOException {
142144
i += 1;
143145
}
144146

145-
String expected = "# TYPE hist summary\n" +
146-
"# HELP hist Generated from Dropwizard metric import (metric=hist, type=io.dropwizard.metrics5.Histogram)\n" +
147-
"hist{quantile=\"0.5\"} 49.0\n" +
148-
"hist{quantile=\"0.75\"} 74.0\n" +
149-
"hist{quantile=\"0.95\"} 94.0\n" +
150-
"hist{quantile=\"0.98\"} 97.0\n" +
151-
"hist{quantile=\"0.99\"} 98.0\n" +
152-
"hist{quantile=\"0.999\"} 99.0\n" +
153-
"hist_count 100\n" +
154-
"# EOF\n";
155-
assertEquals(expected, convertToOpenMetricsFormat(pmRegistry));
147+
// The result should look like this
148+
//
149+
// # TYPE hist summary
150+
// # HELP hist Generated from Dropwizard metric import (metric=hist, type=io.dropwizard.metrics5.Histogram)
151+
// hist{quantile="0.5"} 49.0
152+
// hist{quantile="0.75"} 74.0
153+
// hist{quantile="0.95"} 94.0
154+
// hist{quantile="0.98"} 97.0
155+
// hist{quantile="0.99"} 98.0
156+
// hist{quantile="0.999"} 99.0
157+
// hist_count 100
158+
// # EOF
159+
//
160+
// However, Dropwizard uses a random reservoir sampling algorithm, so the values could as well be off-by-one
161+
//
162+
// # TYPE hist summary
163+
// # HELP hist Generated from Dropwizard metric import (metric=hist, type=io.dropwizard.metrics5.Histogram)
164+
// hist{quantile="0.5"} 50.0
165+
// hist{quantile="0.75"} 75.0
166+
// hist{quantile="0.95"} 95.0
167+
// hist{quantile="0.98"} 98.0
168+
// hist{quantile="0.99"} 99.0
169+
// hist{quantile="0.999"} 99.0
170+
// hist_count 100
171+
// # EOF
172+
//
173+
// The following asserts the values, but allows an error of 1.0 for quantile values.
174+
175+
MetricSnapshots snapshots = pmRegistry.scrape(name -> name.equals("hist"));
176+
Assert.assertEquals(1, snapshots.size());
177+
SummarySnapshot snapshot = (SummarySnapshot) snapshots.get(0);
178+
Assert.assertEquals("hist", snapshot.getMetadata().getName());
179+
Assert.assertEquals("Generated from Dropwizard metric import (metric=hist, type=io.dropwizard.metrics5.Histogram)", snapshot.getMetadata().getHelp());
180+
Assert.assertEquals(1, snapshot.getDataPoints().size());
181+
SummarySnapshot.SummaryDataPointSnapshot dataPoint = snapshot.getDataPoints().get(0);
182+
Assert.assertTrue(dataPoint.hasCount());
183+
Assert.assertEquals(100, dataPoint.getCount());
184+
Assert.assertFalse(dataPoint.hasSum());
185+
Quantiles quantiles = dataPoint.getQuantiles();
186+
Assert.assertEquals(6, quantiles.size());
187+
Assert.assertEquals(0.5, quantiles.get(0).getQuantile(), 0.0);
188+
Assert.assertEquals(49.0, quantiles.get(0).getValue(), 1.0);
189+
Assert.assertEquals(0.75, quantiles.get(1).getQuantile(), 0.0);
190+
Assert.assertEquals(74.0, quantiles.get(1).getValue(), 1.0);
191+
Assert.assertEquals(0.95, quantiles.get(2).getQuantile(), 0.0);
192+
Assert.assertEquals(94.0, quantiles.get(2).getValue(), 1.0);
193+
Assert.assertEquals(0.98, quantiles.get(3).getQuantile(), 0.0);
194+
Assert.assertEquals(97.0, quantiles.get(3).getValue(), 1.0);
195+
Assert.assertEquals(0.99, quantiles.get(4).getQuantile(), 0.0);
196+
Assert.assertEquals(98.0, quantiles.get(4).getValue(), 1.0);
197+
Assert.assertEquals(0.999, quantiles.get(5).getQuantile(), 0.0);
198+
Assert.assertEquals(99.0, quantiles.get(5).getValue(), 1.0);
156199
}
157200

158201
@Test

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL