From 2085b8f9505b07d63154387a48171a079deddd49 Mon Sep 17 00:00:00 2001 From: Pranshu Srivastava Date: Sun, 12 May 2024 22:01:22 +0530 Subject: [PATCH] bugfix: Allow multiple `xprt` fields for NFS stats (#619) Allow parsing multiple `xprt` fields present in the same NFS transport stats data. Fixes: #450 Signed-off-by: Pranshu Srivastava --- mountstats.go | 4 +- mountstats_test.go | 220 ++++++++++++++++++++++++--------------------- 2 files changed, 118 insertions(+), 106 deletions(-) diff --git a/mountstats.go b/mountstats.go index 2f54e77c..75a3b6c8 100644 --- a/mountstats.go +++ b/mountstats.go @@ -88,7 +88,7 @@ type MountStatsNFS struct { // Statistics broken down by filesystem operation. Operations []NFSOperationStats // Statistics about the NFS RPC transport. - Transport NFSTransportStats + Transport []NFSTransportStats } // mountStats implements MountStats. @@ -432,7 +432,7 @@ func parseMountStatsNFS(s *bufio.Scanner, statVersion string) (*MountStatsNFS, e return nil, err } - stats.Transport = *tstats + stats.Transport = append(stats.Transport, *tstats) } // When encountering "per-operation statistics", we must break this diff --git a/mountstats_test.go b/mountstats_test.go index f9588f02..262f7d13 100644 --- a/mountstats_test.go +++ b/mountstats_test.go @@ -116,21 +116,23 @@ func TestMountStats(t *testing.T) { Type: "nfs", Stats: &MountStatsNFS{ StatVersion: "1.0", - Transport: NFSTransportStats{ - Protocol: "tcp", - Port: 1, - Bind: 2, - Connect: 3, - ConnectIdleTime: 4, - IdleTimeSeconds: 5, - Sends: 6, - Receives: 7, - BadTransactionIDs: 8, - CumulativeActiveRequests: 9, - CumulativeBacklog: 10, - MaximumRPCSlotsUsed: 0, // these three are not - CumulativeSendingQueue: 0, // present in statvers=1.0 - CumulativePendingQueue: 0, // + Transport: []NFSTransportStats{ + { + Protocol: "tcp", + Port: 1, + Bind: 2, + Connect: 3, + ConnectIdleTime: 4, + IdleTimeSeconds: 5, + Sends: 6, + Receives: 7, + BadTransactionIDs: 8, + CumulativeActiveRequests: 9, + CumulativeBacklog: 10, + MaximumRPCSlotsUsed: 0, // these three are not + CumulativeSendingQueue: 0, // present in statvers=1.0 + CumulativePendingQueue: 0, // + }, }, }, }}, @@ -144,21 +146,23 @@ func TestMountStats(t *testing.T) { Type: "nfs", Stats: &MountStatsNFS{ StatVersion: "1.0", - Transport: NFSTransportStats{ - Protocol: "udp", - Port: 1, - Bind: 2, - Connect: 0, - ConnectIdleTime: 0, - IdleTimeSeconds: 0, - Sends: 3, - Receives: 4, - BadTransactionIDs: 5, - CumulativeActiveRequests: 6, - CumulativeBacklog: 7, - MaximumRPCSlotsUsed: 0, // these three are not - CumulativeSendingQueue: 0, // present in statvers=1.0 - CumulativePendingQueue: 0, // + Transport: []NFSTransportStats{ + { + Protocol: "udp", + Port: 1, + Bind: 2, + Connect: 0, + ConnectIdleTime: 0, + IdleTimeSeconds: 0, + Sends: 3, + Receives: 4, + BadTransactionIDs: 5, + CumulativeActiveRequests: 6, + CumulativeBacklog: 7, + MaximumRPCSlotsUsed: 0, // these three are not + CumulativeSendingQueue: 0, // present in statvers=1.0 + CumulativePendingQueue: 0, // + }, }, }, }}, @@ -172,21 +176,23 @@ func TestMountStats(t *testing.T) { Type: "nfs", Stats: &MountStatsNFS{ StatVersion: "1.1", - Transport: NFSTransportStats{ - Protocol: "tcp", - Port: 1, - Bind: 2, - Connect: 3, - ConnectIdleTime: 4, - IdleTimeSeconds: 5, - Sends: 6, - Receives: 7, - BadTransactionIDs: 8, - CumulativeActiveRequests: 9, - CumulativeBacklog: 10, - MaximumRPCSlotsUsed: 11, - CumulativeSendingQueue: 12, - CumulativePendingQueue: 13, + Transport: []NFSTransportStats{ + { + Protocol: "tcp", + Port: 1, + Bind: 2, + Connect: 3, + ConnectIdleTime: 4, + IdleTimeSeconds: 5, + Sends: 6, + Receives: 7, + BadTransactionIDs: 8, + CumulativeActiveRequests: 9, + CumulativeBacklog: 10, + MaximumRPCSlotsUsed: 11, + CumulativeSendingQueue: 12, + CumulativePendingQueue: 13, + }, }, }, }}, @@ -200,21 +206,23 @@ func TestMountStats(t *testing.T) { Type: "nfs", Stats: &MountStatsNFS{ StatVersion: "1.1", - Transport: NFSTransportStats{ - Protocol: "udp", - Port: 1, - Bind: 2, - Connect: 0, // these three are not - ConnectIdleTime: 0, // present for UDP - IdleTimeSeconds: 0, // - Sends: 3, - Receives: 4, - BadTransactionIDs: 5, - CumulativeActiveRequests: 6, - CumulativeBacklog: 7, - MaximumRPCSlotsUsed: 8, - CumulativeSendingQueue: 9, - CumulativePendingQueue: 10, + Transport: []NFSTransportStats{ + { + Protocol: "udp", + Port: 1, + Bind: 2, + Connect: 0, // these three are not + ConnectIdleTime: 0, // present for UDP + IdleTimeSeconds: 0, // + Sends: 3, + Receives: 4, + BadTransactionIDs: 5, + CumulativeActiveRequests: 6, + CumulativeBacklog: 7, + MaximumRPCSlotsUsed: 8, + CumulativeSendingQueue: 9, + CumulativePendingQueue: 10, + }, }, }, }}, @@ -354,17 +362,19 @@ func TestMountStats(t *testing.T) { CumulativeTotalRequestMilliseconds: 1953587717, }, }, - Transport: NFSTransportStats{ - Protocol: "tcp", - Port: 832, - Connect: 1, - IdleTimeSeconds: 11, - Sends: 6428, - Receives: 6428, - CumulativeActiveRequests: 12154, - MaximumRPCSlotsUsed: 24, - CumulativeSendingQueue: 26, - CumulativePendingQueue: 5726, + Transport: []NFSTransportStats{ + { + Protocol: "tcp", + Port: 832, + Connect: 1, + IdleTimeSeconds: 11, + Sends: 6428, + Receives: 6428, + CumulativeActiveRequests: 12154, + MaximumRPCSlotsUsed: 24, + CumulativeSendingQueue: 26, + CumulativePendingQueue: 5726, + }, }, }, }, @@ -428,39 +438,41 @@ func TestMountStats(t *testing.T) { Errors: 0, }, }, - Transport: NFSTransportStats{ - Protocol: "rdma", - Port: 0, - Bind: 0, - Connect: 5808, - ConnectIdleTime: 62, - IdleTimeSeconds: 0, - Sends: 494490723, - Receives: 494490687, - BadTransactionIDs: 36, - CumulativeActiveRequests: 10032963746, - CumulativeBacklog: 1282789, - MaximumRPCSlotsUsed: 0, - CumulativeSendingQueue: 0, - CumulativePendingQueue: 0, - ReadChunkCount: 107150285, - WriteChunkCount: 1226637531, - ReplyChunkCount: 2673889, - TotalRdmaRequest: 135120843409861, - PullupCopyCount: 135119397156505, - HardwayRegisterCount: 266368832, - FailedMarshalCount: 75716996, - BadReplyCount: 0, - MrsRecovered: 7853, - MrsOrphaned: 0, - MrsAllocated: 0, - EmptySendctxQ: 0, - TotalRdmaReply: 0, - FixupCopyCount: 119328, - ReplyWaitsForSend: 1336431717, - LocalInvNeeded: 0, - NomsgCallCount: 96, - BcallCount: 0, + Transport: []NFSTransportStats{ + { + Protocol: "rdma", + Port: 0, + Bind: 0, + Connect: 5808, + ConnectIdleTime: 62, + IdleTimeSeconds: 0, + Sends: 494490723, + Receives: 494490687, + BadTransactionIDs: 36, + CumulativeActiveRequests: 10032963746, + CumulativeBacklog: 1282789, + MaximumRPCSlotsUsed: 0, + CumulativeSendingQueue: 0, + CumulativePendingQueue: 0, + ReadChunkCount: 107150285, + WriteChunkCount: 1226637531, + ReplyChunkCount: 2673889, + TotalRdmaRequest: 135120843409861, + PullupCopyCount: 135119397156505, + HardwayRegisterCount: 266368832, + FailedMarshalCount: 75716996, + BadReplyCount: 0, + MrsRecovered: 7853, + MrsOrphaned: 0, + MrsAllocated: 0, + EmptySendctxQ: 0, + TotalRdmaReply: 0, + FixupCopyCount: 119328, + ReplyWaitsForSend: 1336431717, + LocalInvNeeded: 0, + NomsgCallCount: 96, + BcallCount: 0, + }, }, }, }},