-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
protofsm: update GR Manager usage and start using structured logging #9342
base: master
Are you sure you want to change the base?
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
protofsm/state_machine.go
Outdated
@@ -101,8 +102,8 @@ type DaemonAdapters interface { | |||
// TODO(roasbeef): could abstract further? | |||
RegisterConfirmationsNtfn(txid *chainhash.Hash, pkScript []byte, | |||
numConfs, heightHint uint32, | |||
opts ...chainntnfs.NotifierOption, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have a print sample of the before and after here re formatting?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
squashed in the temp commit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
squashed in the prefixed logging change & also added the commit for using a pointer to the GM instead as discussed @Roasbeef. PTAL 🙏
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.
So that we dont have to remember to add the `FSM(%v)` prefix each time we write a log line.
d9194ed
to
2625e95
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🩴
@@ -197,7 +200,10 @@ func NewStateMachine[Event any, Env Environment]( | |||
cfg StateMachineCfg[Event, Env]) StateMachine[Event, Env] { | |||
|
|||
return StateMachine[Event, Env]{ | |||
cfg: cfg, | |||
cfg: cfg, | |||
log: log.WithPrefix( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
@bhandras: review reminder |
This PR touches the protofsm package for 2 reasons:
FSM(%V)
string for each log lineDepends on: btcsuite/btclog#20