Fix: `swarm stats all` command
`swarm stats all` requires that the ResourceManager instance implements `rcmgr.ResourceManagerState`, and `loggingResourceManager` was not implementing it, so the command was failing. Also added a sharness test to check that the command is executing correctly, because `jq -e` doesn't return an error if the json is nil. Signed-off-by: Antonio Navarro Perez <antnavper@gmail.com>
Antonio Navarro Perez committed
Sep 28, 2022 at 16:03 UTC
bffc012c6b1cdbc29234fb110f94b1e87b509740
2 files changed
+39
core/node/libp2p/rcmgr_logging.go
+35
@@ -32,6 +32,7 @@ type loggingScope struct {
32
}
33
34
var _ network.ResourceManager = (*loggingResourceManager)(nil)
35
+var _ rcmgr.ResourceManagerState = (*loggingResourceManager)(nil)
36
37
func (n *loggingResourceManager) start(ctx context.Context) {
38
logInterval := n.logInterval
@@ -103,6 +104,40 @@ func (n *loggingResourceManager) Close() error {
104
return n.delegate.Close()
105
}
106
107
+func (n *loggingResourceManager) ListServices() []string {
108
+ rapi, ok := n.delegate.(rcmgr.ResourceManagerState)
109
+ if !ok {
110
+ return nil
111
+ }
112
+
113
+ return rapi.ListServices()
114
+}
115
+func (n *loggingResourceManager) ListProtocols() []protocol.ID {
116
+ rapi, ok := n.delegate.(rcmgr.ResourceManagerState)
117
+ if !ok {
118
+ return nil
119
+ }
120
+
121
+ return rapi.ListProtocols()
122
+}
123
+func (n *loggingResourceManager) ListPeers() []peer.ID {
124
+ rapi, ok := n.delegate.(rcmgr.ResourceManagerState)
125
+ if !ok {
126
+ return nil
127
+ }
128
+
129
+ return rapi.ListPeers()
130
+}
131
+
132
+func (n *loggingResourceManager) Stat() rcmgr.ResourceManagerStat {
133
+ rapi, ok := n.delegate.(rcmgr.ResourceManagerState)
134
+ if !ok {
135
+ return rcmgr.ResourceManagerStat{}
136
+ }
137
+
138
+ return rapi.Stat()
139
+}
140
+
141
func (s *loggingScope) ReserveMemory(size int, prio uint8) error {
142
err := s.delegate.ReserveMemory(size, prio)
143
s.countErrs(err)
test/sharness/t0139-swarm-rcmgr.sh
+4
@@ -55,6 +55,10 @@ test_expect_success 'ResourceMgr enabled: swarm limit' '
55
jq -e .StreamsOutbound < json
56
'
57
58
+test_expect_success 'connected: swarm stats all working properly' '
59
+ test_expect_code 0 ipfs swarm stats all
60
+'
61
+
62
# every scope has the same fields, so we only inspect System
63
test_expect_success 'ResourceMgr enabled: swarm stats' '
64
ipfs swarm stats all --enc=json | tee json &&