diff options
author | Costa Tsaousis <costa@netdata.cloud> | 2023-09-15 14:51:31 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-15 14:51:31 +0300 |
commit | 717f258c307599ca5955fd34753dbc0430966143 (patch) | |
tree | 6144e7f546a017a4af1d211d635835d663005cb3 /collectors/systemd-journal.plugin | |
parent | 3bae63f27d60eb0abfbeb83beb35dfd55c96b4a9 (diff) |
Facets: fixes 5 (#15976)
Diffstat (limited to 'collectors/systemd-journal.plugin')
-rw-r--r-- | collectors/systemd-journal.plugin/systemd-journal.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/collectors/systemd-journal.plugin/systemd-journal.c b/collectors/systemd-journal.plugin/systemd-journal.c index d7baaa508c..5a247a0a72 100644 --- a/collectors/systemd-journal.plugin/systemd-journal.c +++ b/collectors/systemd-journal.plugin/systemd-journal.c @@ -600,6 +600,40 @@ static void netdata_systemd_journal_rich_message(FACETS *facets __maybe_unused, } static void function_systemd_journal(const char *transaction, char *function, char *line_buffer __maybe_unused, int line_max __maybe_unused, int timeout __maybe_unused) { + static struct { + BUFFER *tmp; + BUFFER *wb; + BUFFER *function; + int response; + time_t expires; + } cache = { + .tmp = NULL, + .wb = NULL, + .function = NULL, + .response = 0, + .expires = 0, + }; + + if(unlikely(!cache.wb)) { + cache.tmp = buffer_create(0, NULL); + cache.wb = buffer_create(0, NULL); + cache.function = buffer_create(0, NULL); + } + + if(buffer_strlen(cache.function) && buffer_strlen(cache.wb) && strcmp(buffer_tostring(cache.function), function) == 0) { + // repeated the same request + netdata_mutex_lock(&stdout_mutex); + if(cache.response == HTTP_RESP_OK) + pluginsd_function_result_to_stdout(transaction, cache.response, "application/json", cache.expires, cache.wb); + else + pluginsd_function_json_error_to_stdout(transaction, cache.response, "failed"); + netdata_mutex_unlock(&stdout_mutex); + return; + } + + buffer_flush(cache.tmp); + buffer_strcat(cache.tmp, function); + BUFFER *wb = buffer_create(0, NULL); buffer_flush(wb); buffer_json_initialize(wb, "\"", "\"", 0, true, BUFFER_JSON_OPTIONS_NEWLINE_ON_ARRAY_ITEMS); @@ -838,6 +872,14 @@ static void function_systemd_journal(const char *transaction, char *function, ch goto cleanup; } + // keep this response in the cache + cache.response = response; + cache.expires = expires; + buffer_flush(cache.wb); + buffer_fast_strcat(cache.wb, buffer_tostring(wb), buffer_strlen(wb)); + buffer_flush(cache.function); + buffer_fast_strcat(cache.function, buffer_tostring(cache.tmp), buffer_strlen(cache.tmp)); + output: netdata_mutex_lock(&stdout_mutex); pluginsd_function_result_to_stdout(transaction, response, "application/json", expires, wb); |