@cryptotaxi247 / netdata-1 / commits / a457dc733

status file timings per step (#19758)

post version_saved; calculate init/exit timings on the go; do not dedup if the version changed

Costa Tsaousis committed Mar 3, 2025 at 20:20 UTC a457dc733dd42b98e466a0cbb68b53a6c1b185bc
2 files changed +26 -17
src/daemon/daemon-status-file.c
+24 -15
@@ -38,6 +38,7 @@ ENUM_STR_MAP_DEFINE(DAEMON_OS_TYPE) = {
38 ENUM_STR_DEFINE_FUNCTIONS(DAEMON_OS_TYPE, DAEMON_OS_TYPE_UNKNOWN, "unknown");
39
40 static DAEMON_STATUS_FILE last_session_status = {
41 + .v = STATUS_FILE_VERSION,
42 .spinlock = SPINLOCK_INITIALIZER,
43 .fatal = {
44 .spinlock = SPINLOCK_INITIALIZER,
@@ -48,6 +49,7 @@ static DAEMON_STATUS_FILE last_session_status = {
49 };
50
51 static DAEMON_STATUS_FILE session_status = {
52 + .v = STATUS_FILE_VERSION,
53 .spinlock = SPINLOCK_INITIALIZER,
54 .fatal = {
55 .spinlock = SPINLOCK_INITIALIZER,
@@ -71,6 +73,7 @@ static XXH64_hash_t daemon_status_file_hash(DAEMON_STATUS_FILE *ds, const char *
73 CLEAN_BUFFER *wb = buffer_create(0, NULL);
74 buffer_json_initialize(wb, "\"", "\"", 0, true, BUFFER_JSON_OPTIONS_MINIFY);
75 buffer_json_member_add_uint64(wb, "version", STATUS_FILE_VERSION);
76 + buffer_json_member_add_uint64(wb, "version_saved", ds->v);
77 buffer_json_member_add_uuid(wb, "host_id", ds->host_id.uuid);
78 buffer_json_member_add_uuid(wb, "node_id", ds->node_id.uuid);
79 buffer_json_member_add_uuid(wb, "claim_id", ds->claim_id.uuid);
@@ -214,6 +217,7 @@ static bool daemon_status_file_from_json(json_object *jobj, void *data, BUFFER *
217 // change management, version to know which fields to expect
218 uint64_t version = 0;
219 JSONC_PARSE_UINT64_OR_ERROR_AND_RETURN(jobj, path, "version", version, error, true);
220 + ds->v = version;
221
222 bool strict = false; // allow missing fields and values
223 bool required_v1 = version >= 1 ? strict : false;
@@ -316,14 +320,15 @@ static bool daemon_status_file_from_json(json_object *jobj, void *data, BUFFER *
320 JSONC_PARSE_ARRAY(jobj, path, "dedup", error, required_v4, {
321 size_t i = 0;
322 JSONC_PARSE_ARRAY_ITEM_OBJECT(jobj, path, i, required_v4, {
319 - if(i >= _countof(ds->dedup.slot))
320 - break;
321 -
322 - JSONC_PARSE_TXT2CHAR_OR_ERROR_AND_RETURN(jobj, path, "@timestamp", datetime, error, required_v4);
323 - if (datetime[0])
324 - ds->dedup.slot[i].timestamp_ut = rfc3339_parse_ut(datetime, NULL);
325 -
326 - JSONC_PARSE_UINT64_OR_ERROR_AND_RETURN(jobj, path, "hash", ds->dedup.slot[i].hash, error, required_v4);
323 + if(i < _countof(ds->dedup.slot)) {
324 + datetime[0] = '\0';
325 + JSONC_PARSE_TXT2CHAR_OR_ERROR_AND_RETURN(jobj, path, "@timestamp", datetime, error, required_v4);
326 + if (datetime[0])
327 + ds->dedup.slot[i].timestamp_ut = rfc3339_parse_ut(datetime, NULL);
328 +
329 + JSONC_PARSE_UINT64_OR_ERROR_AND_RETURN(
330 + jobj, path, "hash", ds->dedup.slot[i].hash, error, required_v4);
331 + }
332 });
333 });
334 }
@@ -350,16 +355,16 @@ static void daemon_status_file_refresh(DAEMON_STATUS status) {
355 session_status.os_type = DAEMON_OS_TYPE_WINDOWS;
356 #endif
357
353 - if(session_status.status != DAEMON_STATUS_INITIALIZING && status == DAEMON_STATUS_INITIALIZING)
358 + if(!session_status.timings.init_started_ut)
359 session_status.timings.init_started_ut = now_ut;
360
356 - if(session_status.status != DAEMON_STATUS_EXITING && status == DAEMON_STATUS_EXITING)
361 + if(status == DAEMON_STATUS_EXITING && !session_status.timings.exit_started_ut)
362 session_status.timings.exit_started_ut = now_ut;
363
359 - if(session_status.status == DAEMON_STATUS_INITIALIZING && status == DAEMON_STATUS_RUNNING)
364 + if(session_status.status == DAEMON_STATUS_INITIALIZING)
365 session_status.timings.init = (time_t)((now_ut - session_status.timings.init_started_ut + USEC_PER_SEC/2) / USEC_PER_SEC);
366
362 - if(session_status.status == DAEMON_STATUS_EXITING && status == DAEMON_STATUS_EXITED)
367 + if(session_status.status == DAEMON_STATUS_EXITING)
368 session_status.timings.exit = (time_t)((now_ut - session_status.timings.exit_started_ut + USEC_PER_SEC/2) / USEC_PER_SEC);
369
370 strncpyz(session_status.version, NETDATA_VERSION, sizeof(session_status.version) - 1);
@@ -419,9 +424,12 @@ static void daemon_status_file_refresh(DAEMON_STATUS status) {
424 session_status.os_id_like = strdupz(last_session_status.os_id_like);
425 if(!session_status.restarts)
426 session_status.restarts = last_session_status.restarts + 1;
422 - if(!session_status.dedup.slot[0].timestamp_ut || !session_status.dedup.slot[0].hash) {
423 - for (size_t i = 0; i < _countof(session_status.dedup.slot); i++)
424 - session_status.dedup.slot[i] = last_session_status.dedup.slot[i];
427 +
428 + if(last_session_status.v == STATUS_FILE_VERSION) {
429 + if (!session_status.dedup.slot[0].timestamp_ut || !session_status.dedup.slot[0].hash) {
430 + for (size_t i = 0; i < _countof(session_status.dedup.slot); i++)
431 + session_status.dedup.slot[i] = last_session_status.dedup.slot[i];
432 + }
433 }
434
435 if(!session_status.install_type) {
@@ -753,6 +761,7 @@ void post_status_file(struct post_status_file_thread_data *d) {
761 buffer_json_member_add_string(wb, "exit_cause", d->cause); // custom
762 buffer_json_member_add_string(wb, "message", d->msg); // ECS
763 buffer_json_member_add_uint64(wb, "priority", d->priority); // custom
764 + buffer_json_member_add_uint64(wb, "version_saved", d->status->v); // custom
765 daemon_status_file_to_json(wb, d->status);
766 buffer_json_finalize(wb);
767
src/daemon/daemon-status-file.h
+2 -2
@@ -73,7 +73,7 @@ typedef struct daemon_status_file {
73 const char *function;
74 const char *errno_str;
75 const char *message;
76 - char stack_trace[4096];
76 + char stack_trace[2048];
77 char thread[ND_THREAD_TAG_MAX + 1];
78 } fatal;
79
@@ -82,7 +82,7 @@ typedef struct daemon_status_file {
82 struct {
83 XXH64_hash_t hash;
84 usec_t timestamp_ut;
85 - } slot[20];
85 + } slot[10];
86 } dedup;
87 } DAEMON_STATUS_FILE;
88