Repository navigation
fix(recording): log to stdout when not running under the systemd journal - #26111
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
WalkthroughThe shared logger selects Journald when Priority: ⬇️ Low Estimated code review effort: 3 (Moderate) | ~20 minutes Change: Bug fix Sequence Diagram(s)sequenceDiagram
participant Inbox as rap-caption-inbox
participant Logger as BigBlueButton.system_logger
participant Env as ENV
participant Journald as Journald::Logger
participant Stdout as StdoutLogger
Inbox->>Logger: request logger with identifier
Logger->>Env: check JOURNAL_STREAM
alt JOURNAL_STREAM is present
Logger->>Journald: create logger
Journald-->>Inbox: return logger
else JOURNAL_STREAM is absent
Logger->>Stdout: enable synchronized stdout and create logger
Stdout-->>Inbox: return logger
end
Suggested reviewers: Merge Risk: ⚪ Minimal · up to
|
TiagoJacobs
left a comment
There was a problem hiding this comment.
Thanks, the diagnosis is right: sd_journal_sendv returns 0 when the socket is missing, so the lines are lost silently. Two changes before this can go in.
1. Detect the journal through JOURNAL_STREAM instead of probing the socket path.
/run/systemd/journal/socket is a private constant of sd_journal_sendv, not an interface. systemd sets JOURNAL_STREAM for every unit whose stdout/stderr goes to the journal, and systemd.exec(5) documents it precisely for this purpose: letting a service upgrade to the native journal protocol. All three rap units use the default StandardOutput, so package installs keep the exact same Journald::Logger; without systemd we log to stdout. No copied path, no new config, and the journald_socket: keyword exists only for the tests and can go away (the test just sets the variable):
def self.system_logger(identifier)
return Journald::Logger.new(identifier) if ENV.key?('JOURNAL_STREAM')
$stdout.sync = true
StdoutLogger.new($stdout, progname: identifier)
end2. The stdout fallback has to implement tag and exception.
rap-caption-inbox.rb calls logger.tag(record_id: ...) do ... end (line 70) and logger.exception(e) (line 153). Plain Logger has neither, so in a container the first caption file raises NoMethodError outside any rescue and kills the inbox. These are the only journald-specific methods the record-and-playback code uses, so a small subclass is enough:
class StdoutLogger < Logger
def tag(**fields)
saved, @tags = @tags, (@tags || {}).merge(fields)
yield
ensure
@tags = saved
end
def exception(e)
error("#{e.class}: #{e.message}\n#{e.backtrace&.join("\n")}")
end
private
def format_message(severity, time, progname, msg)
msg = "#{msg} #{@tags.map { |k, v| "#{k}=#{v}" }.join(' ')}" if @tags&.any?
super
end
endTests: keep the stdout and sync cases, replace the UNIX socket case with JOURNAL_STREAM set, and add tag (fields present inside the block, gone after it) and exception. Set or delete JOURNAL_STREAM explicitly in each test and restore it in teardown, so the result does not depend on where the suite runs.
d90c6e6 to
8aa19de
Compare
|
Thanks, both applied in 8aa19de, with your code as written:
Tests ( I also rebased on the current |
TiagoJacobs
left a comment
There was a problem hiding this comment.
Thanks, this is what I had in mind. Two small things and I think it can go in.
The sync test does not test anything: StringIO#sync always returns true, so it passes with or without the $stdout.sync = true line. Swap the StringIO for a File in that one test, sync defaults to false there and flips to true after system_logger:
def test_stdout_logger_is_synced
ENV.delete('JOURNAL_STREAM')
$stdout = File.open(File::NULL, 'w')
BigBlueButton.system_logger('bbb-rap-test')
assert($stdout.sync, 'stdout must be synced so lines are not lost when the process is killed')
end(teardown already restores $stdout.)
I'd rather fix the two RuboCop offenses than mention them in the description, they are trivial:
def tag(**fields)
saved = @tags
@tags = (saved || {}).merge(fields)
yield
ensure
@tags = saved
end
def exception(exc)
error("#{exc.class}: #{exc.message}\n#{exc.backtrace&.join("\n")}")
endThen drop the "More" paragraph about RuboCop, and the per-file bullet list in the description too, the diff already says that. Please squash into one commit, the intermediate socket-probe version does not need to be in history, and mark the PR ready for review so CodeRabbit runs on it.
One thing I noticed but would leave alone: an exception object logged inside a tag block loses the class and backtrace, because the tags are appended before the formatter sees it. Nothing calls it that way today.
The recording services (rap-starter, the resque worker, the caption inbox) log only through Journald::Logger, which drops every line without an error when there is no journal, as in a container. BigBlueButton.system_logger returns the same Journald::Logger when JOURNAL_STREAM is set, which systemd does for every unit whose stdout/stderr goes to the journal (systemd.exec(5)), so package installs keep logging to journald. Otherwise it returns a StdoutLogger on a synced stdout: a Logger subclass with the journald-specific methods the recording code calls, tag (fields appended to the lines inside the block) and exception. BigBlueButton.logger and rap-caption-inbox.rb use it.
8aa19de to
7e6fc02
Compare
|
Done, squashed into a single commit on top of the current
|
|
Verified 7e6fc02 locally: the 5 logger tests pass, the sync test fails when the sync line is removed, no RuboCop offenses on the changed lines, and the full suite fails the same tests as the base branch. The only item left from my review is marking the PR ready for review so CodeRabbit runs; I'll approve once that and the CI run are through. |
|
The CI failure is the Playwright screenshare test "Hidden presentation stays hidden after screenshare ends when the slide has annotations" timing out in the legacy media job, flagged as flaky by the report itself and unrelated to this change (the same job passed on the previous commit of this PR). I re-ran the failed job. |
✅ Automated tests have passed! |
TiagoJacobs
left a comment
There was a problem hiding this comment.
Approved at 7e6fc02. Verified locally: the 5 logger tests pass, the sync test fails without the sync line, no RuboCop offenses on the changed lines, and the full suite fails the same tests as the base branch. CI is green after re-running the flaky screenshare job. I marked the PR ready for review so CodeRabbit runs on it; if it reports anything substantive, please address it before merge.
59d39ea
into
bigbluebutton:v4.0.x-develop
What does this PR do?
The recording processing services log only through
Journald::Logger(BigBlueButton.loggerinrecord-and-playback/core/lib/recordandplayback.rb, and the caption inbox inrap-caption-inbox.rb). Without a journal, as in a container,Journald::Loggerdrops every line without an error (sd_journal_sendvreturns 0 when the socket is missing), sorap-starter, the resque worker and the caption inbox run silently.This adds
BigBlueButton.system_logger(identifier). It returns the sameJournald::LoggerwhenJOURNAL_STREAMis set, which systemd does for every unit whose stdout/stderr goes to the journal (systemd.exec(5) documents it for exactly this upgrade to the native journal protocol). Otherwise it returns aStdoutLoggeron a synced stdout, tagged with the identifier, so the container runtime collects the lines. The rap units use the defaultStandardOutput, so package installs keep logging to journald exactly as before.StdoutLoggeris a smallLoggersubclass that implements the two journald-specific methods the recording code calls:tag(the fields are appended to the lines logged inside the block and removed after it) andexception(class, message and backtrace).rap-caption-inbox.rbuses both, so a plainLoggerwould raiseNoMethodErroron the first caption file.Closes Issue(s)
None.
Motivation
Found while running the recording services in containers:
rap-starterand the worker produced no output at all, which made processing failures impossible to follow. Container setups patch this line today (for example, the recordings mod of bigbluebutton/docker replaces the journald logger in both files with ased).How to test
In an environment without systemd (e.g. a
rubycontainer with the record-and-playback gems), fromrecord-and-playback/core:Journald::Loggerand the line is lost).I, [...] INFO -- bbb-rap: hello.The caption inbox logger keeps its tags:
prints
INFO -- bbb-rap-caption-inbox: caption processed record_id=abc.On a regular install the services run under systemd with
JOURNAL_STREAMset and keep logging to journald:journalctl -t bbb-rapshows the lines as before. WithJOURNAL_STREAM=8:1set,ruby -Ilib -e 'require "recordandplayback"; p BigBlueButton.logger.class'printsJournald::Logger.bundle exec rake testinrecord-and-playback/core:test_logger.rbpasses (5 runs).More
rake testalso reports a failure inTestEvents#test_enforce_cut_lengths_short_cut_start(edl/test_video.rb); it fails the same way on the base branch and is unrelated to this change.