Skip to content

Commit

Permalink
adding metrics for server stopping
Browse files Browse the repository at this point in the history
  • Loading branch information
elopezcastro authored Sep 20, 2023
1 parent 046821b commit 7e4e72f
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -54,6 +55,7 @@
public abstract class BaseServer<T extends ServersConfiguration> extends Application<T>
{
private static final Logger LOGGER = org.slf4j.LoggerFactory.getLogger(BaseServer.class);
public static final String SERVER_STOPPED = "server-stopped";

AtomicBoolean ready = new AtomicBoolean(false);

Expand Down Expand Up @@ -131,6 +133,7 @@ protected Result check()
}
});


initialiseCors(environment);
initialisePrometheusMetrics(environment);
initialiseOpenTracing(environment);
Expand All @@ -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)
{
Expand All @@ -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);
}
});
}
Expand Down

0 comments on commit 7e4e72f

Please sign in to comment.