@cryptotaxi247 / netdata-1 / commits / 1b7c15ac0

journal timeout (#16195)

* stop the query 250ms before the timeout, to allow sending back partial responses * on timeout return partial responses * give it 500ms * give some additional timeout to plugins.d garbage collection * define an extension to the timeout for all intermediate hops * hunting for the crash... * set value name and len to zero * remove unneeded memset()

Costa Tsaousis committed Oct 14, 2023 at 16:03 UTC 1b7c15ac09de02b1adf62ebd6d4d4e2f1ee0b707
5 files changed +30 -26
collectors/plugins.d/pluginsd_parser.c
+1 -1
@@ -965,7 +965,7 @@ static int pluginsd_function_execute_cb(BUFFER *result_body_wb, int timeout, con
965
966 struct inflight_function tmp = {
967 .started_ut = now,
968 - .timeout_ut = now + timeout * USEC_PER_SEC,
968 + .timeout_ut = now + timeout * USEC_PER_SEC + RRDFUNCTIONS_TIMEOUT_EXTENSION_UT,
969 .result_body_wb = result_body_wb,
970 .timeout = timeout,
971 .function = string_strdupz(function),
collectors/systemd-journal.plugin/systemd-journal.c
+2 -2
@@ -101,7 +101,7 @@ int fstat64(int fd, struct stat64 *buf) {
101
102 #define SYSTEMD_JOURNAL_FUNCTION_DESCRIPTION "View, search and analyze systemd journal entries."
103 #define SYSTEMD_JOURNAL_FUNCTION_NAME "systemd-journal"
104 -#define SYSTEMD_JOURNAL_DEFAULT_TIMEOUT 55
104 +#define SYSTEMD_JOURNAL_DEFAULT_TIMEOUT 60
105 #define SYSTEMD_JOURNAL_MAX_PARAMS 100
106 #define SYSTEMD_JOURNAL_DEFAULT_QUERY_DURATION (1 * 3600)
107 #define SYSTEMD_JOURNAL_DEFAULT_ITEMS_PER_QUERY 200
@@ -2155,7 +2155,7 @@ static void function_systemd_journal(const char *transaction, char *function, in
2155 FUNCTION_QUERY_STATUS tmp_fqs = {
2156 .cancelled = cancelled,
2157 .started_monotonic_ut = now_monotonic_ut,
2158 - .stop_monotonic_ut = now_monotonic_ut + timeout * USEC_PER_SEC,
2158 + .stop_monotonic_ut = now_monotonic_ut + (timeout * USEC_PER_SEC),
2159 };
2160 FUNCTION_QUERY_STATUS *fqs = NULL;
2161 const DICTIONARY_ITEM *fqs_item = NULL;
database/rrdfunctions.c
+1 -1
@@ -833,7 +833,7 @@ static int rrd_call_function_async_and_wait(struct rrd_function_inflight *r) {
833 struct timespec tp;
834 clock_gettime(CLOCK_REALTIME, &tp);
835 usec_t now_ut = tp.tv_sec * USEC_PER_SEC + tp.tv_nsec / NSEC_PER_USEC;
836 - usec_t end_ut = now_ut + r->timeout * USEC_PER_SEC;
836 + usec_t end_ut = now_ut + r->timeout * USEC_PER_SEC + RRDFUNCTIONS_TIMEOUT_EXTENSION_UT;
837
838 struct rrd_function_call_wait *tmp = mallocz(sizeof(struct rrd_function_call_wait));
839 tmp->free_with_signal = false;
database/rrdfunctions.h
+2
@@ -6,6 +6,8 @@
6
7 #include "rrd.h"
8
9 +#define RRDFUNCTIONS_TIMEOUT_EXTENSION_UT (1 * USEC_PER_SEC)
10 +
11 typedef void (*rrd_function_result_callback_t)(BUFFER *wb, int code, void *result_cb_data);
12 typedef bool (*rrd_function_is_cancelled_cb_t)(void *is_cancelled_cb_data);
13 typedef void (*rrd_function_canceller_cb_t)(void *data);
libnetdata/facets/facets.c
+24 -22
@@ -419,19 +419,19 @@ static inline void facets_key_value_copy_to_buffer(FACET_KEY *k) {
419 }
420 }
421
422 -static const char *facets_value_dup(const char *v, uint32_t len) {
423 - char *s = mallocz(len + 1);
422 +static const char *facets_value_dup(const char *s, uint32_t len) {
423 + char *d = mallocz(len + 1);
424
425 if(len)
426 - memcpy(s, v, len);
426 + memcpy(d, s, len);
427
428 - s[len] = '\0';
428 + d[len] = '\0';
429
430 - return s;
430 + return d;
431 }
432
433 static inline void FACET_VALUE_ADD_CONFLICT(FACET_KEY *k, FACET_VALUE *v, const FACET_VALUE * const nv) {
434 - if(!v->name && nv->name && nv->name_len) {
434 + if(!v->name && !v->name_len && nv->name && nv->name_len) {
435 // an actual value, not a filter
436 v->name = facets_value_dup(nv->name, nv->name_len);
437 v->name_len = nv->name_len;
@@ -482,6 +482,10 @@ static inline FACET_VALUE *FACET_VALUE_ADD_TO_INDEX(FACET_KEY *k, const FACET_VA
482 v->name = facets_value_dup(v->name, v->name_len);
483 facet_value_is_used(k, v);
484 }
485 + else {
486 + v->name = NULL;
487 + v->name_len = 0;
488 + }
489
490 k->facets->operations.values.inserts++;
491
@@ -517,6 +521,8 @@ static inline void FACET_VALUE_ADD_EMPTY_VALUE_TO_INDEX(FACET_KEY *k) {
521 static inline void FACET_VALUE_ADD_CURRENT_VALUE_TO_INDEX(FACET_KEY *k) {
522 static __thread FACET_VALUE tv = { 0 };
523
524 + internal_fatal(!facet_key_value_updated(k), "trying to add a non-updated value to the index");
525 +
526 tv.name = facets_key_get_value(k);
527 tv.name_len = facets_key_get_value_length(k);
528 tv.hash = FACETS_HASH_FUNCTION(tv.name, tv.name_len);
@@ -529,6 +535,8 @@ static inline void FACET_VALUE_ADD_OR_UPDATE_SELECTED(FACET_KEY *k, FACETS_HASH
535 FACET_VALUE tv = {
536 .hash = hash,
537 .selected = true,
538 + .name = NULL,
539 + .name_len = 0,
540 };
541 FACET_VALUE_ADD_TO_INDEX(k, &tv);
542 }
@@ -603,7 +611,7 @@ void facets_add_possible_value_name_to_key(FACETS *facets, const char *key, size
611
612 hash = FACETS_HASH_FUNCTION(value, value_length);
613 FACET_VALUE *v = FACET_VALUE_GET_FROM_INDEX(k, hash);
606 - if(v && v->name) return;
614 + if(v && v->name && v->name_len) return;
615
616 FACET_VALUE tv = {
617 .hash = hash,
@@ -1993,11 +2001,8 @@ static int facets_key_values_reorder_by_name_compar(const void *a, const void *b
2001 const FACET_VALUE *av = *((const FACET_VALUE **)a);
2002 const FACET_VALUE *bv = *((const FACET_VALUE **)b);
2003
1996 - const char *an = av->name;
1997 - const char *bn = bv->name;
1998 -
1999 - if(!an) an = "0";
2000 - if(!bn) bn = "0";
2004 + const char *an = (av->name && av->name_len) ? av->name : "0";
2005 + const char *bn = (bv->name && bv->name_len) ? bv->name : "0";
2006
2007 while(*an && ispunct(*an)) an++;
2008 while(*bn && ispunct(*bn)) bn++;
@@ -2023,11 +2028,8 @@ static int facets_key_values_reorder_by_name_numeric_compar(const void *a, const
2028 const FACET_VALUE *av = *((const FACET_VALUE **)a);
2029 const FACET_VALUE *bv = *((const FACET_VALUE **)b);
2030
2026 - const char *an = av->name;
2027 - const char *bn = bv->name;
2028 -
2029 - if(!an) an = "0";
2030 - if(!bn) bn = "0";
2031 + const char *an = (av->name && av->name_len) ? av->name : "0";
2032 + const char *bn = (bv->name && bv->name_len) ? bv->name : "0";
2033
2034 if(strcmp(an, FACET_VALUE_UNSET) == 0) an = "0";
2035 if(strcmp(bn, FACET_VALUE_UNSET) == 0) bn = "0";
@@ -2053,17 +2055,17 @@ static uint32_t facets_sort_and_reorder_values_internal(FACET_KEY *k) {
2055 if((k->facets->options & FACETS_OPTION_DONT_SEND_EMPTY_VALUE_FACETS) && v->empty)
2056 continue;
2057
2056 - if(used >= entries)
2057 - break;
2058 -
2059 - values[used++] = v;
2060 -
2058 if(all_values_numeric && !v->empty && v->name && v->name_len) {
2059 const char *s = v->name;
2060 while(isdigit(*s)) s++;
2061 if(*s != '\0')
2062 all_values_numeric = false;
2063 }
2064 +
2065 + values[used++] = v;
2066 +
2067 + if(used >= entries)
2068 + break;
2069 }
2070 foreach_value_in_key_done(v);
2071