Skip to content

Commit 079952a

Browse files
authored
fix(go.d/megacli): handle Adapters with no drives (netdata#20046)
1 parent 28d40e1 commit 079952a

3 files changed

Lines changed: 35 additions & 6 deletions

File tree

src/go/plugin/go.d/collector/megacli/collect_phys_drives.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ func (c *Collector) collectPhysDrives(mx map[string]int64) error {
5555
var drives int
5656

5757
for _, ad := range adapters {
58+
if len(ad.physDrives) == 0 {
59+
continue
60+
}
61+
5862
if !c.adapters[ad.number] {
5963
c.adapters[ad.number] = true
6064
c.addAdapterCharts(ad)

src/go/plugin/go.d/collector/megacli/collector_test.go

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,21 @@ var (
2020
dataConfigJSON, _ = os.ReadFile("testdata/config.json")
2121
dataConfigYAML, _ = os.ReadFile("testdata/config.yaml")
2222

23-
dataBBUInfoOld, _ = os.ReadFile("testdata/mega-bbu-info-old.txt")
24-
dataBBUInfoRecent, _ = os.ReadFile("testdata/mega-bbu-info-recent.txt")
25-
dataPhysDrivesInfo, _ = os.ReadFile("testdata/mega-phys-drives-info.txt")
23+
dataBBUInfoOld, _ = os.ReadFile("testdata/mega-bbu-info-old.txt")
24+
dataBBUInfoRecent, _ = os.ReadFile("testdata/mega-bbu-info-recent.txt")
25+
dataPhysDrivesInfo, _ = os.ReadFile("testdata/mega-phys-drives-info.txt")
26+
dataPhysDrivesInfoNoDrives, _ = os.ReadFile("testdata/mega-phys-drives-info-no-drives.txt")
2627
)
2728

2829
func Test_testDataIsValid(t *testing.T) {
2930
for name, data := range map[string][]byte{
3031
"dataConfigJSON": dataConfigJSON,
3132
"dataConfigYAML": dataConfigYAML,
3233

33-
"dataBBUInfoOld": dataBBUInfoOld,
34-
"dataBBUInfoRecent": dataBBUInfoRecent,
35-
"dataPhysDrivesInfo": dataPhysDrivesInfo,
34+
"dataBBUInfoOld": dataBBUInfoOld,
35+
"dataBBUInfoRecent": dataBBUInfoRecent,
36+
"dataPhysDrivesInfo": dataPhysDrivesInfo,
37+
"dataPhysDrivesInfoNoDrives": dataPhysDrivesInfoNoDrives,
3638
} {
3739
require.NotNil(t, data, name)
3840
}
@@ -216,6 +218,17 @@ func TestCollector_Collect(t *testing.T) {
216218
"phys_drive_5002538c4002e713_predictive_failure_count": 0,
217219
},
218220
},
221+
"adapter with disconnected drives": {
222+
prepareMock: prepareMockNoDrives,
223+
wantCharts: len(bbuChartsTmpl) * 1,
224+
wantMetrics: map[string]int64{
225+
"bbu_adapter_0_absolute_state_of_charge": 63,
226+
"bbu_adapter_0_capacity_degradation_perc": 10,
227+
"bbu_adapter_0_cycle_count": 4,
228+
"bbu_adapter_0_relative_state_of_charge": 71,
229+
"bbu_adapter_0_temperature": 33,
230+
},
231+
},
219232
"err on exec": {
220233
prepareMock: prepareMockErr,
221234
wantMetrics: nil,
@@ -254,6 +267,13 @@ func prepareMockOK() *mockMegaCliExec {
254267
}
255268
}
256269

270+
func prepareMockNoDrives() *mockMegaCliExec {
271+
return &mockMegaCliExec{
272+
physDrivesInfoData: dataPhysDrivesInfoNoDrives,
273+
bbuInfoData: dataBBUInfoRecent,
274+
}
275+
}
276+
257277
func prepareMockOldBbuOK() *mockMegaCliExec {
258278
return &mockMegaCliExec{
259279
physDrivesInfoData: dataPhysDrivesInfo,
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Adapter #0
2+
3+
Number of Virtual Disks: 0
4+
5+
Exit Code: 0x00

0 commit comments

Comments
 (0)