Skip to content
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

Don't count empty collection as success #1613

Merged
merged 1 commit into from
Feb 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
- `node_md_is_active` is replaced by `node_md_state` with a state set of "active", "inactive", "recovering", "resync".
* Additional label `mountaddr` added to NFS device metrics to distinguish mounts from the same URL, but different IP addresses. #1417
* Metrics node_cpu_scaling_frequency_min_hrts and node_cpu_scaling_frequency_max_hrts of the cpufreq collector were renamed to node_cpu_scaling_frequency_min_hertz and node_cpu_scaling_frequency_max_hertz. #1510
* Collectors that are enabled, but are unable to find data to collect, now return 0 for `node_scrape_collector_success`.

### Changes

* [CHANGE] Add `--collector.netdev.device-whitelist`. #1279
* [CHANGE] Refactor mdadm collector #1403
* [CHANGE] Add `mountaddr` label to NFS metrics. #1417
* [CHANGE] Don't count empty collectors as success. #...
* [FEATURE] Add new schedstat collector #1389
* [FEATURE] Add uname support for Darwin and OpenBSD #1433
* [FEATURE] Add new metric node_cpu_info #1489
Expand Down
2 changes: 1 addition & 1 deletion collector/bonding_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (c *bondingCollector) Update(ch chan<- prometheus.Metric) error {
if err != nil {
if os.IsNotExist(err) {
level.Debug(c.logger).Log("msg", "Not collecting bonding, file does not exist", "file", statusfile)
return nil
return ErrNoData
}
return err
}
Expand Down
14 changes: 13 additions & 1 deletion collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package collector

import (
"errors"
"fmt"
"sync"
"time"
Expand Down Expand Up @@ -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())
Expand All @@ -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
}
2 changes: 1 addition & 1 deletion collector/drbd_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func (c *drbdCollector) Update(ch chan<- prometheus.Metric) error {
if err != nil {
if os.IsNotExist(err) {
level.Debug(c.logger).Log("msg", "stats file does not exist, skipping", "file", statsFile, "err", err)
return nil
return ErrNoData
}

return err
Expand Down
2 changes: 1 addition & 1 deletion collector/hwmon_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ func (c *hwMonCollector) Update(ch chan<- prometheus.Metric) error {
if err != nil {
if os.IsNotExist(err) {
level.Debug(c.logger).Log("msg", "hwmon collector metrics are not available for this system")
return nil
return ErrNoData
}

return err
Expand Down
4 changes: 2 additions & 2 deletions collector/infiniband_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ func (c *infinibandCollector) Update(ch chan<- prometheus.Metric) error {
devices, err := c.fs.InfiniBandClass()
if err != nil {
if os.IsNotExist(err) {
level.Debug(c.logger).Log("msg", "IPv4 sockstat statistics not found, skipping")
return nil
level.Debug(c.logger).Log("msg", "infiniband statistics not found, skipping")
return ErrNoData
}
return fmt.Errorf("error obtaining InfiniBand class info: %s", err)
}
Expand Down
2 changes: 1 addition & 1 deletion collector/ipvs_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (c *ipvsCollector) Update(ch chan<- prometheus.Metric) error {
// Cannot access ipvs metrics, report no error.
if os.IsNotExist(err) {
level.Debug(c.logger).Log("msg", "ipvs collector metrics are not available for this system")
return nil
return ErrNoData
}
return fmt.Errorf("could not get IPVS stats: %s", err)
}
Expand Down
2 changes: 1 addition & 1 deletion collector/mdadm_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (c *mdadmCollector) Update(ch chan<- prometheus.Metric) error {
if err != nil {
if os.IsNotExist(err) {
level.Debug(c.logger).Log("msg", "Not collecting mdstat, file does not exist", "file", *procPath)
return nil
return ErrNoData
}

return fmt.Errorf("error parsing mdstatus: %s", err)
Expand Down
2 changes: 1 addition & 1 deletion collector/nfs_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (c *nfsCollector) Update(ch chan<- prometheus.Metric) error {
if err != nil {
if os.IsNotExist(err) {
level.Debug(c.logger).Log("msg", "Not collecting NFS metrics", "err", err)
return nil
return ErrNoData
}
return fmt.Errorf("failed to retrieve nfs stats: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion collector/nfsd_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (c *nfsdCollector) Update(ch chan<- prometheus.Metric) error {
if err != nil {
if os.IsNotExist(err) {
level.Debug(c.logger).Log("msg", "Not collecting NFSd metrics", "err", err)
return nil
return ErrNoData
}
return fmt.Errorf("failed to retrieve nfsd stats: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions collector/wifi_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,11 @@ func (c *wifiCollector) Update(ch chan<- prometheus.Metric) error {
// Cannot access wifi metrics, report no error.
if os.IsNotExist(err) {
level.Debug(c.logger).Log("msg", "wifi collector metrics are not available for this system")
return nil
return ErrNoData
}
if os.IsPermission(err) {
level.Debug(c.logger).Log("msg", "wifi collector got permission denied when accessing metrics")
return nil
return ErrNoData
}

return fmt.Errorf("failed to access wifi data: %w", err)
Expand Down