diff options
author | Costa Tsaousis <costa@netdata.cloud> | 2024-02-07 15:27:14 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-07 15:27:14 +0200 |
commit | 1630de6eae90b7e39178e63df36aedf41a84cceb (patch) | |
tree | 14daf0b2a33dd19096796a83653ac8a1ebdfadb6 /src | |
parent | 2e8ddaa56c6237b2ab1ba96cd00da7e5e0c8a3ac (diff) |
DYNCFG: support test on new jobs (#16958)
support test on new jobs
Diffstat (limited to 'src')
-rw-r--r-- | src/daemon/config/dyncfg-intercept.c | 33 | ||||
-rw-r--r-- | src/daemon/config/dyncfg.c | 2 | ||||
-rw-r--r-- | src/health/health_dyncfg.c | 7 |
3 files changed, 34 insertions, 8 deletions
diff --git a/src/daemon/config/dyncfg-intercept.c b/src/daemon/config/dyncfg-intercept.c index 58a113ba63..88638988fe 100644 --- a/src/daemon/config/dyncfg-intercept.c +++ b/src/daemon/config/dyncfg-intercept.c @@ -36,8 +36,8 @@ static void dyncfg_function_intercept_job_successfully_added(DYNCFG *df_template DYNCFG_TYPE_JOB, DYNCFG_SOURCE_TYPE_DYNCFG, dc->source, - (df_template->cmds & ~DYNCFG_CMD_ADD) | DYNCFG_CMD_GET | DYNCFG_CMD_UPDATE | DYNCFG_CMD_TEST | DYNCFG_CMD_ENABLE | - DYNCFG_CMD_DISABLE | DYNCFG_CMD_REMOVE, + (df_template->cmds & ~DYNCFG_CMD_ADD) | DYNCFG_CMD_GET | DYNCFG_CMD_UPDATE | DYNCFG_CMD_TEST | + DYNCFG_CMD_ENABLE | DYNCFG_CMD_DISABLE | DYNCFG_CMD_REMOVE, 0, 0, df_template->sync, @@ -180,6 +180,23 @@ static int dyncfg_intercept_early_error(struct rrd_function_execute *rfe, int rc return rc; } +static const DICTIONARY_ITEM *dyncfg_get_template_of_new_job(const char *job_id) { + const char *colon = strrchr(job_id, ':'); + if(!colon) return NULL; + + colon++; + const DICTIONARY_ITEM *item = dictionary_get_and_acquire_item(dyncfg_globals.nodes, colon); + if(!item) return NULL; + + DYNCFG *df = dictionary_acquired_item_value(item); + if(df->type != DYNCFG_TYPE_TEMPLATE) { + dictionary_acquired_item_release(dyncfg_globals.nodes, item); + return NULL; + } + + return item; +} + int dyncfg_function_intercept_cb(struct rrd_function_execute *rfe, void *data __maybe_unused) { // IMPORTANT: this function MUST call the result_cb even on failures @@ -239,9 +256,15 @@ int dyncfg_function_intercept_cb(struct rrd_function_execute *rfe, void *data __ "dyncfg functions intercept: this action does not require a payload"); item = dictionary_get_and_acquire_item(dyncfg_globals.nodes, id); - if(!item) - return dyncfg_intercept_early_error(rfe, HTTP_RESP_NOT_FOUND, - "dyncfg functions intercept: id is not found"); + if(!item) { + if(cmd == DYNCFG_CMD_TEST) { + // this may be a test on a new job + item = dyncfg_get_template_of_new_job(id); + } + + if(!item) + return dyncfg_intercept_early_error(rfe, HTTP_RESP_NOT_FOUND, "dyncfg functions intercept: id is not found"); + } DYNCFG *df = dictionary_acquired_item_value(item); diff --git a/src/daemon/config/dyncfg.c b/src/daemon/config/dyncfg.c index 10ec6039cb..5ee0dcfb60 100644 --- a/src/daemon/config/dyncfg.c +++ b/src/daemon/config/dyncfg.c @@ -331,7 +331,7 @@ bool dyncfg_add_low_level(RRDHOST *host, const char *id, const char *path, // data if(type == DYNCFG_TYPE_TEMPLATE) { // templates do not have data - cmds &= ~(DYNCFG_CMD_GET | DYNCFG_CMD_UPDATE | DYNCFG_CMD_TEST); + cmds &= ~(DYNCFG_CMD_GET | DYNCFG_CMD_UPDATE); } if(cmds != old_cmds) { diff --git a/src/health/health_dyncfg.c b/src/health/health_dyncfg.c index b62673ec74..b111d715ee 100644 --- a/src/health/health_dyncfg.c +++ b/src/health/health_dyncfg.c @@ -382,12 +382,15 @@ static int dyncfg_health_prototype_template_action(BUFFER *result, DYNCFG_CMDS c code = dyncfg_default_response(result, HTTP_RESP_NOT_IMPLEMENTED, "schema not implemented yet for prototype templates"); break; + case DYNCFG_CMD_TEST: + code = dyncfg_default_response(result, HTTP_RESP_NOT_IMPLEMENTED, "test not implemented yet for prototype templates"); + break; + case DYNCFG_CMD_REMOVE: case DYNCFG_CMD_RESTART: case DYNCFG_CMD_DISABLE: case DYNCFG_CMD_ENABLE: case DYNCFG_CMD_UPDATE: - case DYNCFG_CMD_TEST: case DYNCFG_CMD_GET: code = dyncfg_default_response(result, HTTP_RESP_BAD_REQUEST, "action given is not supported for prototype templates"); break; @@ -599,7 +602,7 @@ void health_dyncfg_register_all_prototypes(void) { DYNCFG_HEALTH_ALERT_PROTOTYPE_PREFIX, "/health/alerts/prototypes", DYNCFG_STATUS_ACCEPTED, DYNCFG_TYPE_TEMPLATE, DYNCFG_SOURCE_TYPE_INTERNAL, "internal", - DYNCFG_CMD_SCHEMA | DYNCFG_CMD_ADD | DYNCFG_CMD_ENABLE | DYNCFG_CMD_DISABLE, + DYNCFG_CMD_SCHEMA | DYNCFG_CMD_ADD | DYNCFG_CMD_ENABLE | DYNCFG_CMD_DISABLE | DYNCFG_CMD_TEST, HTTP_ACCESS_SIGNED_ID | HTTP_ACCESS_SAME_SPACE | HTTP_ACCESS_VIEW_AGENT_CONFIG, HTTP_ACCESS_SIGNED_ID | HTTP_ACCESS_SAME_SPACE | HTTP_ACCESS_EDIT_AGENT_CONFIG, dyncfg_health_cb, NULL); |