mirror of
https://github.com/google/nomulus.git
synced 2025-05-13 07:57:13 +02:00
Move metrics shutdown behavior to a ShutdownHook
HttpServlet#destroy() is not called on instance shutdown, so the metrics code was never shut down correctly before. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=156360866
This commit is contained in:
parent
25ff8c7490
commit
2b1ab579dc
2 changed files with 30 additions and 18 deletions
|
@ -14,6 +14,8 @@
|
|||
|
||||
package google.registry.module.frontend;
|
||||
|
||||
import com.google.appengine.api.LifecycleManager;
|
||||
import com.google.appengine.api.LifecycleManager.ShutdownHook;
|
||||
import google.registry.monitoring.metrics.MetricReporter;
|
||||
import google.registry.util.FormattingLogger;
|
||||
import java.io.IOException;
|
||||
|
@ -43,16 +45,20 @@ public final class FrontendServlet extends HttpServlet {
|
|||
} catch (TimeoutException timeoutException) {
|
||||
logger.severefmt("Failed to initialize MetricReporter: %s", timeoutException);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
try {
|
||||
metricReporter.stopAsync().awaitTerminated(10, TimeUnit.SECONDS);
|
||||
logger.info("Shut down MetricReporter");
|
||||
} catch (TimeoutException timeoutException) {
|
||||
logger.severefmt("Failed to stop MetricReporter: %s", timeoutException);
|
||||
}
|
||||
LifecycleManager.getInstance()
|
||||
.setShutdownHook(
|
||||
new ShutdownHook() {
|
||||
@Override
|
||||
public void shutdown() {
|
||||
try {
|
||||
metricReporter.stopAsync().awaitTerminated(10, TimeUnit.SECONDS);
|
||||
logger.info("Shut down MetricReporter");
|
||||
} catch (TimeoutException timeoutException) {
|
||||
logger.severefmt("Failed to stop MetricReporter: %s", timeoutException);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue