From: David ‘Bombe’ Roden Date: Tue, 30 Jul 2019 07:59:17 +0000 (+0200) Subject: 🐛 Fix metrics page showing wrong event count X-Git-Tag: v81^2~159 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=7aa1997cc7aed40c12017c417ece3e03815e1d28;p=Sone.git 🐛 Fix metrics page showing wrong event count --- diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/MetricsPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/MetricsPage.kt index 041e755..e097daf 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/MetricsPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/MetricsPage.kt @@ -13,17 +13,19 @@ import javax.inject.* class MetricsPage @Inject constructor(webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer, private val metricsRegistry: MetricRegistry) : SoneTemplatePage(webInterface, loaders, templateRenderer, "Page.Metrics.Title") { override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) { - metricsRegistry.histogram("sone.parsing.duration").snapshot.also { snapshot -> - templateContext["soneParsingDurationCount"] = snapshot.size() - templateContext["soneParsingDurationMin"] = snapshot.min - templateContext["soneParsingDurationMax"] = snapshot.max - templateContext["soneParsingDurationMedian"] = snapshot.median - templateContext["soneParsingDurationMean"] = snapshot.mean - templateContext["soneParsingDurationPercentile75"] = snapshot.get75thPercentile() - templateContext["soneParsingDurationPercentile95"] = snapshot.get95thPercentile() - templateContext["soneParsingDurationPercentile98"] = snapshot.get98thPercentile() - templateContext["soneParsingDurationPercentile99"] = snapshot.get99thPercentile() - templateContext["soneParsingDurationPercentile999"] = snapshot.get999thPercentile() + metricsRegistry.histogram("sone.parsing.duration").also { histogram -> + templateContext["soneParsingDurationCount"] = histogram.count + histogram.snapshot.also { snapshot -> + templateContext["soneParsingDurationMin"] = snapshot.min + templateContext["soneParsingDurationMax"] = snapshot.max + templateContext["soneParsingDurationMedian"] = snapshot.median + templateContext["soneParsingDurationMean"] = snapshot.mean + templateContext["soneParsingDurationPercentile75"] = snapshot.get75thPercentile() + templateContext["soneParsingDurationPercentile95"] = snapshot.get95thPercentile() + templateContext["soneParsingDurationPercentile98"] = snapshot.get98thPercentile() + templateContext["soneParsingDurationPercentile99"] = snapshot.get99thPercentile() + templateContext["soneParsingDurationPercentile999"] = snapshot.get999thPercentile() + } } } diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/MetricsPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/MetricsPageTest.kt index 0565612..b727909 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/MetricsPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/MetricsPageTest.kt @@ -68,8 +68,16 @@ class MetricsPageTest : WebPageTest() { verifyHistogram("soneParsingDuration") } + @Test + fun `metrics page delivers correct histogram size`() { + val histogram = metricRegistry.histogram("sone.parsing.duration") + (0..4000).forEach(histogram::update) + page.handleRequest(soneRequest, templateContext) + assertThat(templateContext["soneParsingDurationCount"] as Long, equalTo(4001L)) + } + private fun verifyHistogram(name: String) { - assertThat(templateContext["${name}Count"] as Int, equalTo(5)) + assertThat(templateContext["${name}Count"] as Long, equalTo(5L)) assertThat(templateContext["${name}Min"] as Long, equalTo(1L)) assertThat(templateContext["${name}Max"] as Long, equalTo(10L)) assertThat(templateContext["${name}Median"] as Double, equalTo(8.0))