Add a shutdown monitor that publishes shutdown state as a metric
This commit is contained in:
		
							parent
							
								
									758900b7a8
								
							
						
					
					
						commit
						ce7d687205
					
				| 
						 | 
					@ -113,6 +113,7 @@ import org.whispersystems.textsecuregcm.mappers.RateLimitChallengeExceptionMappe
 | 
				
			||||||
import org.whispersystems.textsecuregcm.mappers.RateLimitExceededExceptionMapper;
 | 
					import org.whispersystems.textsecuregcm.mappers.RateLimitExceededExceptionMapper;
 | 
				
			||||||
import org.whispersystems.textsecuregcm.mappers.RetryLaterExceptionMapper;
 | 
					import org.whispersystems.textsecuregcm.mappers.RetryLaterExceptionMapper;
 | 
				
			||||||
import org.whispersystems.textsecuregcm.mappers.ServerRejectedExceptionMapper;
 | 
					import org.whispersystems.textsecuregcm.mappers.ServerRejectedExceptionMapper;
 | 
				
			||||||
 | 
					import org.whispersystems.textsecuregcm.metrics.ApplicationShutdownMonitor;
 | 
				
			||||||
import org.whispersystems.textsecuregcm.metrics.BufferPoolGauges;
 | 
					import org.whispersystems.textsecuregcm.metrics.BufferPoolGauges;
 | 
				
			||||||
import org.whispersystems.textsecuregcm.metrics.CpuUsageGauge;
 | 
					import org.whispersystems.textsecuregcm.metrics.CpuUsageGauge;
 | 
				
			||||||
import org.whispersystems.textsecuregcm.metrics.FileDescriptorGauge;
 | 
					import org.whispersystems.textsecuregcm.metrics.FileDescriptorGauge;
 | 
				
			||||||
| 
						 | 
					@ -506,6 +507,7 @@ public class WhisperServerService extends Application<WhisperServerConfiguration
 | 
				
			||||||
    MigrationRetryAccountsTableCrawler migrationRetryAccountsTableCrawler = new MigrationRetryAccountsTableCrawler(migrationRetryAccounts, accountsManager, accountsDynamoDb, cacheCluster, recurringJobExecutor);
 | 
					    MigrationRetryAccountsTableCrawler migrationRetryAccountsTableCrawler = new MigrationRetryAccountsTableCrawler(migrationRetryAccounts, accountsManager, accountsDynamoDb, cacheCluster, recurringJobExecutor);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    apnSender.setApnFallbackManager(apnFallbackManager);
 | 
					    apnSender.setApnFallbackManager(apnFallbackManager);
 | 
				
			||||||
 | 
					    environment.lifecycle().manage(new ApplicationShutdownMonitor());
 | 
				
			||||||
    environment.lifecycle().manage(apnFallbackManager);
 | 
					    environment.lifecycle().manage(apnFallbackManager);
 | 
				
			||||||
    environment.lifecycle().manage(pubSubManager);
 | 
					    environment.lifecycle().manage(pubSubManager);
 | 
				
			||||||
    environment.lifecycle().manage(messageSender);
 | 
					    environment.lifecycle().manage(messageSender);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,35 @@
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Copyright 2013-2021 Signal Messenger, LLC
 | 
				
			||||||
 | 
					 * SPDX-License-Identifier: AGPL-3.0-only
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					package org.whispersystems.textsecuregcm.metrics;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import io.dropwizard.lifecycle.Managed;
 | 
				
			||||||
 | 
					import io.micrometer.core.instrument.Metrics;
 | 
				
			||||||
 | 
					import java.util.concurrent.atomic.AtomicBoolean;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import static com.codahale.metrics.MetricRegistry.name;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * 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 {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  private final AtomicBoolean shuttingDown = new AtomicBoolean(false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  public ApplicationShutdownMonitor() {
 | 
				
			||||||
 | 
					    Metrics.gauge(name(getClass().getSimpleName(), "shuttingDown"), shuttingDown, b -> b.get() ? 1 : 0);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @Override
 | 
				
			||||||
 | 
					  public void start() throws Exception {
 | 
				
			||||||
 | 
					    shuttingDown.set(false);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @Override
 | 
				
			||||||
 | 
					  public void stop() throws Exception {
 | 
				
			||||||
 | 
					    shuttingDown.set(true);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
		Reference in New Issue