From: David ‘Bombe’ Roden Date: Wed, 31 Jul 2019 11:54:00 +0000 (+0200) Subject: 🔊 Count errors on Sone inserts X-Git-Tag: v81^2~143 X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=commitdiff_plain;h=67c307faa434dff01362363ab896875b36e3d696 🔊 Count errors on Sone inserts --- diff --git a/src/main/java/net/pterodactylus/sone/core/SoneInserter.java b/src/main/java/net/pterodactylus/sone/core/SoneInserter.java index af180a0..e138f79 100644 --- a/src/main/java/net/pterodactylus/sone/core/SoneInserter.java +++ b/src/main/java/net/pterodactylus/sone/core/SoneInserter.java @@ -109,6 +109,7 @@ public class SoneInserter extends AbstractService { private final long delay; private final String soneId; private final Histogram soneInsertDurationHistogram; + private final Meter soneInsertErrorMeter; /** * Creates a new Sone inserter. @@ -151,6 +152,7 @@ public class SoneInserter extends AbstractService { this.eventBus = eventBus; this.freenetInterface = freenetInterface; this.soneInsertDurationHistogram = metricRegistry.histogram("sone.insert.duration"); + this.soneInsertErrorMeter = metricRegistry.meter("sone.insert.errors"); this.soneId = soneId; this.soneModificationDetector = soneModificationDetector; this.delay = delay; @@ -250,6 +252,7 @@ public class SoneInserter extends AbstractService { success = true; logger.log(Level.INFO, String.format("Inserted Sone “%s” at %s.", sone.getName(), finalUri)); } catch (SoneException se1) { + soneInsertErrorMeter.mark(); eventBus.post(new SoneInsertAbortedEvent(sone, se1)); logger.log(Level.WARNING, String.format("Could not insert Sone “%s”!", sone.getName()), se1); } finally { diff --git a/src/test/kotlin/net/pterodactylus/sone/core/SoneInserterTest.kt b/src/test/kotlin/net/pterodactylus/sone/core/SoneInserterTest.kt index d2bb3b4..8b061a7 100644 --- a/src/test/kotlin/net/pterodactylus/sone/core/SoneInserterTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/core/SoneInserterTest.kt @@ -258,7 +258,7 @@ class SoneInserterTest { } @Test - fun `unsuccessful insert does not update metrics`() { + fun `unsuccessful insert does not update histogram but records error`() { val insertUri = mock() createSone(insertUri) val soneModificationDetector = mock() @@ -271,6 +271,8 @@ class SoneInserterTest { soneInserter.serviceRun() val histogram = metricRegistry.histogram("sone.insert.duration") assertThat(histogram.count, equalTo(0L)) + val meter = metricRegistry.meter("sone.insert.errors") + assertThat(meter.count, equalTo(1L)) } }