From 1630de6eae90b7e39178e63df36aedf41a84cceb Mon Sep 17 00:00:00 2001 From: Costa Tsaousis Date: Wed, 7 Feb 2024 15:27:14 +0200 Subject: [PATCH] DYNCFG: support test on new jobs (#16958) support test on new jobs --- src/daemon/config/dyncfg-intercept.c | 33 +++++++++++++++++++++++----- src/daemon/config/dyncfg.c | 2 +- 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 58a113ba638b86..88638988fe8cbc 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 10ec6039cb0329..5ee0dcfb60070f 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 b62673ec7477ef..b111d715ee221b 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);