Skip to content

Commit

Permalink
Set the shutdown gauge earlier in the shutdown process
Browse files Browse the repository at this point in the history
Co-authored-by: Chris Eager <[email protected]>
  • Loading branch information
ravi-signal and eager-signal committed Apr 2, 2024
1 parent 796dce3 commit bb0da69
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@

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);

Expand All @@ -30,12 +30,7 @@ public ApplicationShutdownMonitor(final MeterRegistry meterRegistry) {
}

@Override
public void start() throws Exception {
shuttingDown.set(false);
}

@Override
public void stop() throws Exception {
public void lifeCycleStopping(final LifeCycle event) {
shuttingDown.set(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ public static void configureRegistries(final WhisperServerConfiguration config,
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
Expand Down

0 comments on commit bb0da69

Please sign in to comment.