From e4dc2e2ffa64b1d744ccc81246eb047d796276e2 Mon Sep 17 00:00:00 2001 From: Matt Collins Date: Tue, 14 Mar 2023 09:26:13 +1100 Subject: [PATCH] Don't record metrics for 404s --- src/main/java/com/uid2/optout/Main.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/uid2/optout/Main.java b/src/main/java/com/uid2/optout/Main.java index d97b0af..47beee9 100644 --- a/src/main/java/com/uid2/optout/Main.java +++ b/src/main/java/com/uid2/optout/Main.java @@ -28,6 +28,7 @@ import io.vertx.core.http.HttpServerOptions; import io.vertx.core.http.impl.HttpUtils; import io.vertx.core.json.JsonObject; +import io.vertx.micrometer.MetricsDomain; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import io.vertx.micrometer.Label; @@ -41,10 +42,7 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.time.Instant; -import java.util.ArrayList; -import java.util.EnumSet; -import java.util.List; -import java.util.Optional; +import java.util.*; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Supplier; @@ -225,6 +223,10 @@ private static void setupMetrics(MicrometerMetricsOptions metricOptions) { return actualPath; } })) + // Don't record metrics for 404s. + .meterFilter(MeterFilter.deny(id -> + id.getName().startsWith(MetricsDomain.HTTP_SERVER.getPrefix()) && + Objects.equals(id.getTag(Label.HTTP_CODE.toString()), "404"))) // adding common labels .commonTags("application", "uid2-optout");