Remove deprecated prometheus.InstrumentHandlerFunc (#831)

Update Prometheus client golang use to use `promhttp.Handler()` instead
of `prometheus.InstrumentHandlerFunc()`.
This commit is contained in:
Ben Kochie 2018-02-19 15:44:59 +01:00 committed by GitHub
commit d33a447047
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 31 deletions

View file

@ -56,11 +56,14 @@ func handler(w http.ResponseWriter, r *http.Request) {
registry,
}
// Delegate http serving to Prometheus client library, which will call collector.Collect.
h := promhttp.HandlerFor(gatherers,
promhttp.HandlerOpts{
ErrorLog: log.NewErrorLogger(),
ErrorHandling: promhttp.ContinueOnError,
})
h := promhttp.InstrumentMetricHandler(
registry,
promhttp.HandlerFor(gatherers,
promhttp.HandlerOpts{
ErrorLog: log.NewErrorLogger(),
ErrorHandling: promhttp.ContinueOnError,
}),
)
h.ServeHTTP(w, r)
}
@ -88,8 +91,7 @@ func main() {
log.Infof(" - %s", n)
}
// TODO(ts): Remove deprecated and problematic InstrumentHandlerFunc usage.
http.HandleFunc(*metricsPath, prometheus.InstrumentHandlerFunc("prometheus", handler))
http.HandleFunc(*metricsPath, handler)
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`<html>
<head><title>Node Exporter</title></head>