| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,9 +2,11 @@ | |||
| 2 | 2 | ||
| 3 | 3 | import io.dropwizard.metrics5.*; | |
| 4 | 4 | import io.prometheus.metrics.expositionformats.OpenMetricsTextFormatWriter; | |
| 5 | - import io.prometheus.metrics.instrumentation.dropwizard5.DropwizardExports; | ||
| 6 | 5 | import io.prometheus.metrics.model.registry.PrometheusRegistry; | |
| 6 | + import io.prometheus.metrics.model.snapshots.MetricSnapshots; | ||
| 7 | + import io.prometheus.metrics.model.snapshots.Quantiles; | ||
| 7 | 8 | import io.prometheus.metrics.model.snapshots.SummarySnapshot; | |
| 9 | + import org.junit.Assert; | ||
| 8 | 10 | import org.junit.Before; | |
| 9 | 11 | import org.junit.Test; | |
| 10 | 12 | ||
@@ -142,17 +144,58 @@ public void testHistogram() throws IOException { | |||
| 142 | 144 | i += 1; | |
| 143 | 145 | } | |
| 144 | 146 | ||
| 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); | ||
| 156 | 199 | } | |
| 157 | 200 | ||
| 158 | 201 | @Test | |
| Back | FazBrowse Home | New Git URL |
0 commit comments