Skip to content

Commit

Permalink
Merge pull request #955 from mberndt123/start-server-on-executor
Browse files Browse the repository at this point in the history
Start Prometheus HTTP server on the provided executor
  • Loading branch information
dhoard committed May 8, 2024
2 parents 058b399 + bc479bc commit 6ca57ac
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public static void main(String[] args) throws IOException, InterruptedException
.buildAndStart();

System.out.println("HTTPServer listening on port http://localhost:" + server.getPort() + "/metrics");
Thread.sleep(10_000);
}

private static int parsePortOrExit(String port) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
import com.sun.net.httpserver.HttpServer;
import com.sun.net.httpserver.HttpsConfigurator;
import com.sun.net.httpserver.HttpsServer;
import io.prometheus.metrics.config.ExporterHttpServerProperties;
import io.prometheus.metrics.config.PrometheusProperties;
import io.prometheus.metrics.model.registry.PrometheusRegistry;

import java.io.Closeable;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.SynchronousQueue;
Expand Down Expand Up @@ -55,7 +55,14 @@ private HTTPServer(PrometheusProperties config, ExecutorService executorService,
registerHandler("/", defaultHandler == null ? new DefaultHandler() : defaultHandler, authenticator);
registerHandler("/metrics", new MetricsHandler(config, registry), authenticator);
registerHandler("/-/healthy", new HealthyHandler(), authenticator);
this.server.start();
try {
executorService.submit(() -> this.server.start()).get();
// calling .get() on the Future here to avoid silently discarding errors
} catch (InterruptedException e) {
throw new RuntimeException(e);
} catch (ExecutionException e) {
throw new RuntimeException(e);
}
}

private void registerHandler(String path, HttpHandler handler, Authenticator authenticator) {
Expand Down

0 comments on commit 6ca57ac

Please sign in to comment.