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

Support systemd without files #1286

Closed
roidelapluie opened this issue Nov 19, 2019 · 7 comments · Fixed by #1298
Closed

Support systemd without files #1286

roidelapluie opened this issue Nov 19, 2019 · 7 comments · Fixed by #1298
Assignees
Labels
component/agent type/enhancement Something existing could be improved

Comments

@roidelapluie
Copy link
Contributor

Currently promtail requires systemd to flush its files to disk.

As fluentbit is doing it, it is possible to read journald without requiring it to flush on disk.

@rfratto rfratto self-assigned this Nov 19, 2019
@rfratto
Copy link
Member

rfratto commented Nov 19, 2019

Could you provide any more information that might help me figure out what needs to be changed? I took a look at the fluentbit code and the only obvious difference I could find is that Promtail always calls sd_journal_open_directory, while fluentbit only calls it when an explicit path is provided.

@rfratto rfratto added component/agent type/enhancement Something existing could be improved labels Nov 19, 2019
@roidelapluie
Copy link
Contributor Author

I came to the same conclusion as you.

https://www.freedesktop.org/software/systemd/man/sd_journal_open.html

sd_journal_open()
SD_JOURNAL_RUNTIME_ONLY makes sure only volatile journal files will be opened, excluding those which are stored on persistent storage.

It means that sd_journal_open can read journald volatiles logs (not persisted to disk)

@roidelapluie
Copy link
Contributor Author

One good reason to support this is that it is Red Hat Entreprise Linux 7 default.

@rfratto
Copy link
Member

rfratto commented Nov 19, 2019

Gotcha, thanks for the help. Looking into it more, it's not necessarily the flags that you pass (fluentbit hard-coded SD_JOURNAL_LOCAL_ONLY), but it's that when sd_journal_open_directory is called, the volatile logs aren't read.

See add_search_paths for how systemd reads volatile logs, and how sd_journal_open_directory won't call that function if a path is provided.

I'll work on a PR for this tomorrow. Thanks for reporting!

@roidelapluie
Copy link
Contributor Author

Yes I pasted the flag because it mentions volatile logs, we don't need it.

Also in RHEL7 there is no /var/log/journal by default so promtail-journal does not work out of the box here.

@roidelapluie
Copy link
Contributor Author

Ok, so in my case I could use /run/log/journal to read those logs with loki.

@roidelapluie
Copy link
Contributor Author

for the record:

- job_name: journal
  journal:
    path: /run/log/journal
    labels:
      job: journal

works

rfratto added a commit to rfratto/loki that referenced this issue Nov 25, 2019
The forced default path for the journal target (/var/log/journal) did
not apply to all Linux systems: systemd actually defaults to reading
from _two_ default paths: /var/log/journal and /run/log/journal. Not
setting an explicit default will enable both of those paths to be
searched for journal logs.

The comment mentioning the local machine ID was technically accurate,
but is normally dealt with by bind mounting /etc/machine-id. That's the
standard approach for running fluent-bit in a container, and should be
the standard approach for Promtail as well.

Fixes grafana#1286.
rfratto added a commit that referenced this issue Nov 25, 2019
* pkg/promtail: remove journal target forced path

The forced default path for the journal target (/var/log/journal) did
not apply to all Linux systems: systemd actually defaults to reading
from _two_ default paths: /var/log/journal and /run/log/journal. Not
setting an explicit default will enable both of those paths to be
searched for journal logs.

The comment mentioning the local machine ID was technically accurate,
but is normally dealt with by bind mounting /etc/machine-id. That's the
standard approach for running fluent-bit in a container, and should be
the standard approach for Promtail as well.

Fixes #1286.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/agent type/enhancement Something existing could be improved
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants