From 7b6ecccf385f16a7e139faad522566300e972def Mon Sep 17 00:00:00 2001 From: Ayoub Mrini Date: Tue, 5 Mar 2024 14:45:50 +0100 Subject: [PATCH] chore: class_fibrechannel: support optional attributes (#607) Signed-off-by: machine424 --- sysfs/class_fibrechannel.go | 5 ++ sysfs/class_fibrechannel_test.go | 20 ++++++++ testdata/fixtures.ttar | 81 ++++++++++++++++++++++++++++++++ 3 files changed, 106 insertions(+) diff --git a/sysfs/class_fibrechannel.go b/sysfs/class_fibrechannel.go index d7e62784b..ded07a881 100644 --- a/sysfs/class_fibrechannel.go +++ b/sysfs/class_fibrechannel.go @@ -93,6 +93,11 @@ func (fs FS) parseFibreChannelHost(name string) (*FibreChannelHost, error) { name := filepath.Join(path, f) value, err := util.SysReadFile(name) if err != nil { + // drivers can choose not to expose some attributes to sysfs. + // See: https://github.com/prometheus/node_exporter/issues/2919. + if os.IsNotExist(err) { + continue + } return nil, fmt.Errorf("failed to read file %q: %w", name, err) } diff --git a/sysfs/class_fibrechannel_test.go b/sysfs/class_fibrechannel_test.go index 7181795c9..55f728c2e 100644 --- a/sysfs/class_fibrechannel_test.go +++ b/sysfs/class_fibrechannel_test.go @@ -64,6 +64,26 @@ func TestFibreChannelClass(t *testing.T) { FCPPacketAborts: 0x13, }, }, + "host1": FibreChannelHost{ + Name: "host1", + PortState: "Online", + Counters: FibreChannelCounters{ + DumpedFrames: 0, + ErrorFrames: ^uint64(0), + InvalidCRCCount: 0x20, + RXFrames: 0x30, + RXWords: 0x40, + TXFrames: 0x50, + TXWords: 0x60, + SecondsSinceLastReset: 0x70, + InvalidTXWordCount: 0x80, + LinkFailureCount: 0x90, + LossOfSyncCount: 0x100, + LossOfSignalCount: 0x110, + NosCount: 0x120, + FCPPacketAborts: 0x130, + }, + }, } if diff := cmp.Diff(want, got); diff != "" { diff --git a/testdata/fixtures.ttar b/testdata/fixtures.ttar index 3fdfc5b45..c5d9a6dc7 100644 --- a/testdata/fixtures.ttar +++ b/testdata/fixtures.ttar @@ -5068,6 +5068,87 @@ Lines: 1 Emulex SN1100E2P FV12.4.270.3 DV12.4.0.0. HN:gotest. OS:Linux Mode: 644 # ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Directory: fixtures/sys/class/fc_host/host1 +Mode: 755 +# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Path: fixtures/sys/class/fc_host/host1/port_state +Lines: 1 +Online +Mode: 644 +# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Directory: fixtures/sys/class/fc_host/host1/statistics +Mode: 755 +# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Path: fixtures/sys/class/fc_host/host1/statistics/dumped_frames +Lines: 1 +0x0 +Mode: 644 +# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Path: fixtures/sys/class/fc_host/host1/statistics/error_frames +Lines: 1 +0xffffffffffffffff +Mode: 644 +# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Path: fixtures/sys/class/fc_host/host1/statistics/fcp_packet_aborts +Lines: 1 +0x130 +Mode: 644 +# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Path: fixtures/sys/class/fc_host/host1/statistics/invalid_crc_count +Lines: 1 +0x20 +Mode: 644 +# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Path: fixtures/sys/class/fc_host/host1/statistics/invalid_tx_word_count +Lines: 1 +0x80 +Mode: 644 +# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Path: fixtures/sys/class/fc_host/host1/statistics/link_failure_count +Lines: 1 +0x90 +Mode: 644 +# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Path: fixtures/sys/class/fc_host/host1/statistics/loss_of_signal_count +Lines: 1 +0x110 +Mode: 644 +# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Path: fixtures/sys/class/fc_host/host1/statistics/loss_of_sync_count +Lines: 1 +0x100 +Mode: 644 +# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Path: fixtures/sys/class/fc_host/host1/statistics/nos_count +Lines: 1 +0x120 +Mode: 644 +# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Path: fixtures/sys/class/fc_host/host1/statistics/rx_frames +Lines: 1 +0x30 +Mode: 644 +# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Path: fixtures/sys/class/fc_host/host1/statistics/rx_words +Lines: 1 +0x40 +Mode: 644 +# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Path: fixtures/sys/class/fc_host/host1/statistics/seconds_since_last_reset +Lines: 1 +0x70 +Mode: 644 +# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Path: fixtures/sys/class/fc_host/host1/statistics/tx_frames +Lines: 1 +0x50 +Mode: 644 +# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Path: fixtures/sys/class/fc_host/host1/statistics/tx_words +Lines: 1 +0x60 +Mode: 644 +# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Directory: fixtures/sys/class/infiniband Mode: 755 # ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -