From 7e4e72ff26648eae5c1b1d99a93ac465682230ff Mon Sep 17 00:00:00 2001 From: elopezcastro <82950460+elopezcastro@users.noreply.github.com> Date: Wed, 20 Sep 2023 16:03:43 +0200 Subject: [PATCH] adding metrics for server stopping --- .../java/org/finos/legend/depot/core/http/BaseServer.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/legend-depot-servers-common/src/main/java/org/finos/legend/depot/core/http/BaseServer.java b/legend-depot-servers-common/src/main/java/org/finos/legend/depot/core/http/BaseServer.java index 5231e2089..37518bcbc 100644 --- a/legend-depot-servers-common/src/main/java/org/finos/legend/depot/core/http/BaseServer.java +++ b/legend-depot-servers-common/src/main/java/org/finos/legend/depot/core/http/BaseServer.java @@ -37,6 +37,7 @@ import org.finos.legend.depot.store.StorageConfiguration; import org.finos.legend.depot.tracing.configuration.PrometheusMetricsProviderConfiguration; import org.finos.legend.depot.tracing.configuration.TracingAuthenticationProviderConfiguration; +import org.finos.legend.depot.tracing.services.prometheus.PrometheusMetricsFactory; import org.finos.legend.sdlc.server.error.LegendSDLCServerExceptionMapper; import org.finos.legend.server.pac4j.LegendPac4jBundle; import org.finos.legend.server.shared.bundles.ChainFixingFilterHandler; @@ -54,6 +55,7 @@ public abstract class BaseServer extends Application { private static final Logger LOGGER = org.slf4j.LoggerFactory.getLogger(BaseServer.class); + public static final String SERVER_STOPPED = "server-stopped"; AtomicBoolean ready = new AtomicBoolean(false); @@ -131,6 +133,7 @@ protected Result check() } }); + initialiseCors(environment); initialisePrometheusMetrics(environment); initialiseOpenTracing(environment); @@ -142,6 +145,7 @@ private void registerLifeCycleListener(T configuration, Environment environment) { environment.lifecycle().addLifeCycleListener(new LifeCycle.Listener() { + private long shutDownStartTime = 0L; @Override public void lifeCycleStarting(LifeCycle event) { @@ -166,12 +170,14 @@ public void lifeCycleFailure(LifeCycle event, Throwable cause) public void lifeCycleStopping(LifeCycle event) { LOGGER.info("Stopping {}", configuration.getApplicationName()); + shutDownStartTime = System.currentTimeMillis(); } @Override public void lifeCycleStopped(LifeCycle event) { - LOGGER.info("Stopped {}", configuration.getApplicationName()); + LOGGER.info("Stopped {} in {} ", configuration.getApplicationName(), System.currentTimeMillis() - shutDownStartTime); + PrometheusMetricsFactory.getInstance().incrementCount(SERVER_STOPPED); } }); }