Set the shutdown gauge earlier in the shutdown process

Co-authored-by: Chris Eager <79161849+eager-signal@users.noreply.github.com>
This commit is contained in:
ravi-signal 2024-04-02 09:39:55 -05:00 committed by GitHub
parent 796dce3cd3
commit bb0da69c9e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 9 deletions

View File

@ -8,16 +8,16 @@ package org.whispersystems.textsecuregcm.metrics;
import static com.codahale.metrics.MetricRegistry.name;
import io.dropwizard.lifecycle.Managed;
import io.micrometer.core.instrument.Gauge;
import io.micrometer.core.instrument.MeterRegistry;
import java.util.concurrent.atomic.AtomicBoolean;
import org.eclipse.jetty.util.component.LifeCycle;
/**
* A managed monitor that reports whether the application is shutting down as a metric. That metric can then be used in
* conjunction with other indicators to conditionally fire or suppress alerts.
*/
public class ApplicationShutdownMonitor implements Managed {
public class ApplicationShutdownMonitor implements LifeCycle.Listener {
private final AtomicBoolean shuttingDown = new AtomicBoolean(false);
@ -30,12 +30,7 @@ public class ApplicationShutdownMonitor implements Managed {
}
@Override
public void start() throws Exception {
shuttingDown.set(false);
}
@Override
public void stop() throws Exception {
public void lifeCycleStopping(final LifeCycle event) {
shuttingDown.set(true);
}
}

View File

@ -61,9 +61,9 @@ public class MetricsUtil {
Metrics.addRegistry(dogstatsdMeterRegistry);
}
environment.lifecycle().addEventListener(new ApplicationShutdownMonitor(Metrics.globalRegistry));
environment.lifecycle().addEventListener(
new MicrometerRegistryManager(Metrics.globalRegistry, config.getDatadogConfiguration().pollingFrequency()));
environment.lifecycle().manage(new ApplicationShutdownMonitor(Metrics.globalRegistry));
}
@VisibleForTesting