Skip to content

Commit f2cbb8d

Browse files
authored
Put images in log lines origin (#453)
* Put images in log lines * origin: use seconds for duration logging instead of milliseconds Standardize all duration log fields to use `duration_s` with `.Seconds()` instead of `duration_ms` with `.Milliseconds()` for consistency. Also adds debug logging for successful patch operations and clarifies cache miss log messages.
1 parent c22d364 commit f2cbb8d

File tree

4 files changed

+185
-34
lines changed

4 files changed

+185
-34
lines changed

lib/torrent/scheduler/connstate/state.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ func New(
9898
clk clock.Clock,
9999
localPeerID core.PeerID,
100100
netevents networkevent.Producer,
101-
logger *zap.SugaredLogger) *State {
102-
101+
logger *zap.SugaredLogger,
102+
) *State {
103103
config = config.applyDefaults()
104104

105105
return &State{
@@ -154,8 +154,7 @@ func (s *State) Blacklist(peerID core.PeerID, h core.InfoHash) error {
154154
}
155155
s.blacklist[k] = &blacklistEntry{s.clk.Now().Add(s.config.BlacklistDuration)}
156156

157-
s.log("peer", peerID, "hash", h).Infof(
158-
"Connection blacklisted for %s", s.config.BlacklistDuration)
157+
s.log("peer", peerID, "hash", h).Warnf("Connection blacklisted for %s", s.config.BlacklistDuration)
159158
s.netevents.Produce(
160159
networkevent.BlacklistConnEvent(h, s.localPeerID, peerID, s.config.BlacklistDuration))
161160

@@ -189,8 +188,7 @@ func (s *State) AddPending(peerID core.PeerID, h core.InfoHash, neighbors []core
189188
return ErrTooManyMutualConns
190189
}
191190
s.put(h, peerID, entry{status: _pending})
192-
s.log("hash", h, "peer", peerID).Infof(
193-
"Added pending conn, capacity now at %d", s.capacity(h))
191+
s.log("hash", h, "peer", peerID).Debugf("Added pending conn, capacity now at %d", s.capacity(h))
194192
return nil
195193
case _pending:
196194
return ErrConnAlreadyPending
@@ -207,7 +205,7 @@ func (s *State) DeletePending(peerID core.PeerID, h core.InfoHash) {
207205
return
208206
}
209207
s.delete(h, peerID)
210-
s.log("hash", h, "peer", peerID).Infof(
208+
s.log("hash", h, "peer", peerID).Debugf(
211209
"Deleted pending conn, capacity now at %d", s.capacity(h))
212210
}
213211

@@ -221,7 +219,7 @@ func (s *State) MovePendingToActive(c *conn.Conn) error {
221219
}
222220
s.put(c.InfoHash(), c.PeerID(), entry{status: _active, conn: c})
223221

224-
s.log("hash", c.InfoHash(), "peer", c.PeerID()).Info("Moved conn from pending to active")
222+
s.log("hash", c.InfoHash(), "peer", c.PeerID()).Debug("Moved conn from pending to active")
225223
s.netevents.Produce(networkevent.AddActiveConnEvent(c.InfoHash(), s.localPeerID, c.PeerID()))
226224

227225
return nil
@@ -240,8 +238,7 @@ func (s *State) DeleteActive(c *conn.Conn) {
240238
}
241239
s.delete(c.InfoHash(), c.PeerID())
242240

243-
s.log("hash", c.InfoHash(), "peer", c.PeerID()).Infof(
244-
"Deleted active conn, capacity now at %d", s.capacity(c.InfoHash()))
241+
s.log("hash", c.InfoHash(), "peer", c.PeerID()).Debugf("Deleted active conn, capacity now at %d", s.capacity(c.InfoHash()))
245242
s.netevents.Produce(networkevent.DropActiveConnEvent(
246243
c.InfoHash(), s.localPeerID, c.PeerID()))
247244
}

lib/torrent/scheduler/events.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ func (e incomingConnEvent) apply(s *state) {
189189
e.c.Close()
190190
return
191191
}
192-
s.log("conn", e.c).Info("Added incoming conn")
192+
s.log("conn", e.c).Debug("Added incoming conn")
193193
}
194194

195195
// failedOutgoingHandshakeEvent occurs when a pending incoming connection fails
@@ -416,16 +416,14 @@ func (e preemptionTickEvent) apply(s *state) {
416416
}
417417

418418
for h, ctrl := range s.torrentControls {
419-
idleSeeder :=
420-
ctrl.dispatcher.Complete() &&
421-
s.sched.clock.Now().Sub(ctrl.dispatcher.LastReadTime()) >= s.sched.config.SeederTTI
419+
idleSeeder := ctrl.dispatcher.Complete() &&
420+
s.sched.clock.Now().Sub(ctrl.dispatcher.LastReadTime()) >= s.sched.config.SeederTTI
422421
if idleSeeder {
423422
s.sched.torrentlog.SeedTimeout(ctrl.dispatcher.Digest(), h)
424423
}
425424

426-
idleLeecher :=
427-
!ctrl.dispatcher.Complete() &&
428-
s.sched.clock.Now().Sub(ctrl.dispatcher.LastWriteTime()) >= s.sched.config.LeecherTTI
425+
idleLeecher := !ctrl.dispatcher.Complete() &&
426+
s.sched.clock.Now().Sub(ctrl.dispatcher.LastWriteTime()) >= s.sched.config.LeecherTTI
429427
if idleLeecher {
430428
s.sched.torrentlog.LeechTimeout(ctrl.dispatcher.Digest(), h)
431429
}

0 commit comments

Comments
 (0)