DYNCFG: support test on new jobs (#16958)
support test on new jobs
Costa Tsaousis committed
Feb 7, 2024 at 15:27 UTC
1630de6eae90b7e39178e63df36aedf41a84cceb
3 files changed
+34
-8
src/daemon/config/dyncfg-intercept.c
+28
-5
@@ -36,8 +36,8 @@ static void dyncfg_function_intercept_job_successfully_added(DYNCFG *df_template
36
DYNCFG_TYPE_JOB,
37
DYNCFG_SOURCE_TYPE_DYNCFG,
38
dc->source,
39
- (df_template->cmds & ~DYNCFG_CMD_ADD) | DYNCFG_CMD_GET | DYNCFG_CMD_UPDATE | DYNCFG_CMD_TEST | DYNCFG_CMD_ENABLE |
40
- DYNCFG_CMD_DISABLE | DYNCFG_CMD_REMOVE,
39
+ (df_template->cmds & ~DYNCFG_CMD_ADD) | DYNCFG_CMD_GET | DYNCFG_CMD_UPDATE | DYNCFG_CMD_TEST |
40
+ DYNCFG_CMD_ENABLE | DYNCFG_CMD_DISABLE | DYNCFG_CMD_REMOVE,
41
0,
42
0,
43
df_template->sync,
@@ -180,6 +180,23 @@ static int dyncfg_intercept_early_error(struct rrd_function_execute *rfe, int rc
180
return rc;
181
}
182
183
+static const DICTIONARY_ITEM *dyncfg_get_template_of_new_job(const char *job_id) {
184
+ const char *colon = strrchr(job_id, ':');
185
+ if(!colon) return NULL;
186
+
187
+ colon++;
188
+ const DICTIONARY_ITEM *item = dictionary_get_and_acquire_item(dyncfg_globals.nodes, colon);
189
+ if(!item) return NULL;
190
+
191
+ DYNCFG *df = dictionary_acquired_item_value(item);
192
+ if(df->type != DYNCFG_TYPE_TEMPLATE) {
193
+ dictionary_acquired_item_release(dyncfg_globals.nodes, item);
194
+ return NULL;
195
+ }
196
+
197
+ return item;
198
+}
199
+
200
int dyncfg_function_intercept_cb(struct rrd_function_execute *rfe, void *data __maybe_unused) {
201
202
// 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 __
256
"dyncfg functions intercept: this action does not require a payload");
257
258
item = dictionary_get_and_acquire_item(dyncfg_globals.nodes, id);
242
- if(!item)
243
- return dyncfg_intercept_early_error(rfe, HTTP_RESP_NOT_FOUND,
244
- "dyncfg functions intercept: id is not found");
259
+ if(!item) {
260
+ if(cmd == DYNCFG_CMD_TEST) {
261
+ // this may be a test on a new job
262
+ item = dyncfg_get_template_of_new_job(id);
263
+ }
264
+
265
+ if(!item)
266
+ return dyncfg_intercept_early_error(rfe, HTTP_RESP_NOT_FOUND, "dyncfg functions intercept: id is not found");
267
+ }
268
269
DYNCFG *df = dictionary_acquired_item_value(item);
270
src/daemon/config/dyncfg.c
+1
-1
@@ -331,7 +331,7 @@ bool dyncfg_add_low_level(RRDHOST *host, const char *id, const char *path,
331
// data
332
if(type == DYNCFG_TYPE_TEMPLATE) {
333
// templates do not have data
334
- cmds &= ~(DYNCFG_CMD_GET | DYNCFG_CMD_UPDATE | DYNCFG_CMD_TEST);
334
+ cmds &= ~(DYNCFG_CMD_GET | DYNCFG_CMD_UPDATE);
335
}
336
337
if(cmds != old_cmds) {
src/health/health_dyncfg.c
+5
-2
@@ -382,12 +382,15 @@ static int dyncfg_health_prototype_template_action(BUFFER *result, DYNCFG_CMDS c
382
code = dyncfg_default_response(result, HTTP_RESP_NOT_IMPLEMENTED, "schema not implemented yet for prototype templates");
383
break;
384
385
+ case DYNCFG_CMD_TEST:
386
+ code = dyncfg_default_response(result, HTTP_RESP_NOT_IMPLEMENTED, "test not implemented yet for prototype templates");
387
+ break;
388
+
389
case DYNCFG_CMD_REMOVE:
390
case DYNCFG_CMD_RESTART:
391
case DYNCFG_CMD_DISABLE:
392
case DYNCFG_CMD_ENABLE:
393
case DYNCFG_CMD_UPDATE:
390
- case DYNCFG_CMD_TEST:
394
case DYNCFG_CMD_GET:
395
code = dyncfg_default_response(result, HTTP_RESP_BAD_REQUEST, "action given is not supported for prototype templates");
396
break;
@@ -599,7 +602,7 @@ void health_dyncfg_register_all_prototypes(void) {
602
DYNCFG_HEALTH_ALERT_PROTOTYPE_PREFIX, "/health/alerts/prototypes",
603
DYNCFG_STATUS_ACCEPTED, DYNCFG_TYPE_TEMPLATE,
604
DYNCFG_SOURCE_TYPE_INTERNAL, "internal",
602
- DYNCFG_CMD_SCHEMA | DYNCFG_CMD_ADD | DYNCFG_CMD_ENABLE | DYNCFG_CMD_DISABLE,
605
+ DYNCFG_CMD_SCHEMA | DYNCFG_CMD_ADD | DYNCFG_CMD_ENABLE | DYNCFG_CMD_DISABLE | DYNCFG_CMD_TEST,
606
HTTP_ACCESS_SIGNED_ID | HTTP_ACCESS_SAME_SPACE | HTTP_ACCESS_VIEW_AGENT_CONFIG,
607
HTTP_ACCESS_SIGNED_ID | HTTP_ACCESS_SAME_SPACE | HTTP_ACCESS_EDIT_AGENT_CONFIG,
608
dyncfg_health_cb, NULL);