Skip to content

Commit

Permalink
respect flood protection configuration for daemon (netdata#19360)
Browse files Browse the repository at this point in the history
* respect flood protection configuration for daemon

* added journal message id for flood protection; netdata startup; added new systemd message id to journal annotations
  • Loading branch information
ktsaou authored Jan 9, 2025
1 parent b33416d commit ee9de67
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,9 @@ static void netdata_systemd_journal_message_ids_init(void) {
msgid_into_dict("a8fa8dacdb1d443e9503b8be367a6adb", "SysV Service Found");
msgid_into_dict("187c62eb1e7f463bb530394f52cb090f", "Portable Service attached");
msgid_into_dict("76c5c754d628490d8ecba4c9d042112b", "Portable Service detached");
msgid_into_dict("9cf56b8baf9546cf9478783a8de42113", "systemd-networkd sysctl changed by foreign process");
msgid_into_dict("ad7089f928ac4f7ea00c07457d47ba8a", "SRK into TPM authorization failure");
msgid_into_dict("b2bcbaf5edf948e093ce50bbea0e81ec", "Secure Attention Key (SAK) was pressed");

// dbus
// https://github.com/bus1/dbus-broker/blob/main/src/catalog/catalog-ids.h
Expand Down Expand Up @@ -606,12 +609,14 @@ static void netdata_systemd_journal_message_ids_init(void) {
msgid_into_dict("dd11929c788e48bdbb6276fb5f26b08a", "Boltd starting");

// Netdata
msgid_into_dict("1e6061a9fbd44501b3ccc368119f2b69", "Netdata startup");
msgid_into_dict("ed4cdb8f1beb4ad3b57cb3cae2d162fa", "Netdata connection from child");
msgid_into_dict("6e2e3839067648968b646045dbf28d66", "Netdata connection to parent");
msgid_into_dict("9ce0cb58ab8b44df82c4bf1ad9ee22de", "Netdata alert transition");
msgid_into_dict("6db0018e83e34320ae2a659d78019fb7", "Netdata alert notification");
msgid_into_dict("23e93dfccbf64e11aac858b9410d8a82", "Netdata fatal message");
msgid_into_dict("8ddaf5ba33a74078b609250db1e951f3", "Sensor state transition");
msgid_into_dict("ec87a56120d5431bace51e2fb8bba243", "Netdata log flood protection");
}

void netdata_systemd_journal_transform_message_id(FACETS *facets __maybe_unused, BUFFER *wb, FACETS_TRANSFORMATION_SCOPE scope __maybe_unused, void *data __maybe_unused) {
Expand Down
10 changes: 9 additions & 1 deletion src/daemon/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,15 @@ int netdata_main(int argc, char **argv) {

// initialize the log files
nd_log_initialize();
netdata_log_info("Netdata agent version '%s' is starting", NETDATA_VERSION);
{
ND_LOG_STACK lgs[] = {
ND_LOG_FIELD_UUID(NDF_MESSAGE_ID, &netdata_startup_msgid),
ND_LOG_FIELD_END(),
};
ND_LOG_STACK_PUSH(lgs);

netdata_log_info("Netdata agent version '%s' is starting", NETDATA_VERSION);
}

// ----------------------------------------------------------------------------------------------------------------
// global configuration
Expand Down
18 changes: 10 additions & 8 deletions src/libnetdata/log/nd_log-config.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,17 +191,19 @@ void nd_log_set_facility(const char *facility) {
}

void nd_log_set_flood_protection(size_t logs, time_t period) {
nd_log.sources[NDLS_DAEMON].limits.logs_per_period =
nd_log.sources[NDLS_DAEMON].limits.logs_per_period_backup;
nd_log.sources[NDLS_COLLECTORS].limits.logs_per_period =
nd_log.sources[NDLS_COLLECTORS].limits.logs_per_period_backup = logs;
// daemon logs
nd_log.sources[NDLS_DAEMON].limits.logs_per_period = logs;
nd_log.sources[NDLS_DAEMON].limits.logs_per_period_backup = logs;
nd_log.sources[NDLS_DAEMON].limits.throttle_period = period;

nd_log.sources[NDLS_DAEMON].limits.throttle_period =
nd_log.sources[NDLS_COLLECTORS].limits.throttle_period = period;
// collectors logs
nd_log.sources[NDLS_COLLECTORS].limits.logs_per_period = logs;
nd_log.sources[NDLS_COLLECTORS].limits.logs_per_period_backup = logs;
nd_log.sources[NDLS_COLLECTORS].limits.throttle_period = period;

char buf[100];
snprintfz(buf, sizeof(buf), "%" PRIu64, (uint64_t )period);
snprintfz(buf, sizeof(buf), "%" PRIu64, (uint64_t)period);
nd_setenv("NETDATA_ERRORS_THROTTLE_PERIOD", buf, 1);
snprintfz(buf, sizeof(buf), "%" PRIu64, (uint64_t )logs);
snprintfz(buf, sizeof(buf), "%" PRIu64, (uint64_t)logs);
nd_setenv("NETDATA_ERRORS_PER_PERIOD", buf, 1);
}
1 change: 1 addition & 0 deletions src/libnetdata/log/nd_log-internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ struct nd_log_source {
FILE *fp;

ND_LOG_FIELD_PRIORITY min_priority;
const nd_uuid_t *pending_msgid;
const char *pending_msg;
struct nd_log_limit limits;

Expand Down
7 changes: 7 additions & 0 deletions src/libnetdata/log/nd_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,12 +329,19 @@ static void nd_logger(const char *file, const char *function, const unsigned lon
.txt = nd_log.sources[source].pending_msg,
};

thread_log_fields[NDF_MESSAGE_ID].entry = (struct log_stack_entry){
.set = nd_log.sources[source].pending_msgid != NULL,
.type = NDFT_UUID,
.uuid = nd_log.sources[source].pending_msgid,
};

nd_logger_log_fields(spinlock, fp, false, priority, output,
&nd_log.sources[source],
thread_log_fields, THREAD_FIELDS_MAX);

freez((void *)nd_log.sources[source].pending_msg);
nd_log.sources[source].pending_msg = NULL;
nd_log.sources[source].pending_msgid = NULL;
}

errno_clear();
Expand Down
2 changes: 2 additions & 0 deletions src/libnetdata/log/nd_log_limit.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ bool nd_log_limit_reached(struct nd_log_source *source) {
freez((void *)source->pending_msg);

source->pending_msg = strdupz(buffer_tostring(wb));
source->pending_msgid = &log_flood_protection_msgid;
buffer_free(wb);
}

Expand Down Expand Up @@ -84,6 +85,7 @@ bool nd_log_limit_reached(struct nd_log_source *source) {
freez((void *)source->pending_msg);

source->pending_msg = strdupz(buffer_tostring(wb));
source->pending_msgid = &log_flood_protection_msgid;
buffer_free(wb);
}

Expand Down
2 changes: 2 additions & 0 deletions src/libnetdata/uuid/uuid.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ ND_UUID_DEFINE(health_alert_transition_msgid, 0x9c, 0xe0, 0xcb, 0x58, 0xab, 0x8b
// this is also defined in alarm-notify.sh.in
ND_UUID_DEFINE(health_alert_notification_msgid, 0x6d, 0xb0, 0x01, 0x8e, 0x83, 0xe3, 0x43, 0x20, 0xae, 0x2a, 0x65, 0x9d, 0x78, 0x01, 0x9f, 0xb7);
ND_UUID_DEFINE(sensors_state_transition_msgid, 0x8d, 0xda, 0xf5, 0xba, 0x33, 0xa7, 0x40, 0x78, 0xb6, 0x09, 0x25, 0x0d, 0xb1, 0xe9, 0x51, 0xf3);
ND_UUID_DEFINE(log_flood_protection_msgid, 0xec, 0x87, 0xa5, 0x61, 0x20, 0xd5, 0x43, 0x1b, 0xac, 0xe5, 0x1e, 0x2f, 0xb8, 0xbb, 0xa2, 0x43);
ND_UUID_DEFINE(netdata_startup_msgid, 0x1e, 0x60, 0x61, 0xa9, 0xfb, 0xd4, 0x45, 0x01, 0xb3, 0xcc, 0xc3, 0x68, 0x11, 0x9f, 0x2b, 0x69);

ND_UUID UUID_generate_from_hash(const void *payload, size_t payload_len);

Expand Down

0 comments on commit ee9de67

Please sign in to comment.