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

Add new follow method #386

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Add new follow method #386

wants to merge 6 commits into from

Conversation

maGitty
Copy link

@maGitty maGitty commented Dec 17, 2021

First, thanks a lot for providing this interface to systemd, I currently use it to synchronise the journal of multiple devices with an external remote.

The recent follow method didn't work as I wanted it for my use case to due to various reasons:

  • After each wait, only one one journal entry was written to the writer
    • So, if more than one entry adds to the journal within the specified 100ms, the journal stays behind the tail
  • The formatter hook is quite extensible, but channels might give slightly higher flexibility
  • Skipping entries manually from outside is not possible

Copy link
Contributor

@lucab lucab left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!
While the features seem useful, the implementation of FollowTail especially may need a bit of re-design.
Also, I'd be happy if this can be covered by some basic test just for sanity.

@@ -256,6 +256,48 @@ process:
}
}

// SkipN skips the next n entries and returns the number of skipped entries and an eventual error.
func (r *JournalReader) SkipN(n int) (int, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it may be useful here to check that n >= 0.

// SkipN skips the next n entries and returns the number of skipped entries and an eventual error.
func (r *JournalReader) SkipN(n int) (int, error) {
var i int
for i := 1; i <= n; i++ {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious, why doesn't this start at i := 0? Let's maybe change to that, as it may be less surprising to read, right?

Copy link
Author

Choose a reason for hiding this comment

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

Didn't notice until you mentioned it, but it really looks kind of messy! Thanks.


// FollowTail synchronously follows the JournalReader, writing each new journal entry to entries.
// It will start from the next unread entry.
func (r *JournalReader) FollowTail(entries chan *JournalEntry) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not overly positive with this proposed signature, as it lacks at least a Context to cancel the inner looping logic.
Additionally, I'm wondering whether it is better to return two channels (entries and err) so that the whole follow-tailing logic can be handled asynchronously.

@maGitty
Copy link
Author

maGitty commented Mar 31, 2022

Thanks a lot for your suggestions @lucab! I implemented some of them already and will come back for the rest soon. Especially enabling better asynchronous behaviour of the FollowTail method will surely increase the number of possible use cases.

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.

None yet

2 participants