zero mtime when a fallback check fails (#19740)
* zero mtime when a fallback check fails * increase the number of dedup items to 20
Costa Tsaousis committed
Mar 1, 2025 at 17:30 UTC
eed19849d27ca3692f5221db603aa1988380b830
2 files changed
+10
-7
src/daemon/daemon-status-file.c
+9
-6
@@ -429,8 +429,10 @@ static bool check_status_file(const char *directory, char *filename, size_t file
429
430
// Get file metadata
431
OS_FILE_METADATA metadata = os_get_file_metadata(filename);
432
- if (!OS_FILE_METADATA_OK(metadata))
432
+ if (!OS_FILE_METADATA_OK(metadata)) {
433
+ *mtime = 0;
434
return false;
435
+ }
436
437
*mtime = metadata.modified_time;
438
return true;
@@ -646,6 +648,7 @@ static void dedup_keep_hash(DAEMON_STATUS_FILE *ds, XXH64_hash_t hash) {
648
// find the same hash
649
for(size_t i = 0; i < _countof(ds->dedup); i++) {
650
if(ds->dedup[i].hash == hash) {
651
+ ds->dedup[i].hash = hash;
652
ds->dedup[i].timestamp_ut = now_realtime_usec();
653
spinlock_unlock(&dsf_spinlock);
654
return;
@@ -669,8 +672,8 @@ static void dedup_keep_hash(DAEMON_STATUS_FILE *ds, XXH64_hash_t hash) {
672
store_at_slot = i;
673
}
674
672
- ds->dedup[store_at_slot].timestamp_ut = now_realtime_usec();
675
ds->dedup[store_at_slot].hash = hash;
676
+ ds->dedup[store_at_slot].timestamp_ut = now_realtime_usec();
677
678
spinlock_unlock(&dsf_spinlock);
679
}
@@ -682,7 +685,7 @@ struct post_status_file_thread_data {
685
const char *cause;
686
const char *msg;
687
ND_LOG_FIELD_PRIORITY priority;
685
- DAEMON_STATUS_FILE status;
688
+ DAEMON_STATUS_FILE *status;
689
};
690
691
void post_status_file(struct post_status_file_thread_data *d) {
@@ -691,7 +694,7 @@ void post_status_file(struct post_status_file_thread_data *d) {
694
buffer_json_member_add_string(wb, "exit_cause", d->cause); // custom
695
buffer_json_member_add_string(wb, "message", d->msg); // ECS
696
buffer_json_member_add_uint64(wb, "priority", d->priority); // custom
694
- daemon_status_file_to_json(wb, &d->status);
697
+ daemon_status_file_to_json(wb, d->status);
698
buffer_json_finalize(wb);
699
700
const char *json_data = buffer_tostring(wb);
@@ -709,7 +712,7 @@ void post_status_file(struct post_status_file_thread_data *d) {
712
713
CURLcode rc = curl_easy_perform(curl);
714
if(rc == CURLE_OK) {
712
- XXH64_hash_t hash = daemon_status_file_hash(&d->status, d->msg, d->cause);
715
+ XXH64_hash_t hash = daemon_status_file_hash(d->status, d->msg, d->cause);
716
dedup_keep_hash(&session_status, hash);
717
daemon_status_file_save(&session_status);
718
}
@@ -923,7 +926,7 @@ void daemon_status_file_check_crash(void) {
926
struct post_status_file_thread_data *d = calloc(1, sizeof(*d));
927
d->cause = strdupz(cause);
928
d->msg = strdupz(msg);
926
- d->status = last_session_status;
929
+ d->status = &last_session_status;
930
d->priority = pri.post;
931
nd_thread_create("post_status_file", NETDATA_THREAD_OPTION_DONT_LOG | NETDATA_THREAD_OPTION_DEFAULT, post_status_file_thread, d);
932
}
src/daemon/daemon-status-file.h
+1
-1
@@ -74,7 +74,7 @@ typedef struct daemon_status_file {
74
struct {
75
XXH64_hash_t hash;
76
usec_t timestamp_ut;
77
- } dedup[10];
77
+ } dedup[20];
78
} DAEMON_STATUS_FILE;
79
80
// loads the last status saved