Merge pull request #25096 from DaanDeMeyer/journald-log-fixes

journal: Ratelimit more journald log messages
This commit is contained in:
Daan De Meyer
2022-11-16 16:40:00 +01:00
committed by GitHub
12 changed files with 270 additions and 153 deletions
+36 -26
View File
@@ -4161,6 +4161,10 @@ int journal_file_get_cutoff_monotonic_usec(JournalFile *f, sd_id128_t boot_id, u
return 1;
}
/* Ideally this would be a function parameter but initializers for static fields have to be compile
* time constants so we hardcode the interval instead. */
#define LOG_RATELIMIT ((RateLimit) { .interval = 60 * USEC_PER_SEC, .burst = 3 })
bool journal_file_rotate_suggested(JournalFile *f, usec_t max_file_usec, int log_level) {
assert(f);
assert(f->header);
@@ -4178,25 +4182,27 @@ bool journal_file_rotate_suggested(JournalFile *f, usec_t max_file_usec, int log
if (JOURNAL_HEADER_CONTAINS(f->header, n_data))
if (le64toh(f->header->n_data) * 4ULL > (le64toh(f->header->data_hash_table_size) / sizeof(HashItem)) * 3ULL) {
log_full(log_level,
"Data hash table of %s has a fill level at %.1f (%"PRIu64" of %"PRIu64" items, %llu file size, %"PRIu64" bytes per hash table item), suggesting rotation.",
f->path,
100.0 * (double) le64toh(f->header->n_data) / ((double) (le64toh(f->header->data_hash_table_size) / sizeof(HashItem))),
le64toh(f->header->n_data),
le64toh(f->header->data_hash_table_size) / sizeof(HashItem),
(unsigned long long) f->last_stat.st_size,
f->last_stat.st_size / le64toh(f->header->n_data));
log_ratelimit_full(
log_level, LOG_RATELIMIT,
"Data hash table of %s has a fill level at %.1f (%"PRIu64" of %"PRIu64" items, %llu file size, %"PRIu64" bytes per hash table item), suggesting rotation.",
f->path,
100.0 * (double) le64toh(f->header->n_data) / ((double) (le64toh(f->header->data_hash_table_size) / sizeof(HashItem))),
le64toh(f->header->n_data),
le64toh(f->header->data_hash_table_size) / sizeof(HashItem),
(unsigned long long) f->last_stat.st_size,
f->last_stat.st_size / le64toh(f->header->n_data));
return true;
}
if (JOURNAL_HEADER_CONTAINS(f->header, n_fields))
if (le64toh(f->header->n_fields) * 4ULL > (le64toh(f->header->field_hash_table_size) / sizeof(HashItem)) * 3ULL) {
log_full(log_level,
"Field hash table of %s has a fill level at %.1f (%"PRIu64" of %"PRIu64" items), suggesting rotation.",
f->path,
100.0 * (double) le64toh(f->header->n_fields) / ((double) (le64toh(f->header->field_hash_table_size) / sizeof(HashItem))),
le64toh(f->header->n_fields),
le64toh(f->header->field_hash_table_size) / sizeof(HashItem));
log_ratelimit_full(
log_level, LOG_RATELIMIT,
"Field hash table of %s has a fill level at %.1f (%"PRIu64" of %"PRIu64" items), suggesting rotation.",
f->path,
100.0 * (double) le64toh(f->header->n_fields) / ((double) (le64toh(f->header->field_hash_table_size) / sizeof(HashItem))),
le64toh(f->header->n_fields),
le64toh(f->header->field_hash_table_size) / sizeof(HashItem));
return true;
}
@@ -4204,17 +4210,19 @@ bool journal_file_rotate_suggested(JournalFile *f, usec_t max_file_usec, int log
* longest chain is longer than some threshold, let's suggest rotation. */
if (JOURNAL_HEADER_CONTAINS(f->header, data_hash_chain_depth) &&
le64toh(f->header->data_hash_chain_depth) > HASH_CHAIN_DEPTH_MAX) {
log_full(log_level,
"Data hash table of %s has deepest hash chain of length %" PRIu64 ", suggesting rotation.",
f->path, le64toh(f->header->data_hash_chain_depth));
log_ratelimit_full(
log_level, LOG_RATELIMIT,
"Data hash table of %s has deepest hash chain of length %" PRIu64 ", suggesting rotation.",
f->path, le64toh(f->header->data_hash_chain_depth));
return true;
}
if (JOURNAL_HEADER_CONTAINS(f->header, field_hash_chain_depth) &&
le64toh(f->header->field_hash_chain_depth) > HASH_CHAIN_DEPTH_MAX) {
log_full(log_level,
"Field hash table of %s has deepest hash chain of length at %" PRIu64 ", suggesting rotation.",
f->path, le64toh(f->header->field_hash_chain_depth));
log_ratelimit_full(
log_level, LOG_RATELIMIT,
"Field hash table of %s has deepest hash chain of length at %" PRIu64 ", suggesting rotation.",
f->path, le64toh(f->header->field_hash_chain_depth));
return true;
}
@@ -4223,9 +4231,10 @@ bool journal_file_rotate_suggested(JournalFile *f, usec_t max_file_usec, int log
JOURNAL_HEADER_CONTAINS(f->header, n_fields) &&
le64toh(f->header->n_data) > 0 &&
le64toh(f->header->n_fields) == 0) {
log_full(log_level,
"Data objects of %s are not indexed by field objects, suggesting rotation.",
f->path);
log_ratelimit_full(
log_level, LOG_RATELIMIT,
"Data objects of %s are not indexed by field objects, suggesting rotation.",
f->path);
return true;
}
@@ -4236,9 +4245,10 @@ bool journal_file_rotate_suggested(JournalFile *f, usec_t max_file_usec, int log
t = now(CLOCK_REALTIME);
if (h > 0 && t > h + max_file_usec) {
log_full(log_level,
"Oldest entry in %s is older than the configured file retention duration (%s), suggesting rotation.",
f->path, FORMAT_TIMESPAN(max_file_usec, USEC_PER_SEC));
log_ratelimit_full(
log_level, LOG_RATELIMIT,
"Oldest entry in %s is older than the configured file retention duration (%s), suggesting rotation.",
f->path, FORMAT_TIMESPAN(max_file_usec, USEC_PER_SEC));
return true;
}
}