class MetricsHttpService implements MetricsService {

  @Override
  public CompletableFuture<?> start() {
    LOG.info("Starting metrics http service on {}:{}", config.getHost(), config.getPort());
    // Create the HTTP server and a router object.
    httpServer =
        vertx.createHttpServer(
            new HttpServerOptions().setHost(config.getHost()).setPort(config.getPort()));

    final Router router = Router.router(vertx);

    // Verify Host header.
    router.route().handler(checkAllowlistHostHeader());

    // Endpoint for AWS health check.
    router.route("/").method(HttpMethod.GET).handler(this::handleEmptyRequest);

    // Endpoint for Prometheus metrics monitoring.
    router.route("/metrics").method(HttpMethod.GET).handler(this::metricsRequest);

    final CompletableFuture<?> resultFuture = new CompletableFuture<>();
    httpServer
        .requestHandler(router)
        .listen(
            res -> {
              if (!res.failed()) {
                resultFuture.complete(null);
                final int actualPort = httpServer.actualPort();
                config.setActualPort(actualPort);
                LOG.info(
                    "Metrics service started and listening on {}:{}",
                    actualPort,
                    httpServer.actualPort());
                return;
              }
              httpServer = null;
              final Throwable cause = res.cause();
              if (cause instanceof SocketException) {
                resultFuture.completeExceptionally(
                    new RuntimeException(
                        String.format(
                            "Failed to bind metrics listener to %s:%s (actual port %s): %s",
                            config.getHost(),
                            config.getPort(),
                            config.getActualPort(),
                            cause.getMessage())));
                return;
              }
              resultFuture.completeExceptionally(cause);
            });
    return resultFuture;
  }

    MetricsHttpService(
      final Vertx vertx,
      final MetricsConfiguration configuration,
      final MetricsSystem metricsSystem);

}