🔊 Count errors on Sone inserts
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 31 Jul 2019 11:54:00 +0000 (13:54 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 31 Jul 2019 11:54:00 +0000 (13:54 +0200)
src/main/java/net/pterodactylus/sone/core/SoneInserter.java
src/test/kotlin/net/pterodactylus/sone/core/SoneInserterTest.kt

index af180a0..e138f79 100644 (file)
@@ -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 {
index d2bb3b4..8b061a7 100644 (file)
@@ -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<FreenetURI>()
                createSone(insertUri)
                val soneModificationDetector = mock<SoneModificationDetector>()
@@ -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))
        }
 
 }