protofsm: update GR Manager usage and start using structured logging#9342
protofsm: update GR Manager usage and start using structured logging#9342ellemouton merged 6 commits intolightningnetwork:masterfrom
Conversation
|
Important Review skippedAuto reviews are limited to specific labels. 🏷️ Labels to auto review (1)
Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
8c9dad2 to
2fefda4
Compare
| // TODO(roasbeef): could abstract further? | ||
| RegisterConfirmationsNtfn(txid *chainhash.Hash, pkScript []byte, | ||
| numConfs, heightHint uint32, | ||
| opts ...chainntnfs.NotifierOption, |
There was a problem hiding this comment.
Prob the main stylistic diff in the codebase rn, but I prefer this option as it makes it clearer where the args end, and the return value starts.
There was a problem hiding this comment.
Imo that only holds if the return values can in-fact fit on one line which is not always the case.
Personally I find the ) { on the unindented line strange
protofsm/state_machine.go
Outdated
| daemonEvent.TargetPeer.SerializeCompressed(), | ||
| lnutils.SpewLogClosure(daemonEvent.Msgs), | ||
| ) | ||
| log.DebugS(ctx, "Sending message", |
There was a problem hiding this comment.
Do you have a print sample of the before and after here re formatting?
There was a problem hiding this comment.
2024-12-10 13:20:44.552 [DBG]: FSM(test) Starting state machine
2024-12-10 13:20:44.552 [DBG]: FSM(test) Sending event event=(*protofsm.emitInternal)(0x1045f1240)({
})
2024-12-10 13:20:44.552 [DBG]: FSM(test) Applying new event event=(*protofsm.emitInternal)(0x1045f1240)({
})
2024-12-10 13:20:44.552 [DBG]: FSM(test) Processing event event=(*protofsm.emitInternal)(0x1045f1240)({
})
2024-12-10 13:20:44.552 [DBG]: FSM(test) Adding new internal event to queue event !BADKEY=(*protofsm.goToFin)(0x1045f1240)({
})
2024-12-10 13:20:44.552 [INF]: FSM(test) State transition from_state=*protofsm.dummyStateStart to_state=*protofsm.dummyStateStart
2024-12-10 13:20:44.552 [DBG]: FSM(test) Processing event event=(*protofsm.goToFin)(0x1045f1240)({
})
2024-12-10 13:20:44.552 [INF]: FSM(test) State transition from_state=*protofsm.dummyStateStart to_state=*protofsm.dummyStateFin
protofsm/state_machine.go
Outdated
| log.Debugf("FSM(%v): processing "+ | ||
| "daemon %v daemon events", | ||
| s.cfg.Env.Name(), len(dEvents)) | ||
| log.DebugS(ctx, "Processing daemon events", |
There was a problem hiding this comment.
Is this upper case construct something new we're attempting to make standard with the new logging format?
There was a problem hiding this comment.
I think in general we go for log lines that start with upper case? searching around the code base, i can see that most of our log lines start with an upper case letter
protofsm/state_machine.go
Outdated
| ctx context.Context) context.Context { | ||
|
|
||
| return btclog.WithCtx(ctx, | ||
| btclog.Fmt("fsm_name", s.cfg.Env.Name())) //nolint:govet |
There was a problem hiding this comment.
Is there anyway we can keep the old prefix nature? At least when scanning, IMO it's useful for it to be at the very start as depending on the size of your editor/viewport, the end of the line may require moving the cursor to actually view.
There was a problem hiding this comment.
as the library stands today, no. But what can be done is: to create a prefixed logger in NewStateMachine and then carry that around in the StateMachine struct. Then we just need to remember to do s.log.* for log lines.
shall we do that instead here?
There was a problem hiding this comment.
ok i've added a temporary commit at the end that does it this way. Let me know if you think this is ok and i can squash in the change.
The logs now look like this:
2024-12-10 13:20:44.552 [DBG]: FSM(test) Starting state machine
2024-12-10 13:20:44.552 [DBG]: FSM(test) Sending event event=(*protofsm.emitInternal)(0x1045f1240)({
})
2024-12-10 13:20:44.552 [DBG]: FSM(test) Applying new event event=(*protofsm.emitInternal)(0x1045f1240)({
})
2024-12-10 13:20:44.552 [DBG]: FSM(test) Processing event event=(*protofsm.emitInternal)(0x1045f1240)({
})
2024-12-10 13:20:44.552 [DBG]: FSM(test) Adding new internal event to queue event !BADKEY=(*protofsm.goToFin)(0x1045f1240)({
})
2024-12-10 13:20:44.552 [INF]: FSM(test) State transition from_state=*protofsm.dummyStateStart to_state=*protofsm.dummyStateStart
2024-12-10 13:20:44.552 [DBG]: FSM(test) Processing event event=(*protofsm.goToFin)(0x1045f1240)({
})
2024-12-10 13:20:44.552 [INF]: FSM(test) State transition from_state=*protofsm.dummyStateStart to_state=*protofsm.dummyStateFin
There was a problem hiding this comment.
squashed in the temp commit
ellemouton
left a comment
There was a problem hiding this comment.
Thanks for taking a look @Roasbeef - responded to your comments
protofsm/state_machine.go
Outdated
| log.Debugf("FSM(%v): processing "+ | ||
| "daemon %v daemon events", | ||
| s.cfg.Env.Name(), len(dEvents)) | ||
| log.DebugS(ctx, "Processing daemon events", |
There was a problem hiding this comment.
I think in general we go for log lines that start with upper case? searching around the code base, i can see that most of our log lines start with an upper case letter
protofsm/state_machine.go
Outdated
| ctx context.Context) context.Context { | ||
|
|
||
| return btclog.WithCtx(ctx, | ||
| btclog.Fmt("fsm_name", s.cfg.Env.Name())) //nolint:govet |
There was a problem hiding this comment.
as the library stands today, no. But what can be done is: to create a prefixed logger in NewStateMachine and then carry that around in the StateMachine struct. Then we just need to remember to do s.log.* for log lines.
shall we do that instead here?
2fefda4 to
a86da09
Compare
b0afb02 to
d9194ed
Compare
ellemouton
left a comment
There was a problem hiding this comment.
squashed in the prefixed logging change & also added the commit for using a pointer to the GM instead as discussed @Roasbeef. PTAL 🙏
d9194ed to
2625e95
Compare
| return StateMachine[Event, Env]{ | ||
| cfg: cfg, | ||
| cfg: cfg, | ||
| log: log.WithPrefix( |
go.mod
Outdated
|
|
||
| retract v0.0.2 | ||
|
|
||
| replace github.com/btcsuite/btclog/v2 => github.com/ellemouton/btclog/v2 v2.0.0-20241210110018-997ee6596623 |
There was a problem hiding this comment.
nit: just flagging so it not forgotten :)
There was a problem hiding this comment.
thanks yeah - luckily the linter wont ever let us forget these replaces :)
|
@ellemouton, remember to re-request review from reviewers when ready |
This bump includes a fix which prevents attribute value quoting if the value string contains a newline character. This is so that if we call spew.DumpS(), the output will stay nicely formatted. The update also includes a couple more Hex helpers which we can make use of now.
Update to use the latest version of the GoroutineManager which takes a context via the `Go` method instead of the constructor.
2625e95 to
c80651a
Compare
So that we dont have to remember to add the `FSM(%v)` prefix each time we write a log line.
c80651a to
5de4278
Compare
5de4278 to
42ce9d6
Compare
This PR touches the protofsm package for 2 reasons:
FSM(%V)string for each log lineDepends on: btcsuite/btclog#20