-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Cleanup prometheus metrics after a reload #2726
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ import ( | |
"time" | ||
|
||
"github.com/golang/glog" | ||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/prometheus/client_golang/prometheus/promhttp" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
@@ -39,9 +40,8 @@ import ( | |
"k8s.io/client-go/tools/clientcmd" | ||
|
||
"k8s.io/ingress-nginx/internal/file" | ||
"k8s.io/ingress-nginx/internal/ingress/annotations/class" | ||
"k8s.io/ingress-nginx/internal/ingress/controller" | ||
"k8s.io/ingress-nginx/internal/ingress/metric/collector" | ||
"k8s.io/ingress-nginx/internal/ingress/metric" | ||
"k8s.io/ingress-nginx/internal/k8s" | ||
"k8s.io/ingress-nginx/internal/net/ssl" | ||
"k8s.io/ingress-nginx/version" | ||
|
@@ -118,25 +118,20 @@ func main() { | |
|
||
conf.Client = kubeClient | ||
|
||
ngx := controller.NewNGINXController(conf, fs) | ||
reg := prometheus.NewRegistry() | ||
mc, err := metric.NewCollector(conf.ListenPorts.Status, reg) | ||
if err != nil { | ||
glog.Fatalf("Error creating prometheus collectos: %v", err) | ||
} | ||
mc.Start() | ||
|
||
ngx := controller.NewNGINXController(conf, mc, fs) | ||
go handleSigterm(ngx, func(code int) { | ||
os.Exit(code) | ||
}) | ||
|
||
mux := http.NewServeMux() | ||
go registerHandlers(conf.EnableProfiling, conf.ListenPorts.Health, ngx, mux) | ||
|
||
err = collector.InitNGINXStatusCollector(conf.Namespace, class.IngressClass, conf.ListenPorts.Status) | ||
|
||
if err != nil { | ||
glog.Fatalf("Error creating metric collector: %v", err) | ||
} | ||
|
||
err = collector.NewInstance(conf.Namespace, class.IngressClass) | ||
if err != nil { | ||
glog.Fatalf("Error creating unix socket server: %v", err) | ||
} | ||
go registerHandlers(conf.EnableProfiling, conf.ListenPorts.Health, ngx, mux, reg) | ||
|
||
ngx.Start() | ||
} | ||
|
@@ -240,14 +235,20 @@ func handleFatalInitError(err error) { | |
err) | ||
} | ||
|
||
func registerHandlers(enableProfiling bool, port int, ic *controller.NGINXController, mux *http.ServeMux) { | ||
func registerHandlers( | ||
enableProfiling bool, | ||
port int, | ||
ic *controller.NGINXController, | ||
mux *http.ServeMux, | ||
reg *prometheus.Registry) { | ||
|
||
// expose health check endpoint (/healthz) | ||
healthz.InstallHandler(mux, | ||
healthz.PingHealthz, | ||
ic, | ||
) | ||
|
||
mux.Handle("/metrics", promhttp.Handler()) | ||
mux.Handle("/metrics", promhttp.HandlerFor(reg, promhttp.HandlerOpts{})) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Handler() will instrument the handler too. If you want to keep this, use this instead:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @discordianfish There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just realized this too :) |
||
|
||
mux.HandleFunc("/build", func(w http.ResponseWriter, r *http.Request) { | ||
w.WriteHeader(http.StatusOK) | ||
|
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.
The default registry enables the GoCollector and ProcessCollector. I think we should keep these metrics by adding:
``
reg.MustRegister(prometheus.NewGoCollector())
reg.MustRegister(prometheus.NewProcessCollector(os.Getpid(), ""))
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.
done