mirror of
https://github.com/google/nomulus.git
synced 2025-05-13 16:07:15 +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.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,10 +45,12 @@ 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);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
LifecycleManager.getInstance()
|
||||||
|
.setShutdownHook(
|
||||||
|
new ShutdownHook() {
|
||||||
@Override
|
@Override
|
||||||
public void destroy() {
|
public void shutdown() {
|
||||||
try {
|
try {
|
||||||
metricReporter.stopAsync().awaitTerminated(10, TimeUnit.SECONDS);
|
metricReporter.stopAsync().awaitTerminated(10, TimeUnit.SECONDS);
|
||||||
logger.info("Shut down MetricReporter");
|
logger.info("Shut down MetricReporter");
|
||||||
|
@ -54,6 +58,8 @@ public final class BackendServlet extends HttpServlet {
|
||||||
logger.severefmt("Failed to stop MetricReporter: %s", timeoutException);
|
logger.severefmt("Failed to stop MetricReporter: %s", timeoutException);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void service(HttpServletRequest req, HttpServletResponse rsp) throws IOException {
|
public void service(HttpServletRequest req, HttpServletResponse rsp) throws IOException {
|
||||||
|
|
|
@ -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,10 +45,12 @@ 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);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
LifecycleManager.getInstance()
|
||||||
|
.setShutdownHook(
|
||||||
|
new ShutdownHook() {
|
||||||
@Override
|
@Override
|
||||||
public void destroy() {
|
public void shutdown() {
|
||||||
try {
|
try {
|
||||||
metricReporter.stopAsync().awaitTerminated(10, TimeUnit.SECONDS);
|
metricReporter.stopAsync().awaitTerminated(10, TimeUnit.SECONDS);
|
||||||
logger.info("Shut down MetricReporter");
|
logger.info("Shut down MetricReporter");
|
||||||
|
@ -54,6 +58,8 @@ public final class FrontendServlet extends HttpServlet {
|
||||||
logger.severefmt("Failed to stop MetricReporter: %s", timeoutException);
|
logger.severefmt("Failed to stop MetricReporter: %s", timeoutException);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void service(HttpServletRequest req, HttpServletResponse rsp) throws IOException {
|
public void service(HttpServletRequest req, HttpServletResponse rsp) throws IOException {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue