From 1e154ae8ec26b592b949cde1f1a7747ad420d955 Mon Sep 17 00:00:00 2001 From: Ben Kochie Date: Mon, 1 Mar 2021 19:44:21 +0100 Subject: [PATCH 1/4] Handle errors from disabled PSI subsystem When CONFIG_PSI_DEFAULT_DISABLED=y, the pressure system returns "operation not supported", rather than permission denied or not exposing the /proc/pressure files. Fixes: https://github.com/prometheus/node_exporter/issues/1961 Signed-off-by: Ben Kochie --- CHANGELOG.md | 2 ++ collector/pressure_linux.go | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fff87d73..2cf6ec33 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ * [ENHANCEMENT] * [BUGFIX] +* [BUGFIX] Handle errors from disabled PSI subsystem #1983 + ## 1.1.1 / 2021-02-12 * [BUGFIX] Fix ineffassign issue #1957 diff --git a/collector/pressure_linux.go b/collector/pressure_linux.go index bd660451..ad81ad73 100644 --- a/collector/pressure_linux.go +++ b/collector/pressure_linux.go @@ -19,6 +19,7 @@ import ( "errors" "fmt" "os" + "syscall" "github.com/go-kit/kit/log" "github.com/go-kit/kit/log/level" @@ -94,6 +95,10 @@ func (c *pressureStatsCollector) Update(ch chan<- prometheus.Metric) error { 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 ErrNoData } + if errors.Is(err, syscall.ENOTSUP) { + level.Debug(c.logger).Log("msg", "pressure information is disabled, add psi=1 kernel command line to enable it") + return ErrNoData + } return fmt.Errorf("failed to retrieve pressure stats: %w", err) } switch res { From 57d572e19419370b8639d7f9810f812afc518f48 Mon Sep 17 00:00:00 2001 From: Ben Kochie Date: Tue, 2 Mar 2021 16:46:47 +0100 Subject: [PATCH 2/4] Sanitize strings from /sys/class/power_supply Avoid panic on invalid UTF-8 from /sys/class/power_supply by sanitizing strings parsed from the kernel. * Add a broken string to the test fixtures. Fixes: https://github.com/prometheus/node_exporter/issues/1979 Signed-off-by: Ben Kochie --- CHANGELOG.md | 1 + collector/fixtures/e2e-output.txt | 2 +- collector/fixtures/sys.ttar | 2 +- collector/powersupplyclass.go | 3 ++- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2cf6ec33..1bc76489 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ * [BUGFIX] * [BUGFIX] Handle errors from disabled PSI subsystem #1983 +* [BUGFIX] Sanitize strings from /sys/class/power_supply #1984 ## 1.1.1 / 2021-02-12 diff --git a/collector/fixtures/e2e-output.txt b/collector/fixtures/e2e-output.txt index 468ee872..02175f41 100644 --- a/collector/fixtures/e2e-output.txt +++ b/collector/fixtures/e2e-output.txt @@ -2613,7 +2613,7 @@ node_power_supply_energy_watthour{power_supply="BAT0"} 36.58 # HELP node_power_supply_info info of /sys/class/power_supply/. # TYPE node_power_supply_info gauge node_power_supply_info{power_supply="AC",type="Mains"} 1 -node_power_supply_info{capacity_level="Normal",manufacturer="LGC",model_name="LNV-45N1",power_supply="BAT0",serial_number="38109",status="Discharging",technology="Li-ion",type="Battery"} 1 +node_power_supply_info{capacity_level="Normal",manufacturer="LGC",model_name="LNV-45N1�",power_supply="BAT0",serial_number="38109",status="Discharging",technology="Li-ion",type="Battery"} 1 # HELP node_power_supply_online online value of /sys/class/power_supply/. # TYPE node_power_supply_online gauge node_power_supply_online{power_supply="AC"} 0 diff --git a/collector/fixtures/sys.ttar b/collector/fixtures/sys.ttar index 0392d205..9f072430 100644 --- a/collector/fixtures/sys.ttar +++ b/collector/fixtures/sys.ttar @@ -1298,7 +1298,7 @@ Mode: 444 # ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Path: sys/class/power_supply/BAT0/model_name Lines: 1 -LNV-45N1 +LNV-45N1ÀÀ Mode: 444 # ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Directory: sys/class/power_supply/BAT0/power diff --git a/collector/powersupplyclass.go b/collector/powersupplyclass.go index adebf0e6..cd2028d0 100644 --- a/collector/powersupplyclass.go +++ b/collector/powersupplyclass.go @@ -21,6 +21,7 @@ import ( "fmt" "os" "regexp" + "strings" "github.com/go-kit/kit/log" "github.com/prometheus/client_golang/prometheus" @@ -153,7 +154,7 @@ func (c *powerSupplyClassCollector) Update(ch chan<- prometheus.Metric) error { } { if value != "" { keys = append(keys, name) - values = append(values, value) + values = append(values, strings.ToValidUTF8(value, "�")) } } From 3c73a869afb47ed900049fbc233bff95f64f4b95 Mon Sep 17 00:00:00 2001 From: Ben Kochie Date: Wed, 3 Mar 2021 08:57:16 +0100 Subject: [PATCH 3/4] Silence missing netclass errors * Handle no such file and permission denied errors. * Reduce excessive error wrapping. Fixes: https://github.com/prometheus/node_exporter/issues/1840 Signed-off-by: Ben Kochie --- CHANGELOG.md | 1 + collector/netclass_linux.go | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1bc76489..dbfc9fa3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ * [BUGFIX] Handle errors from disabled PSI subsystem #1983 * [BUGFIX] Sanitize strings from /sys/class/power_supply #1984 +* [BUGFIX] Silence missing netclass errors #1986 ## 1.1.1 / 2021-02-12 diff --git a/collector/netclass_linux.go b/collector/netclass_linux.go index 0fde2191..515f4d74 100644 --- a/collector/netclass_linux.go +++ b/collector/netclass_linux.go @@ -17,10 +17,13 @@ package collector import ( + "errors" "fmt" + "os" "regexp" "github.com/go-kit/kit/log" + "github.com/go-kit/kit/log/level" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/procfs/sysfs" "gopkg.in/alecthomas/kingpin.v2" @@ -61,6 +64,10 @@ func NewNetClassCollector(logger log.Logger) (Collector, error) { func (c *netClassCollector) Update(ch chan<- prometheus.Metric) error { netClass, err := c.getNetClassInfo() if err != nil { + if errors.Is(err, os.ErrNotExist) || errors.Is(err, os.ErrPermission) { + level.Debug(c.logger).Log("msg", "Could not read netclass file", "err", err) + return ErrNoData + } return fmt.Errorf("could not get net class info: %w", err) } for _, ifaceInfo := range netClass { @@ -173,9 +180,8 @@ func pushMetric(ch chan<- prometheus.Metric, subsystem string, name string, valu func (c *netClassCollector) getNetClassInfo() (sysfs.NetClass, error) { netClass, err := c.fs.NetClass() - if err != nil { - return netClass, fmt.Errorf("error obtaining net class info: %w", err) + return netClass, err } for device := range netClass { From 03d8426627f710c408416a99dd6c120155d44b4e Mon Sep 17 00:00:00 2001 From: Ben Kochie Date: Fri, 5 Mar 2021 08:30:29 +0100 Subject: [PATCH 4/4] Release version 1.1.2 * [BUGFIX] Handle errors from disabled PSI subsystem #1983 * [BUGFIX] Sanitize strings from /sys/class/power_supply #1984 * [BUGFIX] Silence missing netclass errors #1986 Signed-off-by: Ben Kochie --- CHANGELOG.md | 2 ++ VERSION | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dbfc9fa3..ef9658aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ * [ENHANCEMENT] * [BUGFIX] +## 1.1.2 / 2021-03-05 + * [BUGFIX] Handle errors from disabled PSI subsystem #1983 * [BUGFIX] Sanitize strings from /sys/class/power_supply #1984 * [BUGFIX] Silence missing netclass errors #1986 diff --git a/VERSION b/VERSION index 524cb552..45a1b3f4 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.1.1 +1.1.2