Skip to content

Commit

Permalink
Merge pull request #2808 from ToMe25/fix_error_total_disabling
Browse files Browse the repository at this point in the history
Fix promhttp_metric_handler_errors_total being always active
  • Loading branch information
SuperQ authored Oct 16, 2023
2 parents 6384499 + db3a437 commit 0f6a4d8
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions node_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,22 +123,34 @@ func (h *handler) innerHandler(filters ...string) (http.Handler, error) {
if err := r.Register(nc); err != nil {
return nil, fmt.Errorf("couldn't register node collector: %s", err)
}
handler := promhttp.HandlerFor(
prometheus.Gatherers{h.exporterMetricsRegistry, r},
promhttp.HandlerOpts{
ErrorLog: stdlog.New(log.NewStdlibAdapter(level.Error(h.logger)), "", 0),
ErrorHandling: promhttp.ContinueOnError,
MaxRequestsInFlight: h.maxRequests,
Registry: h.exporterMetricsRegistry,
},
)

var handler http.Handler
if h.includeExporterMetrics {
handler = promhttp.HandlerFor(
prometheus.Gatherers{h.exporterMetricsRegistry, r},
promhttp.HandlerOpts{
ErrorLog: stdlog.New(log.NewStdlibAdapter(level.Error(h.logger)), "", 0),
ErrorHandling: promhttp.ContinueOnError,
MaxRequestsInFlight: h.maxRequests,
Registry: h.exporterMetricsRegistry,
},
)
// Note that we have to use h.exporterMetricsRegistry here to
// use the same promhttp metrics for all expositions.
handler = promhttp.InstrumentMetricHandler(
h.exporterMetricsRegistry, handler,
)
} else {
handler = promhttp.HandlerFor(
r,
promhttp.HandlerOpts{
ErrorLog: stdlog.New(log.NewStdlibAdapter(level.Error(h.logger)), "", 0),
ErrorHandling: promhttp.ContinueOnError,
MaxRequestsInFlight: h.maxRequests,
},
)
}

return handler, nil
}

Expand Down

0 comments on commit 0f6a4d8

Please sign in to comment.