From b513809710f1f7c87dfaaa3fc4ef6e949232cae7 Mon Sep 17 00:00:00 2001 From: Viktor Lofgren Date: Fri, 14 Feb 2025 17:09:48 +0100 Subject: [PATCH] (*) Stopgap fix for metrics server initialization errors bringing down services --- .../service/server/MetricsServer.java | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/code/common/service/java/nu/marginalia/service/server/MetricsServer.java b/code/common/service/java/nu/marginalia/service/server/MetricsServer.java index d30b04e1..1c4a50b5 100644 --- a/code/common/service/java/nu/marginalia/service/server/MetricsServer.java +++ b/code/common/service/java/nu/marginalia/service/server/MetricsServer.java @@ -6,25 +6,34 @@ import nu.marginalia.service.module.ServiceConfiguration; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.net.InetSocketAddress; public class MetricsServer { + private static Logger logger = LoggerFactory.getLogger(MetricsServer.class); + @Inject - public MetricsServer(ServiceConfiguration configuration) throws Exception { + public MetricsServer(ServiceConfiguration configuration) { // If less than zero, we forego setting up a metrics server if (configuration.metricsPort() < 0) return; - Server server = new Server(new InetSocketAddress(configuration.bindAddress(), configuration.metricsPort())); + try { + Server server = new Server(new InetSocketAddress(configuration.bindAddress(), configuration.metricsPort())); - ServletContextHandler context = new ServletContextHandler(); - context.setContextPath("/"); - server.setHandler(context); + ServletContextHandler context = new ServletContextHandler(); + context.setContextPath("/"); + server.setHandler(context); - context.addServlet(new ServletHolder(new MetricsServlet()), "/metrics"); + context.addServlet(new ServletHolder(new MetricsServlet()), "/metrics"); - server.start(); + server.start(); + } + catch (Exception|NoSuchMethodError ex) { + logger.error("Failed to set up metrics server", ex); + } } }