-
Notifications
You must be signed in to change notification settings - Fork 343
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
Use web configuration from exporter-toolkit #461
Conversation
b7531cb
to
22a1ce9
Compare
LGTM! (almost ^^) SIGINT : nicolas@MacBook-Pro-de-Nicolas:~/go/src/github.com/n-rodriguez/nginx-prometheus-exporter$ ./nginx-prometheus-exporter
level=info ts=2023-07-20T17:27:44.004Z caller=exporter.go:137 msg="Starting nginx-prometheus-exporter" version="(version=0.11.0, branch=, revision=c722e30e951cd1fae380543e6ac993b73e6a6d63)"
level=info ts=2023-07-20T17:27:44.004Z caller=exporter.go:138 msg="Build context" build_context="(go=go1.20.3, platform=darwin/arm64, user=, date=, tags=unknown)"
level=info ts=2023-07-20T17:27:44.006Z caller=tls_config.go:274 msg="Listening on" address=[::]:9113
level=info ts=2023-07-20T17:27:44.006Z caller=tls_config.go:277 msg="TLS is disabled." http2=false address=[::]:9113
^Clevel=info ts=2023-07-20T17:27:44.830Z caller=exporter.go:259 msg="Shutting down"
level=info ts=2023-07-20T17:27:44.830Z caller=exporter.go:250 msg="HTTP server closed"
nicolas@MacBook-Pro-de-Nicolas:~/go/src/github.com/n-rodriguez/nginx-prometheus-exporter$ echo $?
0 SIGTERM : nicolas@MacBook-Pro-de-Nicolas:~/go/src/github.com/n-rodriguez/nginx-prometheus-exporter$ ./nginx-prometheus-exporter
level=info ts=2023-07-20T17:30:39.388Z caller=exporter.go:137 msg="Starting nginx-prometheus-exporter" version="(version=0.11.0, branch=, revision=c722e30e951cd1fae380543e6ac993b73e6a6d63)"
level=info ts=2023-07-20T17:30:39.388Z caller=exporter.go:138 msg="Build context" build_context="(go=go1.20.3, platform=darwin/arm64, user=, date=, tags=unknown)"
level=info ts=2023-07-20T17:30:39.390Z caller=tls_config.go:274 msg="Listening on" address=[::]:9113
level=info ts=2023-07-20T17:30:39.390Z caller=tls_config.go:277 msg="TLS is disabled." http2=false address=[::]:9113
Terminated: 15
nicolas@MacBook-Pro-de-Nicolas:~/go/src/github.com/n-rodriguez/nginx-prometheus-exporter$ echo $?
143 There is an issue with It works with this patch : diff --git a/exporter.go b/exporter.go
index 6c81376..2de83a5 100644
--- a/exporter.go
+++ b/exporter.go
@@ -11,6 +11,7 @@ import (
"os"
"os/signal"
"strings"
+ "syscall"
"time"
plusclient "github.com/nginxinc/nginx-plus-go-client/client"
@@ -237,7 +238,7 @@ func main() {
http.Handle("/", landingPage)
}
- ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, os.Kill)
+ ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
defer cancel()
srv := &http.Server{ nicolas@MacBook-Pro-de-Nicolas:~/go/src/github.com/n-rodriguez/nginx-prometheus-exporter$ ./nginx-prometheus-exporter
level=info ts=2023-07-20T17:44:25.176Z caller=exporter.go:138 msg="Starting nginx-prometheus-exporter" version="(version=0.11.0, branch=, revision=c722e30e951cd1fae380543e6ac993b73e6a6d63-modified)"
level=info ts=2023-07-20T17:44:25.176Z caller=exporter.go:139 msg="Build context" build_context="(go=go1.20.3, platform=darwin/arm64, user=, date=, tags=unknown)"
level=info ts=2023-07-20T17:44:25.178Z caller=tls_config.go:274 msg="Listening on" address=[::]:9113
level=info ts=2023-07-20T17:44:25.178Z caller=tls_config.go:277 msg="TLS is disabled." http2=false address=[::]:9113
level=info ts=2023-07-20T17:44:33.863Z caller=exporter.go:260 msg="Shutting down"
level=info ts=2023-07-20T17:44:33.863Z caller=exporter.go:251 msg="HTTP server closed"
nicolas@MacBook-Pro-de-Nicolas:~/go/src/github.com/n-rodriguez/nginx-prometheus-exporter$ echo $?
0 |
Thanks for reviewing @n-rodriguez From: https://github.com/golang/go/blob/master/src/os/exec_posix.go#L16-L24 // The only signal values guaranteed to be present in the os package on all
// systems are os.Interrupt (send the process an interrupt) and os.Kill (force
// the process to exit). On Windows, sending os.Interrupt to a process with
// os.Process.Signal is not implemented; it will return an error instead of
// sending a signal.
var (
Interrupt Signal = syscall.SIGINT
Kill Signal = syscall.SIGKILL
) so Like this I think: signal.NotifyContext(context.Background(), os.Interrupt, os.Kill, syscall.SIGTERM) To be honest I'm not entirely sure I see the value of waiting for a shutdown in the first place, we're not serving traffic or anything like that, since it's just exposing metrics, but I guess it doesn't hurt. |
yes, please 👍 |
Added |
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.
LGTM!
basically it's the same thing : an http request => in all cases you don't want clients to receive a truncated response from the server. (https://pkg.go.dev/net/http#Server.Shutdown) |
Dependency ReviewThe following issues were found:
License Issuesgo.mod
Allowed Licenses: Apache-1.1, Apache-2.0, BSD-2-Clause, BSD-3-Clause, BSL-1.0, ISC, MIT, NCSA, OpenSSL, Python-2.0, X11 Scanned Manifest Filesgo.mod
|
Replaces manual implementation of TLS and adds Basic Auth.
a5b34db
to
72ef862
Compare
Proposed changes
Thanks @lucian-vanghele for opening #231 and bringing this to my attention.
Closes #232
Closes #393
Closes #425