Skip to content

Commit 60c6648

Browse files
SuperQv-zhuravlev
authored andcommitted
Fix pressure collector nil reference (prometheus#3016)
Check that the PSI metrics are returned in order to avoid nil pointer dereference. * Update fixutre to match real-world samples. Fixes: prometheus#3015 Signed-off-by: Ben Kochie <[email protected]> Signed-off-by: Vitaly Zhuravlev <[email protected]>
1 parent cc2b5a7 commit 60c6648

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
some avg10=0.00 avg60=0.00 avg300=0.00 total=14036781
2+
full avg10=0.00 avg60=0.00 avg300=0.00 total=0

collector/pressure_linux.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,14 @@ func (c *pressureStatsCollector) Update(ch chan<- prometheus.Metric) error {
102102
}
103103
return fmt.Errorf("failed to retrieve pressure stats: %w", err)
104104
}
105+
if vals.Some == nil {
106+
level.Debug(c.logger).Log("msg", "pressure information returned no 'some' data")
107+
return ErrNoData
108+
}
109+
if vals.Full == nil {
110+
level.Debug(c.logger).Log("msg", "pressure information returned no 'full' data")
111+
return ErrNoData
112+
}
105113
switch res {
106114
case "cpu":
107115
ch <- prometheus.MustNewConstMetric(c.cpu, prometheus.CounterValue, float64(vals.Some.Total)/1000.0/1000.0)

0 commit comments

Comments
 (0)