Fix pressure collector nil reference (#3016)

Check that the PSI metrics are returned in order to avoid nil pointer
dereference.
* Update fixutre to match real-world samples.

Fixes: https://github.com/prometheus/node_exporter/issues/3015

Signed-off-by: Ben Kochie <superq@gmail.com>
This commit is contained in:
Ben Kochie 2024-05-16 08:38:58 +02:00 committed by GitHub
parent 66fab10db4
commit 3afc0a341e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 0 deletions

View file

@ -1 +1,2 @@
some avg10=0.00 avg60=0.00 avg300=0.00 total=14036781 some avg10=0.00 avg60=0.00 avg300=0.00 total=14036781
full avg10=0.00 avg60=0.00 avg300=0.00 total=0

View file

@ -102,6 +102,14 @@ func (c *pressureStatsCollector) Update(ch chan<- prometheus.Metric) error {
} }
return fmt.Errorf("failed to retrieve pressure stats: %w", err) return fmt.Errorf("failed to retrieve pressure stats: %w", err)
} }
if vals.Some == nil {
level.Debug(c.logger).Log("msg", "pressure information returned no 'some' data")
return ErrNoData
}
if vals.Full == nil {
level.Debug(c.logger).Log("msg", "pressure information returned no 'full' data")
return ErrNoData
}
switch res { switch res {
case "cpu": case "cpu":
ch <- prometheus.MustNewConstMetric(c.cpu, prometheus.CounterValue, float64(vals.Some.Total)/1000.0/1000.0) ch <- prometheus.MustNewConstMetric(c.cpu, prometheus.CounterValue, float64(vals.Some.Total)/1000.0/1000.0)