Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions blockdevice/stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func TestBlockDevice(t *testing.T) {
if err != nil {
t.Fatal(err)
}
expectedNumOfDevices := 8
expectedNumOfDevices := 9
if len(devices) != expectedNumOfDevices {
t.Fatalf(failMsgFormat, "Incorrect number of devices", expectedNumOfDevices, len(devices))
}
Expand All @@ -95,18 +95,18 @@ func TestBlockDevice(t *testing.T) {
if device0stats.WeightedIOTicks != 6088971 {
t.Errorf(failMsgFormat, "Incorrect time in queue", 6088971, device0stats.WeightedIOTicks)
}
device7stats, count, err := blockdevice.SysBlockDeviceStat(devices[7])
device8stats, count, err := blockdevice.SysBlockDeviceStat(devices[8])
if count != 15 {
t.Errorf(failMsgFormat, "Incorrect number of stats read", 15, count)
}
if err != nil {
t.Fatal(err)
}
if device7stats.WriteSectors != 286915323 {
t.Errorf(failMsgFormat, "Incorrect write merges", 286915323, device7stats.WriteSectors)
if device8stats.WriteSectors != 286915323 {
t.Errorf(failMsgFormat, "Incorrect write merges", 286915323, device8stats.WriteSectors)
}
if device7stats.DiscardTicks != 12 {
t.Errorf(failMsgFormat, "Incorrect discard ticks", 12, device7stats.DiscardTicks)
if device8stats.DiscardTicks != 12 {
t.Errorf(failMsgFormat, "Incorrect discard ticks", 12, device8stats.DiscardTicks)
}
blockQueueStatExpected := BlockQueueStats{
AddRandom: 1,
Expand Down Expand Up @@ -147,7 +147,7 @@ func TestBlockDevice(t *testing.T) {
WriteZeroesMaxBytes: 0,
}

blockQueueStat, err := blockdevice.SysBlockDeviceQueueStats(devices[7])
blockQueueStat, err := blockdevice.SysBlockDeviceQueueStats(devices[8])
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -232,12 +232,12 @@ func TestSysBlockDeviceSize(t *testing.T) {
if err != nil {
t.Fatal(err)
}
size7, err := blockdevice.SysBlockDeviceSize(devices[7])
size8, err := blockdevice.SysBlockDeviceSize(devices[8])
if err != nil {
t.Fatal(err)
}
size7Expected := uint64(1920383410176)
if size7 != size7Expected {
t.Errorf("Incorrect BlockDeviceSize, expected: \n%+v, got: \n%+v", size7Expected, size7)
size8Expected := uint64(1920383410176)
if size8 != size8Expected {
t.Errorf("Incorrect BlockDeviceSize, expected: \n%+v, got: \n%+v", size8Expected, size8)
}
}
14 changes: 10 additions & 4 deletions sysfs/mdraid.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,16 @@ func (fs FS) Mdraids() ([]Mdraid, error) {
return mdraids, err
}

if val, err := util.ReadUintFromFile(filepath.Join(path, "raid_disks")); err == nil {
md.Disks = val
} else {
return mdraids, err
// RAID level is set to 'container', 'imsm' or 'ddf', no physical disks are assigned.
switch md.Level {
case "container", "imsm", "ddf":
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check issue prometheus/node_exporter#3528

In that scenario the level file is empty, which will result in this switch statement going into the default switch case and result in error due to raid_disks also being empty.

However, I'm not entirely sure if the level file is empty if it is appropriate to set md.Disks to zero too

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, we might want to make md.Disks a pointer and for tihs caes set md.Disks = nil.

md.Disks = 0
default:
if val, err := util.ReadUintFromFile(filepath.Join(path, "raid_disks")); err == nil {
md.Disks = val
} else {
return mdraids, err
}
}

if val, err := util.SysReadFile(filepath.Join(path, "uuid")); err == nil {
Expand Down
8 changes: 8 additions & 0 deletions sysfs/mdraid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ func TestMdraidStats(t *testing.T) {
SyncAction: "recover",
SyncCompleted: 0.7500458659491194,
},
{
Device: "md7",
Level: "container",
ArrayState: "inactive",
MetadataVersion: "1.2",
Disks: 0,
UUID: "0e51f6d1-b357-2712-8eaa-31f6f597be6b",
},
}

if diff := cmp.Diff(want, got); diff != "" {
Expand Down
31 changes: 31 additions & 0 deletions testdata/fixtures.ttar
Original file line number Diff line number Diff line change
Expand Up @@ -4478,6 +4478,37 @@ Lines: 1
5f529b25-6efd-46e4-99a2-31f6f597be6b
Mode: 444
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Directory: fixtures/sys/block/md7
Mode: 755
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Directory: fixtures/sys/block/md7/md
Mode: 755
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: fixtures/sys/block/md7/md/array_state
Lines: 1
inactive
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: fixtures/sys/block/md7/md/level
Lines: 1
container
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: fixtures/sys/block/md7/md/metadata_version
Lines: 1
1.2
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: fixtures/sys/block/md7/md/raid_disks
Lines: 1

Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: fixtures/sys/block/md7/md/uuid
Lines: 1
0e51f6d1-b357-2712-8eaa-31f6f597be6b
Mode: 444
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Directory: fixtures/sys/block/sda
Mode: 755
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Expand Down