-
Notifications
You must be signed in to change notification settings - Fork 804
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Start Prometheus HTTP server on the provided executor #955
Conversation
The metrics HTTP server should run on a daemon JVM thread so as to not keep the JVM running even though all relevant threads have already exited. Unfortunately, the OpenJDK builtin HTTP server likes to spawn its own HTTP Dispatcher thread on startup. https://github.com/openjdk/jdk/blob/02c95a6d7eb77ed17ae64d0f585197e87a67cc4a/src/jdk.httpserver/share/classes/sun/net/httpserver/ServerImpl.java#L190 This new thread inherits the daemon flag from the thread that started it, therefore we need to call the start method from the executor service, because those threads are daemon threads. Signed-off-by: Matthias Berndt <matthias.berndt@ttmzero.com>
Signed-off-by: Matthias Berndt <matthias.berndt@ttmzero.com>
OK, here's the thing. This change is working exactly as intended and prevents Prometheus from spawning non-Daemon threads. In the tests however, this Prometheus thread is the only non-Daemon thread other than the main thread, and the main thread exits right after starting the Prometheus HTTP server, leading to the termination of the program before the tests can complete. There are probably programs out there that run everything in daemon threads, the only thing keeping their JVM alive being the Prometheus HTTP server, and so this change would break their program. |
I feel this is a good change - the application should be responsible for preventing the application from exiting and shouldn't rely on If this PR causes test issues/failures in We could add a
|
Thanks you for your encouraging remarks @dhoard. Regarding the |
The thought was if someone wanted the
|
Oh, I see what you mean now. I think such functionality is beyond the scope of the library and it doesn't really save much code anyway. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor changes.
...-exporter-httpserver/src/main/java/io/prometheus/metrics/exporter/httpserver/HTTPServer.java
Outdated
Show resolved
Hide resolved
...-exporter-httpserver/src/main/java/io/prometheus/metrics/exporter/httpserver/HTTPServer.java
Show resolved
Hide resolved
Signed-off-by: Matthias Berndt <matthias.berndt@ttmzero.com>
Signed-off-by: Matthias Berndt <matthias.berndt@ttmzero.com>
@mberndt123 Thanks for the PR! |
The metrics HTTP server should run on a daemon JVM
thread so as to not keep the JVM running even
though all relevant threads have already exited.
Unfortunately, the OpenJDK builtin HTTP server
likes to spawn its own HTTP Dispatcher thread on
startup.
https://github.com/openjdk/jdk/blob/02c95a6d7eb77ed17ae64d0f585197e87a67cc4a/src/jdk.httpserver/share/classes/sun/net/httpserver/ServerImpl.java#L190
This new thread inherits the daemon flag from the
thread that started it, therefore we need to call
the start method from the executor service,
because those threads are daemon threads.