diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-07-24 09:54:23 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-07-24 09:54:44 +0000 |
commit | 836b47cb7e99a977c5a23b059ca1d0b5065d310e (patch) | |
tree | 1604da8f482d02effa033c94a84be42bc0c848c3 /src/database/rrdfunctions-inline.c | |
parent | Releasing debian version 1.44.3-2. (diff) | |
download | netdata-836b47cb7e99a977c5a23b059ca1d0b5065d310e.tar.xz netdata-836b47cb7e99a977c5a23b059ca1d0b5065d310e.zip |
Merging upstream version 1.46.3.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/database/rrdfunctions-inline.c')
-rw-r--r-- | src/database/rrdfunctions-inline.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/database/rrdfunctions-inline.c b/src/database/rrdfunctions-inline.c new file mode 100644 index 00000000..3eb30e7b --- /dev/null +++ b/src/database/rrdfunctions-inline.c @@ -0,0 +1,44 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +#include "rrdfunctions-inline.h" + +struct rrd_function_inline { + rrd_function_execute_inline_cb_t cb; +}; + +static int rrd_function_run_inline(struct rrd_function_execute *rfe, void *data) { + + // IMPORTANT: this function MUST call the result_cb even on failures + + struct rrd_function_inline *fi = data; + + int code; + + if(rfe->is_cancelled.cb && rfe->is_cancelled.cb(rfe->is_cancelled.data)) + code = HTTP_RESP_CLIENT_CLOSED_REQUEST; + else + code = fi->cb(rfe->result.wb, rfe->function); + + if(code == HTTP_RESP_CLIENT_CLOSED_REQUEST || (rfe->is_cancelled.cb && rfe->is_cancelled.cb(rfe->is_cancelled.data))) { + buffer_flush(rfe->result.wb); + code = HTTP_RESP_CLIENT_CLOSED_REQUEST; + } + + if(rfe->result.cb) + rfe->result.cb(rfe->result.wb, code, rfe->result.data); + + return code; +} + +void rrd_function_add_inline(RRDHOST *host, RRDSET *st, const char *name, int timeout, int priority, + const char *help, const char *tags, + HTTP_ACCESS access, rrd_function_execute_inline_cb_t execute_cb) { + + rrd_collector_started(); // this creates a collector that runs for as long as netdata runs + + struct rrd_function_inline *fi = callocz(1, sizeof(struct rrd_function_inline)); + fi->cb = execute_cb; + + rrd_function_add(host, st, name, timeout, priority, help, tags, access, true, + rrd_function_run_inline, fi); +} |