-
Notifications
You must be signed in to change notification settings - Fork 26
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
Journal probe rework #7
Conversation
92059d7
to
6f80467
Compare
src/probes/journal.c
Outdated
// The three highest log levels, all indicating errors | ||
MATCH("PRIORITY=1"); | ||
MATCH("PRIORITY=2"); | ||
MATCH("PRIORITY=3"); | ||
OR; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps name-space the macros (JOURNAL_MATCH), (JOURNAL_AND) etc...
Have a comment summarizing boolean logic (boot_id & (1 || 2 || 3 || exited)
Unit tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I renamed the macros and added documentation for the logical expression.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The journal probe is in the same boat as the crash probe... No unit tests are written for either because they rely on system libraries for most of their operation, and I'm not sure how I would go about mocking everything for the tests.
The error case is negative, so fix the return code conditional check appropriately. Signed-off-by: Patrick McCarty <[email protected]>
Previous behavior was to only filter LOG_ERR messages from the telemetrics crashprobe, but it will be helpful to make this probe more generic to capture log messages with the highest log levels. Signed-off-by: Patrick McCarty <[email protected]>
The make payloads more legible, make sure separate messages are newline separated. Signed-off-by: Patrick McCarty <[email protected]>
Signed-off-by: Patrick McCarty <[email protected]>
To avoid having to read the repetitive error handling when adding journal filters, add some helper macros. Signed-off-by: Patrick McCarty <[email protected]>
Signed-off-by: Patrick McCarty <[email protected]>
This field appears to be set when services fail, so filter on it as well. Signed-off-by: Patrick McCarty <[email protected]>
The previous logic concatenates log messages on initial startup, when the entire journal is read to process existing messages. But doing so might run into the payload size limit (8KB), and thus fail to create a record. Sending one record per log message will ensure that the payload size remains relatively small, almost always below the 8KB size limit. Signed-off-by: Patrick McCarty <[email protected]>
I omitted log level 0 from the filter, so add it here. Signed-off-by: Patrick McCarty <[email protected]>
Signed-off-by: Patrick McCarty <[email protected]>
6f80467
to
15bdcf0
Compare
src/probes/journal.c
Outdated
return false; | ||
} | ||
|
||
r = sd_journal_add_match(journal, "PRIORITY=2", 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I sense a configuration option and a loop eventually for this code ala:
telemetrics.conf: journal-log-level = X
for (int i = 1; i < atoi(X); i++) { sd_journal_add_match }
kind of thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A config option would be helpful, I agree. I opened #12 for tracking.
r = sd_journal_add_match(journal, data, 0); \ | ||
if (r < 0) { \ | ||
tm_journal_match_err(r); \ | ||
return false; \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Always a little scary when the macro can return in some cases but in this case it seems reasonable enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. In this case, sd_journal_add_match
and friends returning an error is very unlikely, so I figured the returns here would be acceptable for unlikely conditions.
src/probes/journal.c
Outdated
// The three highest log levels, all indicating errors | ||
JOURNAL_MATCH("PRIORITY=1"); | ||
JOURNAL_MATCH("PRIORITY=2"); | ||
JOURNAL_MATCH("PRIORITY=3"); | ||
JOURNAL_OR; | ||
// Only set for service-level error conditions | ||
JOURNAL_MATCH("EXIT_CODE=exited"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this confuses me a little. I'd expect exited to be a possible issue assuming non zero exit but looking at:
journalctl -F EXIT_CODE
dumped
exited
killed
I'd assume we may want to look at the dumped and killed case potentially too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, interesting. In my testing, I only encountered "exited", but I didn't inspect the source to see what other values it accepts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Filed an issue for this (#13)
// For now, we send one record per log message, in case the | ||
// there is a large backlog of messages and we exceed the | ||
// payload size limit (8KB). And ignore errors, hoping that it's | ||
// a transient problem. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine as we can try to put things back together server side. Though could we have a message-id + optional message part X/Y type thing? It would really make things easier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking of using the telemetry machine-id + client record timestamp fields to piece together a series of journal probe records. Would that be acceptable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yea that should work just as well. Drinking from the firehouse of the full log will always be a little tricky.
|
||
if (!send_data(error_class)) { | ||
telem_log(LOG_ERR, "Failed to send data. Ignoring.\n"); | ||
return num_entries; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I am a little worried about this as the function doesn't seem to take a last tried value so I'm unsure how well this would handle an error in the middle of sending messages and resuming from that point later on.
src/probes/journal.c
Outdated
} | ||
|
||
if (!payload) { | ||
} else if (ret == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah if I would have read a little further on I'd have seen it.
So I'm wondering if before returning when send_data fails, we could put the data back onto the journal so it can be attempted to be read next time.
Also ret could be 0 when send_data fails so the no existing entries log message would be wrong. I'd return -1 in the send_data case and hopefully there is a way to get data back into the journal after pulling it out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an excellent observation. I wasn't considering how the probe should behave in the event of send_data
failures. I suppose I could call sd_journal_previous
to move the pointer in the reverse direction in this case, but a timeout would be needed...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, I think that I want to continue ignoring send_data
failures for now, since this may indicate a configuration problem with the telemetry client on the system. Also, I think it's acceptable for the journal probe to be "lossy" with respect to the data it collects.
But I will revisit the error handling here later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll remove the LOG_DEBUG you mentioned.
A return value of 0 can also indicate send_data() failure, so remove this log message. Signed-off-by: Patrick McCarty <[email protected]>
This series reworks the existing journal probe to make it more generic, able to capture error log messages for any service, not just the crashprobe.