0
0
Fork 0
mirror of https://github.com/netdata/netdata.git synced 2025-04-24 13:14:11 +00:00

DYNCFG: support test on new jobs ()

support test on new jobs
This commit is contained in:
Costa Tsaousis 2024-02-07 15:27:14 +02:00 committed by GitHub
parent 2e8ddaa56c
commit 1630de6eae
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 34 additions and 8 deletions

View file

@ -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);

View file

@ -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) {

View file

@ -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);