From: David ‘Bombe’ Roden Date: Wed, 20 Nov 2019 20:55:09 +0000 (+0100) Subject: 🐛 Fix wrong size of histogram displayed X-Git-Tag: v81^2~28 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=e1013489a9f9906f339095f178f6dc7ef4ea5e0d;p=Sone.git 🐛 Fix wrong size of histogram displayed --- diff --git a/src/main/kotlin/net/pterodactylus/sone/template/HistogramRenderer.kt b/src/main/kotlin/net/pterodactylus/sone/template/HistogramRenderer.kt index 6816135..dba32b2 100644 --- a/src/main/kotlin/net/pterodactylus/sone/template/HistogramRenderer.kt +++ b/src/main/kotlin/net/pterodactylus/sone/template/HistogramRenderer.kt @@ -12,7 +12,7 @@ class HistogramRenderer : Filter { override fun format(templateContext: TemplateContext, data: Any?, parameters: Map?): Any? { templateContext["metricName"] = (parameters?.get("name") as String?)?.dotToCamel()?.let { "Page.Metrics.$it.Title" } (data as? Histogram)?.snapshot?.run { - templateContext["count"] = size() + templateContext["count"] = data.count templateContext["min"] = min templateContext["max"] = max templateContext["mean"] = mean diff --git a/src/test/kotlin/net/pterodactylus/sone/template/HistogramRendererTest.kt b/src/test/kotlin/net/pterodactylus/sone/template/HistogramRendererTest.kt index 592c3ef..cc450d6 100644 --- a/src/test/kotlin/net/pterodactylus/sone/template/HistogramRendererTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/template/HistogramRendererTest.kt @@ -72,7 +72,7 @@ class HistogramRendererTest { @Test fun `second column contains count`() { createAndVerifyTableRow { - assertThat(it.getElementsByTag("td")[1].text(), equalTo("1001")) + assertThat(it.getElementsByTag("td")[1].text(), equalTo("2001")) } } @@ -84,7 +84,7 @@ class HistogramRendererTest { @Test fun `third column contains min value`() { createAndVerifyTableRow { - assertThat(it.getElementsByTag("td")[2].text(), equalTo("3.4ms")) + assertThat(it.getElementsByTag("td")[2].text(), equalTo("2.0ms")) } } @@ -96,7 +96,7 @@ class HistogramRendererTest { @Test fun `fourth column contains max value`() { createAndVerifyTableRow { - assertThat(it.getElementsByTag("td")[3].text(), equalTo("998.9ms")) + assertThat(it.getElementsByTag("td")[3].text(), equalTo("998.0ms")) } } @@ -108,7 +108,7 @@ class HistogramRendererTest { @Test fun `fifth column contains mean value`() { createAndVerifyTableRow { - assertThat(it.getElementsByTag("td")[4].text(), equalTo("503.4ms")) + assertThat(it.getElementsByTag("td")[4].text(), equalTo("492.7ms")) } } @@ -120,7 +120,7 @@ class HistogramRendererTest { @Test fun `sixth column contains median value`() { createAndVerifyTableRow { - assertThat(it.getElementsByTag("td")[5].text(), equalTo("501.0ms")) + assertThat(it.getElementsByTag("td")[5].text(), equalTo("483.6ms")) } } @@ -132,7 +132,7 @@ class HistogramRendererTest { @Test fun `seventh column contains 75th percentile`() { createAndVerifyTableRow { - assertThat(it.getElementsByTag("td")[6].text(), equalTo("757.8ms")) + assertThat(it.getElementsByTag("td")[6].text(), equalTo("740.9ms")) } } @@ -144,7 +144,7 @@ class HistogramRendererTest { @Test fun `eighth column contains 95th percentile`() { createAndVerifyTableRow { - assertThat(it.getElementsByTag("td")[7].text(), equalTo("948.6ms")) + assertThat(it.getElementsByTag("td")[7].text(), equalTo("940.9ms")) } } @@ -156,7 +156,7 @@ class HistogramRendererTest { @Test fun `ninth column contains 98th percentile`() { createAndVerifyTableRow { - assertThat(it.getElementsByTag("td")[8].text(), equalTo("972.7ms")) + assertThat(it.getElementsByTag("td")[8].text(), equalTo("975.6ms")) } } @@ -168,7 +168,7 @@ class HistogramRendererTest { @Test fun `tenth column contains 99th percentile`() { createAndVerifyTableRow { - assertThat(it.getElementsByTag("td")[9].text(), equalTo("986.4ms")) + assertThat(it.getElementsByTag("td")[9].text(), equalTo("991.6ms")) } } @@ -180,7 +180,7 @@ class HistogramRendererTest { @Test fun `eleventh column contains 99,9th percentile`() { createAndVerifyTableRow { - assertThat(it.getElementsByTag("td")[10].text(), equalTo("998.5ms")) + assertThat(it.getElementsByTag("td")[10].text(), equalTo("998.0ms")) } } @@ -199,6 +199,6 @@ class HistogramRendererTest { } private val random = Random(1) -private val histogram = MetricRegistry().histogram("test.histogram").apply { - (0..1000).map { random.nextInt(1_000_000) }.forEach(this::update) +private val histogram = MetricRegistry().histogram("test.histogram") { Histogram(SlidingWindowReservoir(1028)) }.apply { + (0..2000).map { random.nextInt(1_000_000) }.forEach(this::update) }