From f0332993efc52e723d2337ff96969542a4ebd69a Mon Sep 17 00:00:00 2001 From: Li Ling Date: Thu, 20 Aug 2020 14:09:55 +0200 Subject: [PATCH] Empty collection should return success=0 (#1323, #1723) Signed-off-by: Li Ling --- collector/pressure_linux.go | 2 +- collector/rapl_linux.go | 2 +- collector/zfs.go | 8 ++++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/collector/pressure_linux.go b/collector/pressure_linux.go index 8f0b8db6..026b9c7b 100644 --- a/collector/pressure_linux.go +++ b/collector/pressure_linux.go @@ -89,7 +89,7 @@ func (c *pressureStatsCollector) Update(ch chan<- prometheus.Metric) error { vals, err := c.fs.PSIStatsForResource(res) if err != nil { level.Debug(c.logger).Log("msg", "pressure information is unavailable, you need a Linux kernel >= 4.20 and/or CONFIG_PSI enabled for your kernel") - return nil + return ErrNoData } switch res { case "cpu": diff --git a/collector/rapl_linux.go b/collector/rapl_linux.go index 25498c94..2a0e805f 100644 --- a/collector/rapl_linux.go +++ b/collector/rapl_linux.go @@ -50,7 +50,7 @@ func (c *raplCollector) Update(ch chan<- prometheus.Metric) error { // nil zones are fine when platform doesn't have powercap files present. zones, err := sysfs.GetRaplZones(c.fs) if err != nil { - return nil + return ErrNoData } for _, rz := range zones { diff --git a/collector/zfs.go b/collector/zfs.go index b530e350..332fde00 100644 --- a/collector/zfs.go +++ b/collector/zfs.go @@ -65,6 +65,14 @@ func NewZFSCollector(logger log.Logger) (Collector, error) { } func (c *zfsCollector) Update(ch chan<- prometheus.Metric) error { + + if _, err := c.openProcFile(c.linuxProcpathBase); err != nil { + if err == errZFSNotAvailable { + level.Debug(c.logger).Log("err", err) + return ErrNoData + } + } + for subsystem := range c.linuxPathMap { if err := c.updateZfsStats(subsystem, ch); err != nil { if err == errZFSNotAvailable {