Don't count empty collection as success (#1613)
Many collectors depend on underlying features to be enabled. This causes confusion about what "success" means. This changes the behavior of the `node_scrape_collector_success` metric. * When a collector is unable to find data don't return success. * Catch the no data error and send to Debug log level to avoid log spam. * Update collectors to support this new functionality. * Fix copy-pasta mistake in infiband debug message. Closes: https://github.com/prometheus/node_exporter/issues/1323 Signed-off-by: Ben Kochie <superq@gmail.com>
This commit is contained in:
parent
1a75bc7b50
commit
3e1b0f1bee
11 changed files with 26 additions and 12 deletions
|
|
@ -15,6 +15,7 @@
|
|||
package collector
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"sync"
|
||||
"time"
|
||||
|
|
@ -131,7 +132,11 @@ func execute(name string, c Collector, ch chan<- prometheus.Metric, logger log.L
|
|||
var success float64
|
||||
|
||||
if err != nil {
|
||||
level.Error(logger).Log("msg", "collector failed", "name", name, "duration_seconds", duration.Seconds(), "err", err)
|
||||
if IsNoDataError(err) {
|
||||
level.Debug(logger).Log("msg", "collector returned no data", "name", name, "duration_seconds", duration.Seconds(), "err", err)
|
||||
} else {
|
||||
level.Error(logger).Log("msg", "collector failed", "name", name, "duration_seconds", duration.Seconds(), "err", err)
|
||||
}
|
||||
success = 0
|
||||
} else {
|
||||
level.Debug(logger).Log("msg", "collector succeeded", "name", name, "duration_seconds", duration.Seconds())
|
||||
|
|
@ -155,3 +160,10 @@ type typedDesc struct {
|
|||
func (d *typedDesc) mustNewConstMetric(value float64, labels ...string) prometheus.Metric {
|
||||
return prometheus.MustNewConstMetric(d.desc, d.valueType, value, labels...)
|
||||
}
|
||||
|
||||
// ErrNoData indicates the collector found no data to collect, but had no other error.
|
||||
var ErrNoData = errors.New("collector returned no data")
|
||||
|
||||
func IsNoDataError(err error) bool {
|
||||
return err == ErrNoData
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue