/** * Starts Prometheus HTTP endpoint on which Prometheus may scrape the data. */ private void startKamonPrometheusHttpEndpoint(final ActorSystem actorSystem) { if (configReader.metrics().isPrometheusEnabled() && prometheusReporter != null) { final ActorMaterializer materializer = createActorMaterializer(actorSystem); final Route prometheusReporterRoute = PrometheusReporterRoute .buildPrometheusReporterRoute(prometheusReporter); final CompletionStage<ServerBinding> binding = Http.get(actorSystem) .bindAndHandle(prometheusReporterRoute.flow(actorSystem, materializer), ConnectHttp.toHost(configReader.metrics().getPrometheusHostname(), configReader.metrics().getPrometheusPort()), materializer); binding.thenAccept(theBinding -> CoordinatedShutdown.get(actorSystem).addTask( CoordinatedShutdown.PhaseServiceUnbind(), "shutdown_prometheus_http_endpoint", () -> { logger.info("Gracefully shutting down Prometheus HTTP endpoint.."); // prometheus requests don't get the luxury of being processed a long time after shutdown: return theBinding.terminate(Duration.ofSeconds(1)) .handle((httpTerminated, e) -> Done.getInstance()); }) ).exceptionally(failure -> { logger.error("Kamon Prometheus HTTP endpoint could not be started: {}", failure.getMessage(), failure); logger.error("Terminating actorSystem!"); actorSystem.terminate(); return null; }); } }
/** * Starts Prometheus HTTP endpoint on which Prometheus may scrape the data. */ private void startKamonPrometheusHttpEndpoint(final ActorSystem actorSystem) { if (configReader.metrics().isPrometheusEnabled() && prometheusReporter != null) { final ActorMaterializer materializer = createActorMaterializer(actorSystem); final Route prometheusReporterRoute = PrometheusReporterRoute .buildPrometheusReporterRoute(prometheusReporter); final CompletionStage<ServerBinding> binding = Http.get(actorSystem) .bindAndHandle(prometheusReporterRoute.flow(actorSystem, materializer), ConnectHttp.toHost(configReader.metrics().getPrometheusHostname(), configReader.metrics().getPrometheusPort()), materializer); binding.thenAccept(theBinding -> CoordinatedShutdown.get(actorSystem).addTask( CoordinatedShutdown.PhaseServiceUnbind(), "shutdown_prometheus_http_endpoint", () -> { logger.info("Gracefully shutting down Prometheus HTTP endpoint.."); // prometheus requests don't get the luxury of being processed a long time after shutdown: return theBinding.terminate(Duration.ofSeconds(1)) .handle((httpTerminated, e) -> Done.getInstance()); }) ).exceptionally(failure -> { logger.error("Kamon Prometheus HTTP endpoint could not be started: {}", failure.getMessage(), failure); logger.error("Terminating actorSystem!"); actorSystem.terminate(); return null; }); } }
private void bindHttpStatusRoute(final ActorRef healthCheckingActor, final HttpConfigReader httpConfig, final ActorMaterializer materializer) { String hostname = httpConfig.getHostname(); if (hostname.isEmpty()) { hostname = ConfigUtil.getLocalHostAddress(); log.info("No explicit hostname configured, using HTTP hostname: {}", hostname); } final CompletionStage<ServerBinding> binding = Http.get(getContext().system()) .bindAndHandle(createRoute(getContext().system(), healthCheckingActor).flow(getContext().system(), materializer), ConnectHttp.toHost(hostname, httpConfig.getPort()), materializer); binding.thenAccept(theBinding -> CoordinatedShutdown.get(getContext().getSystem()).addTask( CoordinatedShutdown.PhaseServiceUnbind(), "shutdown_health_http_endpoint", () -> { log.info("Gracefully shutting down status/health HTTP endpoint.."); return theBinding.terminate(Duration.ofSeconds(1)) .handle((httpTerminated, e) -> Done.getInstance()); }) ).exceptionally(failure -> { log.error(failure, "Something very bad happened: {}", failure.getMessage()); getContext().system().terminate(); return null; }); }
private void createHealthCheckingActorHttpBinding(final HttpConfigReader httpConfig, final ActorRef healthCheckingActor, final ActorMaterializer materializer) { String hostname = httpConfig.getHostname(); if (hostname.isEmpty()) { hostname = ConfigUtil.getLocalHostAddress(); log.info("No explicit hostname configured, using HTTP hostname: {}", hostname); } final CompletionStage<ServerBinding> binding = Http.get(getContext().system()) // .bindAndHandle( createRoute(getContext().system(), healthCheckingActor).flow(getContext().system(), materializer), ConnectHttp.toHost(hostname, httpConfig.getPort()), materializer); binding.thenAccept(theBinding -> CoordinatedShutdown.get(getContext().getSystem()).addTask( CoordinatedShutdown.PhaseServiceUnbind(), "shutdown_health_http_endpoint", () -> { log.info("Gracefully shutting down status/health HTTP endpoint.."); return theBinding.terminate(Duration.ofSeconds(1)) .handle((httpTerminated, e) -> Done.getInstance()); }) ).exceptionally(failure -> { log.error(failure, "Something very bad happened: {}", failure.getMessage()); getContext().system().terminate(); return null; }); }
CoordinatedShutdown.PhaseServiceUnbind(), "shutdown_http_endpoint", () -> { log.info("Gracefully shutting down user HTTP endpoint.."); return theBinding.terminate(Duration.ofSeconds(10)) .handle((httpTerminated, e) -> Done.getInstance()); });
CoordinatedShutdown.PhaseServiceUnbind(), "shutdown_health_http_endpoint", () -> { log.info("Gracefully shutting down status/health HTTP endpoint.."); return theBinding.terminate(Duration.ofSeconds(1)) .handle((httpTerminated, e) -> Done.getInstance()); })
CoordinatedShutdown.PhaseServiceUnbind(), "shutdown_health_http_endpoint", () -> { log.info("Gracefully shutting down status/health HTTP endpoint.."); return theBinding.terminate(Duration.ofSeconds(1)) .handle((httpTerminated, e) -> Done.getInstance()); })
CoordinatedShutdown.PhaseServiceUnbind(), "shutdown_health_http_endpoint", () -> { log.info("Gracefully shutting down status/health HTTP endpoint.."); return theBinding.terminate(Duration.ofSeconds(1)) .handle((httpTerminated, e) -> Done.getInstance()); })