Skip to content

Commit

Permalink
DYNCFG: support test on new jobs (netdata#16958)
Browse files Browse the repository at this point in the history
support test on new jobs
  • Loading branch information
ktsaou authored Feb 7, 2024
1 parent 2e8ddaa commit 1630de6
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
33 changes: 28 additions & 5 deletions src/daemon/config/dyncfg-intercept.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/daemon/config/dyncfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 5 additions & 2 deletions src/health/health_dyncfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 1630de6

Please sign in to comment.