From a530d52d05699924ad09cfabe462e9f53c7b095d Mon Sep 17 00:00:00 2001 From: bvn13 Date: Tue, 17 Sep 2024 21:54:58 +0300 Subject: [PATCH] preparing springboot --- springboot/IgnoringActuatorLoggingFilter.java | 38 +++++++++++++++++++ springboot/logback-prod.xml | 11 ++++++ springboot.yaml => springboot/springboot.yaml | 0 3 files changed, 49 insertions(+) create mode 100644 springboot/IgnoringActuatorLoggingFilter.java create mode 100644 springboot/logback-prod.xml rename springboot.yaml => springboot/springboot.yaml (100%) diff --git a/springboot/IgnoringActuatorLoggingFilter.java b/springboot/IgnoringActuatorLoggingFilter.java new file mode 100644 index 0000000..4162979 --- /dev/null +++ b/springboot/IgnoringActuatorLoggingFilter.java @@ -0,0 +1,38 @@ +package me.bvn13.logging; + +import ch.qos.logback.classic.spi.ILoggingEvent; +import ch.qos.logback.core.filter.Filter; +import ch.qos.logback.core.spi.FilterReply; + +import java.util.HashSet; +import java.util.Set; +import java.util.regex.Pattern; + +public class IgnoringActuatorLoggingFilter extends Filter { + private static final Pattern ACTUATOR = + Pattern.compile("GET \"/(health|prometheus)\", parameters=\\{}"); + private static final Pattern COMPLETED = + Pattern.compile("Completed 200 OK"); + + private final Set activeThreads = new HashSet<>(); + + @Override + public FilterReply decide(ILoggingEvent loggingEvent) { + if (isHealthOrPrometheus(loggingEvent.getMessage())) { + activeThreads.add(loggingEvent.getThreadName()); + return FilterReply.DENY; + } else if (isCompleted200Ok(loggingEvent.getMessage()) && activeThreads.remove(loggingEvent.getThreadName())) { + return FilterReply.DENY; + } else { + return FilterReply.ACCEPT; + } + } + + private boolean isHealthOrPrometheus(String message) { + return ACTUATOR.matcher(message).matches(); + } + + private boolean isCompleted200Ok(String message) { + return COMPLETED.matcher(message).matches(); + } +} diff --git a/springboot/logback-prod.xml b/springboot/logback-prod.xml new file mode 100644 index 0000000..d633115 --- /dev/null +++ b/springboot/logback-prod.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/springboot.yaml b/springboot/springboot.yaml similarity index 100% rename from springboot.yaml rename to springboot/springboot.yaml