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

sdjournal: please add support for journal namespaces #413

Open
klaernie opened this issue Nov 9, 2022 · 2 comments · May be fixed by #421
Open

sdjournal: please add support for journal namespaces #413

klaernie opened this issue Nov 9, 2022 · 2 comments · May be fixed by #421

Comments

@klaernie
Copy link

klaernie commented Nov 9, 2022

I am using sdjournal indirectly with the filebeat journald input, and was wondering if reading from a non-default journald namespace is supported directly. I know that I can point filebeat to the namespace's systemd.journal file residing in /var/lib/journal/machine-id.namespace, but this requires knowledge of the machine-id for each individual server.
I solved the problem for our system by symlinking the machine-id.namespace directory to a machine-independent path, but this still feels hacked together.

Looking at the code it doesn't seem like, so I just wanted to confirm.

Thanks a lot and all the best!

@lucab lucab changed the title sdjournal: is reading from journald namespaces supported? sdjournal: please add support for journal namespaces Nov 10, 2022
@lucab
Copy link
Contributor

lucab commented Nov 10, 2022

Good question! There are multiple levels to cover on this:

  • The sdjournal package is built on top of C primitives provided by libsystemd.so, so it could in theory support namespaced journals without much troubles by wrapping the relevant API.
  • It looks like we are not currently binding the libsystemd function sd_journal_open_namespace() to a Go wrapper. This is likely not on purpose, but because the Go package is older than the journal namespace logic.
  • We should add a NewJournalFromNamespace(...) wrapper (or similar name), I've retitled this ticket accordingly. I don't currently have bandwidth to tackle this myself this month, but I can happily review PRs.
  • The sd_journal_open_namespace() API has been added only recently in systemd (>= 245, 2020/03). We'll need to make consumers aware that this helper won't work or be available on older environments.

@klaernie
Copy link
Author

Thanks for letting me know!

While I'd love to just dig in and implement this, I sadly have no golang skills, but I don't expect you or any contributor to jump at that anyway.

Regarding the behaviour with systemd<245 I'd probably just expect a "does not exist" error, after all you only start reading logs from a namespace if you already write to one, which wouldn't work there as well (I even had to make a minor OS upgrade to get a namespaced journal available for my application). So unless the golang-c interaction breaks on that I'd consider this all the awareness needed.

igor-tsiglyar pushed a commit to igor-tsiglyar/go-systemd that referenced this issue May 17, 2023
wrap sd_journal_open_namespace C call to enable reading
journal records in non-default namespace

fixes coreos#413
igor-tsiglyar pushed a commit to igor-tsiglyar/go-systemd that referenced this issue Jun 5, 2023
wrap sd_journal_open_namespace C call to enable reading
journal records in non-default namespace

fixes coreos#413
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 a pull request may close this issue.

2 participants