Skip to content
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

[RFC] core: notify plugins when a log line is emitted #6990

Merged

Conversation

vincenzopalazzo
Copy link
Collaborator

@vincenzopalazzo vincenzopalazzo commented Jan 11, 2024

While our logging is super flexible, we are missing a feature to give the power to a plugin to be notified about logging.

This is useful when you are deploying core lightning in production and want a dashboard where it is possible to monitor the log with proper tools like Graphana, or tracing information with a framework like open telemetry

@vincenzopalazzo vincenzopalazzo added this to the v24.02 milestone Jan 11, 2024
@vincenzopalazzo vincenzopalazzo force-pushed the macros/notify-logs branch 2 times, most recently from 832805a to e46eb96 Compare January 12, 2024 15:08
@vincenzopalazzo vincenzopalazzo changed the title core: notify plugins when a log line is emitted [RFC] core: notify plugins when a log line is emitted Jan 12, 2024
Copy link
Member

@cdecker cdecker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies for reviewing a draft, but the PR caught my attention, since it's something I have been looking into as well.

The choice of augmenting the warning notification seems a bit strange, shouldn't the log topic contain all logs, and warning logs be replicated. We should try to avoid coupling semantics of different things together.

One major issue with the log notification is the fact that it trivially produces infinite recursions: print a log line while handling a log notification and voila, you just caused a deadlock in the form of an infinite recursion.

We should track the origin of logs, and not deliver logs originating from log subscribers to other log subscribers. That even fixes the problem of two plugins playing seesaw, by seeing each other's log messages produced during log processing :-)

lightningd/notification.c Outdated Show resolved Hide resolved
lightningd/plugin.c Outdated Show resolved Hide resolved
@cdecker
Copy link
Member

cdecker commented Jan 15, 2024

Also, this is a draft, so please do not attach a milestone to it. Milestones are for the release captain to signal their intent to include a PR in a release, not for maintainers and developers to just tag and throw things over the wall.

@cdecker cdecker removed this from the v24.02 milestone Jan 15, 2024
@vincenzopalazzo
Copy link
Collaborator Author

Also, this is a draft, so please do not attach a milestone to it. Milestones are for the release captain to signal their intent to include a PR in a release

I forgot to turn on this, I was fighting with the CI and did not realize that the last push was finding the CI. So I guess this is ready to be review and I would love that you consider the inclusion inside this release if possible 😄

@vincenzopalazzo vincenzopalazzo marked this pull request as ready for review January 15, 2024 17:02
@vincenzopalazzo
Copy link
Collaborator Author

One major issue with the log notification is the fact that it trivially produces infinite recursions: print a log line while handling a log notification and voila, you just caused a deadlock in the form of an infinite recursion.

Yes but this is true also for hooks, we can write the hook in a way that will create a loop.

The idea here for this PoC is that the log notification needs to be specified by the user so the user should be able to not log in to this function. An example that I am thinking of is a programmer who writes an infinite recursion.

OFC I can add a /* FIXME: ... */ there and we can try to implement your tracking call proposal?

@cdecker
Copy link
Member

cdecker commented Jan 15, 2024

I don't think that'll be necessary. These deadlocks should be pretty evident, and we can add the extra warning later.

I'd still like the warnings to also end up in the log topic, so please decouple log and warning notifications and then I'm very happy with this PR 👍

@cdecker cdecker self-assigned this Jan 15, 2024
@vincenzopalazzo
Copy link
Collaborator Author

vincenzopalazzo commented Jan 15, 2024

I'd still like the warnings to also end up in the log topic, so please decouple log and warning notifications and then I'm very happy with this PR 👍

Thank you. I would like to clarify that the warning should be replicated with the previous body, and a new log notification should also be emitted for the warning log, right?

Copy link
Member

@cdecker cdecker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please decouple the log from the warning topic. log should contain every log event, while warning should receive only a subset of the logs. We can add deadlock-protection in a separate step.

@vincenzopalazzo vincenzopalazzo force-pushed the macros/notify-logs branch 5 times, most recently from 8faf8a8 to d9ad513 Compare January 17, 2024 16:04
@vincenzopalazzo
Copy link
Collaborator Author

Ok @cdecker this should be ready for another review, sorry for the delay

plugins/libplugin.c Outdated Show resolved Hide resolved
@vincenzopalazzo vincenzopalazzo force-pushed the macros/notify-logs branch 2 times, most recently from 9fa51d3 to 034b858 Compare January 27, 2024 19:37
@vincenzopalazzo
Copy link
Collaborator Author

Review addressed @cdecker

Rebased to resolve some conflicts too!

@vincenzopalazzo vincenzopalazzo force-pushed the macros/notify-logs branch 4 times, most recently from d3ec95a to a31e313 Compare January 28, 2024 09:59
@vincenzopalazzo
Copy link
Collaborator Author

Trivial rebase to resolve the common/Makefile conflicts

@vincenzopalazzo
Copy link
Collaborator Author

Trivial Rebase and I think this is ready for considering the inclusion

I don't think that'll be necessary. These deadlocks should be pretty evident, and we can add the extra warning later.

I am using this assumption and trying to fix the recursion later, for the simple fact that we have these recursion problems also for hooks, so we should design a detect loop solution that will work also for hooks, but IMHO this is unrelated to this PR

Currently make a plugin that do reportings of logs on
a services like graphana is not possible. So this commit
include the possibility to write a plugin that do the report
of this analisys.

Changelog-Added: core: notify plugins when a log line is emitted.
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
Changelog-None: docs: adds documentation about the log notification
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
@endothermicdev endothermicdev merged commit b5cfd98 into ElementsProject:master May 17, 2024
32 of 35 checks passed
@vincenzopalazzo vincenzopalazzo deleted the macros/notify-logs branch May 17, 2024 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants