Skip to content

Commit 1e3c2aa

Browse files
authored
Add handle for Redfish null reply (#138)
* add handle for null reply update rule and test data update adjust indent update for revice comment WIP * Add test case in collector_test.go update testdata * update
1 parent c728794 commit 1e3c2aa

File tree

8 files changed

+189891
-181686
lines changed

8 files changed

+189891
-181686
lines changed

redfish/collector_test.go

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ func testCollect(t *testing.T) {
131131
urlPath: "/redfish/v1/Chassis/System.Embedded.1/Blocks/0",
132132
filePath: "../testdata/redfish_block.json",
133133
},
134+
{
135+
urlPath: "/redfish/v1/Chassis/System.Embedded.1/Sensors/Device1",
136+
filePath: "../testdata/redfish_sensors.json",
137+
},
134138
}
135139

136140
expectedSet := []*struct {
@@ -176,17 +180,35 @@ func testCollect(t *testing.T) {
176180
},
177181
},
178182
{
179-
name: "hw_last_update",
180-
typ: prommodel.MetricType_COUNTER,
181-
value: math.NaN(), // don't care
183+
name: "hw_last_update",
184+
typ: prommodel.MetricType_COUNTER,
185+
//value: math.NaN(), // don't care
182186
labels: map[string]string{},
183187
},
184188
{
185-
name: "hw_last_update_duration_minutes",
186-
typ: prommodel.MetricType_GAUGE,
187-
value: math.NaN(), // don't care
189+
name: "hw_last_update_duration_minutes",
190+
typ: prommodel.MetricType_GAUGE,
191+
//value: math.NaN(), // don't care
188192
labels: map[string]string{},
189193
},
194+
{
195+
name: "hw_chassis_sensors_thresholds_uppercritical_reading",
196+
typ: prommodel.MetricType_GAUGE,
197+
value: math.NaN(), // null
198+
labels: map[string]string{
199+
"chassis": "System.Embedded.1",
200+
"sensor": "Device1",
201+
},
202+
},
203+
{
204+
name: "hw_chassis_sensors_thresholds_upperfatal_reading",
205+
typ: prommodel.MetricType_GAUGE,
206+
value: 150,
207+
labels: map[string]string{
208+
"chassis": "System.Embedded.1",
209+
"sensor": "Device1",
210+
},
211+
},
190212
}
191213

192214
cc, err := clientConfig()
@@ -254,11 +276,18 @@ func testCollect(t *testing.T) {
254276
default:
255277
t.Fatalf("unknown type: ")
256278
}
257-
if actualMetricName == expected.name &&
258-
(math.IsNaN(expected.value) || val == expected.value) &&
259-
matchLabels(actualLabels, expected.labels) {
260-
expected.matched = true
261-
continue ActualLoop
279+
if actualMetricName == expected.name && matchLabels(actualLabels, expected.labels) {
280+
if actualMetricName == "hw_last_update" || actualMetricName == "hw_last_update_duration_minutes" {
281+
expected.matched = true
282+
continue ActualLoop
283+
}
284+
if math.IsNaN(expected.value) && math.IsNaN(val) {
285+
expected.matched = true
286+
continue ActualLoop
287+
} else if expected.value == val {
288+
expected.matched = true
289+
continue ActualLoop
290+
}
262291
}
263292
}
264293
t.Error("unexpected metric; name:", actualMetricName, "value:", actual.GetGauge().GetValue(), "labels:", actualLabels)

redfish/converter.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package redfish
33
import (
44
"errors"
55
"fmt"
6+
"math"
67
)
78

89
type converter func(interface{}) (float64, error)
@@ -15,6 +16,10 @@ var typeToConverters = map[string]converter{
1516
}
1617

1718
func numberConverter(data interface{}) (float64, error) {
19+
// Redfish sometimes returns null for numeric values, so we handle that case.
20+
if data == nil {
21+
return math.NaN(), nil
22+
}
1823
value, ok := data.(float64)
1924
if !ok {
2025
return 0, errors.New("value was not float64")

redfish/rendered_rules.go

Lines changed: 3 additions & 51 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)