Skip to content

Commit

Permalink
chore: class_fibrechannel: support optional attributes (#607)
Browse files Browse the repository at this point in the history
Signed-off-by: machine424 <ayoubmrini424@gmail.com>
  • Loading branch information
machine424 committed Mar 5, 2024
1 parent da53333 commit 7b6eccc
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 0 deletions.
5 changes: 5 additions & 0 deletions sysfs/class_fibrechannel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
20 changes: 20 additions & 0 deletions sysfs/class_fibrechannel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand Down
81 changes: 81 additions & 0 deletions testdata/fixtures.ttar
Original file line number Diff line number Diff line change
Expand Up @@ -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 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Expand Down

0 comments on commit 7b6eccc

Please sign in to comment.