mirror of
https://github.com/google/nomulus
synced 2026-01-06 21:47:31 +00: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:
@@ -14,6 +14,8 @@
|
|||||||
|
|
||||||
package google.registry.module.backend;
|
package google.registry.module.backend;
|
||||||
|
|
||||||
|
import com.google.appengine.api.LifecycleManager;
|
||||||
|
import com.google.appengine.api.LifecycleManager.ShutdownHook;
|
||||||
import google.registry.monitoring.metrics.MetricReporter;
|
import google.registry.monitoring.metrics.MetricReporter;
|
||||||
import google.registry.util.FormattingLogger;
|
import google.registry.util.FormattingLogger;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -43,16 +45,20 @@ public final class BackendServlet extends HttpServlet {
|
|||||||
} catch (TimeoutException timeoutException) {
|
} catch (TimeoutException timeoutException) {
|
||||||
logger.severefmt("Failed to initialize MetricReporter: %s", timeoutException);
|
logger.severefmt("Failed to initialize MetricReporter: %s", timeoutException);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
LifecycleManager.getInstance()
|
||||||
public void destroy() {
|
.setShutdownHook(
|
||||||
try {
|
new ShutdownHook() {
|
||||||
metricReporter.stopAsync().awaitTerminated(10, TimeUnit.SECONDS);
|
@Override
|
||||||
logger.info("Shut down MetricReporter");
|
public void shutdown() {
|
||||||
} catch (TimeoutException timeoutException) {
|
try {
|
||||||
logger.severefmt("Failed to stop MetricReporter: %s", timeoutException);
|
metricReporter.stopAsync().awaitTerminated(10, TimeUnit.SECONDS);
|
||||||
}
|
logger.info("Shut down MetricReporter");
|
||||||
|
} catch (TimeoutException timeoutException) {
|
||||||
|
logger.severefmt("Failed to stop MetricReporter: %s", timeoutException);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -14,6 +14,8 @@
|
|||||||
|
|
||||||
package google.registry.module.frontend;
|
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.monitoring.metrics.MetricReporter;
|
||||||
import google.registry.util.FormattingLogger;
|
import google.registry.util.FormattingLogger;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -43,16 +45,20 @@ public final class FrontendServlet extends HttpServlet {
|
|||||||
} catch (TimeoutException timeoutException) {
|
} catch (TimeoutException timeoutException) {
|
||||||
logger.severefmt("Failed to initialize MetricReporter: %s", timeoutException);
|
logger.severefmt("Failed to initialize MetricReporter: %s", timeoutException);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
LifecycleManager.getInstance()
|
||||||
public void destroy() {
|
.setShutdownHook(
|
||||||
try {
|
new ShutdownHook() {
|
||||||
metricReporter.stopAsync().awaitTerminated(10, TimeUnit.SECONDS);
|
@Override
|
||||||
logger.info("Shut down MetricReporter");
|
public void shutdown() {
|
||||||
} catch (TimeoutException timeoutException) {
|
try {
|
||||||
logger.severefmt("Failed to stop MetricReporter: %s", timeoutException);
|
metricReporter.stopAsync().awaitTerminated(10, TimeUnit.SECONDS);
|
||||||
}
|
logger.info("Shut down MetricReporter");
|
||||||
|
} catch (TimeoutException timeoutException) {
|
||||||
|
logger.severefmt("Failed to stop MetricReporter: %s", timeoutException);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user