fix(go.d/megacli): handle Adapters with no drives (#20046)
Ilya Mashchenko committed
Apr 3, 2025 at 16:13 UTC
079952acf740e26696be14852eed12ae31e87448
3 files changed
+35
-6
src/go/plugin/go.d/collector/megacli/collect_phys_drives.go
+4
@@ -55,6 +55,10 @@ func (c *Collector) collectPhysDrives(mx map[string]int64) error {
55
var drives int
56
57
for _, ad := range adapters {
58
+ if len(ad.physDrives) == 0 {
59
+ continue
60
+ }
61
+
62
if !c.adapters[ad.number] {
63
c.adapters[ad.number] = true
64
c.addAdapterCharts(ad)
src/go/plugin/go.d/collector/megacli/collector_test.go
+26
-6
@@ -20,9 +20,10 @@ var (
20
dataConfigJSON, _ = os.ReadFile("testdata/config.json")
21
dataConfigYAML, _ = os.ReadFile("testdata/config.yaml")
22
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")
27
)
28
29
func Test_testDataIsValid(t *testing.T) {
@@ -30,9 +31,10 @@ func Test_testDataIsValid(t *testing.T) {
31
"dataConfigJSON": dataConfigJSON,
32
"dataConfigYAML": dataConfigYAML,
33
33
- "dataBBUInfoOld": dataBBUInfoOld,
34
- "dataBBUInfoRecent": dataBBUInfoRecent,
35
- "dataPhysDrivesInfo": dataPhysDrivesInfo,
34
+ "dataBBUInfoOld": dataBBUInfoOld,
35
+ "dataBBUInfoRecent": dataBBUInfoRecent,
36
+ "dataPhysDrivesInfo": dataPhysDrivesInfo,
37
+ "dataPhysDrivesInfoNoDrives": dataPhysDrivesInfoNoDrives,
38
} {
39
require.NotNil(t, data, name)
40
}
@@ -216,6 +218,17 @@ func TestCollector_Collect(t *testing.T) {
218
"phys_drive_5002538c4002e713_predictive_failure_count": 0,
219
},
220
},
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
+ },
232
"err on exec": {
233
prepareMock: prepareMockErr,
234
wantMetrics: nil,
@@ -254,6 +267,13 @@ func prepareMockOK() *mockMegaCliExec {
267
}
268
}
269
270
+func prepareMockNoDrives() *mockMegaCliExec {
271
+ return &mockMegaCliExec{
272
+ physDrivesInfoData: dataPhysDrivesInfoNoDrives,
273
+ bbuInfoData: dataBBUInfoRecent,
274
+ }
275
+}
276
+
277
func prepareMockOldBbuOK() *mockMegaCliExec {
278
return &mockMegaCliExec{
279
physDrivesInfoData: dataPhysDrivesInfo,
src/go/plugin/go.d/collector/megacli/testdata/mega-phys-drives-info-no-drives.txt
new
+5
@@ -0,0 +1,5 @@
1
+Adapter #0
2
+
3
+Number of Virtual Disks: 0
4
+
5
+Exit Code: 0x00
\ No newline at end of file