Skip to content

Commit 379c323

Browse files
committed
chore: fix formatting
1 parent 539c2f8 commit 379c323

File tree

2 files changed

+11
-48
lines changed

2 files changed

+11
-48
lines changed

libp2p/metrics/bandwidth.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import asyncio
21
from prometheus_client import Counter
32

43

@@ -8,7 +7,6 @@ class BandwidthMetrics:
87
"""
98

109
def __init__(self):
11-
1210
self.bandwidth = Counter(
1311
"libp2p_bandwidth_bytes_total",
1412
"Bandwidth usage by direction and protocol stack",
@@ -70,7 +68,6 @@ def __init__(self, transport, metrics: BandwidthMetrics):
7068
self.metrics = metrics
7169

7270
async def dial(self, addr, protocols):
73-
7471
stream = await self.transport.dial(addr)
7572

7673
return InstrumentedStream(
@@ -80,11 +77,10 @@ async def dial(self, addr, protocols):
8077
)
8178

8279
async def accept(self, protocols):
83-
8480
stream = await self.transport.accept()
8581

8682
return InstrumentedStream(
8783
stream,
8884
self.metrics,
8985
protocols,
90-
)
86+
)

libp2p/metrics/swarm.py

Lines changed: 10 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import time
2+
23
from prometheus_client import Counter, Histogram
34

45

@@ -9,7 +10,6 @@ class SwarmMetrics:
910
"""
1011

1112
def __init__(self):
12-
1313
# ---------------------------
1414
# incoming connections
1515
# ---------------------------
@@ -40,19 +40,14 @@ def __init__(self):
4040
"swarm_connections_establishment_duration_seconds",
4141
"Time taken to establish connection",
4242
["role", "protocols"],
43-
buckets=(
44-
0.01, 0.02, 0.05, 0.1,
45-
0.2, 0.5, 1, 2, 5, 10
46-
),
43+
buckets=(0.01, 0.02, 0.05, 0.1, 0.2, 0.5, 1, 2, 5, 10),
4744
)
4845

4946
self.connections_duration = Histogram(
5047
"swarm_connections_duration_seconds",
5148
"Time a connection was alive",
5249
["role", "protocols", "cause"],
53-
buckets=(
54-
0.01, 0.1, 1, 5, 10, 30, 60, 300, 600
55-
),
50+
buckets=(0.01, 0.1, 1, 5, 10, 30, 60, 300, 600),
5651
)
5752

5853
# ---------------------------
@@ -135,11 +130,9 @@ def record(self, event):
135130
"""
136131
Record a SwarmEvent-like object.
137132
"""
138-
139133
etype = event["type"]
140134

141135
if etype == "ConnectionEstablished":
142-
143136
role = event["role"]
144137
protocols = event["protocols"]
145138
conn_id = event["connection_id"]
@@ -158,7 +151,6 @@ def record(self, event):
158151
self.connections[conn_id] = time.time()
159152

160153
elif etype == "ConnectionClosed":
161-
162154
conn_id = event["connection_id"]
163155
role = event["role"]
164156
protocols = event["protocols"]
@@ -174,65 +166,40 @@ def record(self, event):
174166
).observe(elapsed)
175167

176168
elif etype == "IncomingConnection":
177-
178-
self.connections_incoming.labels(
179-
protocols=event["protocols"]
180-
).inc()
169+
self.connections_incoming.labels(protocols=event["protocols"]).inc()
181170

182171
elif etype == "IncomingConnectionError":
183-
184172
self.connections_incoming_error.labels(
185173
error=event["error"],
186174
protocols=event["protocols"],
187175
).inc()
188176

189177
elif etype == "OutgoingConnectionError":
190-
191178
self.outgoing_connection_error.labels(
192179
peer=event["peer"],
193180
error=event["error"],
194181
).inc()
195182

196183
elif etype == "NewListenAddr":
197-
198-
self.new_listen_addr.labels(
199-
protocols=event["protocols"]
200-
).inc()
184+
self.new_listen_addr.labels(protocols=event["protocols"]).inc()
201185

202186
elif etype == "ExpiredListenAddr":
203-
204-
self.expired_listen_addr.labels(
205-
protocols=event["protocols"]
206-
).inc()
187+
self.expired_listen_addr.labels(protocols=event["protocols"]).inc()
207188

208189
elif etype == "ListenerClosed":
209-
210-
self.listener_closed.labels(
211-
protocols=event["protocols"]
212-
).inc()
190+
self.listener_closed.labels(protocols=event["protocols"]).inc()
213191

214192
elif etype == "ListenerError":
215-
216193
self.listener_error.inc()
217194

218195
elif etype == "Dialing":
219-
220196
self.dial_attempt.inc()
221197

222198
elif etype == "NewExternalAddrCandidate":
223-
224-
self.external_addr_candidates.labels(
225-
protocols=event["protocols"]
226-
).inc()
199+
self.external_addr_candidates.labels(protocols=event["protocols"]).inc()
227200

228201
elif etype == "ExternalAddrConfirmed":
229-
230-
self.external_addr_confirmed.labels(
231-
protocols=event["protocols"]
232-
).inc()
202+
self.external_addr_confirmed.labels(protocols=event["protocols"]).inc()
233203

234204
elif etype == "ExternalAddrExpired":
235-
236-
self.external_addr_expired.labels(
237-
protocols=event["protocols"]
238-
).inc()
205+
self.external_addr_expired.labels(protocols=event["protocols"]).inc()

0 commit comments

Comments
 (0)