DYNCFG fix REPORT_JOB_STATUS streaming (#16272)
* handle empty reason string as no reason * properly handle missing and empty reason strings
Timotej S committed
Oct 25, 2023 at 16:54 UTC
88a02e9e22798d2b0390723df9a5e3c62268f3a2
3 files changed
+10
-5
collectors/plugins.d/pluginsd_parser.c
+1
-1
@@ -2512,7 +2512,7 @@ static inline PARSER_RC pluginsd_job_status_common(char **words, size_t num_word
2512
return PLUGINSD_DISABLE_PLUGIN(parser, PLUGINSD_KEYWORD_REPORT_JOB_STATUS, "unknown job status");
2513
2514
char *message = NULL;
2515
- if (num_words == 5)
2515
+ if (num_words == 5 && strlen(words[4]) > 0)
2516
message = words[4];
2517
2518
const DICTIONARY_ITEM *plugin_item;
libnetdata/dyn_conf/README.md
+4
-2
@@ -119,16 +119,18 @@ Where:
119
#### REPORT_JOB_STATUS
120
121
```
122
-REPORT_JOB_STATUS {MODULE_NAME} {JOB_NAME} {STATUS} {STATE} "{REASON}"
122
+REPORT_JOB_STATUS {MODULE_NAME} {JOB_NAME} {STATUS} {STATE} ["REASON"]
123
```
124
125
+Note the REASON parameter is optional and can be entirelly ommited (for example when state is OK there is no need to send any reason).
126
+
127
Where:
128
129
- `MODULE_NAME` is the name of the module.
130
- `JOB_NAME` is the name of the job.
131
- `STATUS` is one of `stopped`, `running`, or `error`.
132
- `STATE`, just send zero.
131
-- `REASON` is a message describing the status.
133
+- `REASON` is a message describing the status. In case you don't want to send any reason string it is preferable to omit this parameter altogether (as opposed to sending empty string `""`).
134
135
136
### Commands plugins must serve
streaming/rrdpush.c
+5
-2
@@ -485,10 +485,13 @@ void rrdpush_send_job_status_update(RRDHOST *host, const char *plugin_name, cons
485
486
BUFFER *wb = sender_start(host->sender);
487
488
- buffer_sprintf(wb, PLUGINSD_KEYWORD_REPORT_JOB_STATUS " %s %s %s %s %d\n", plugin_name, module_name, job->name, job_status2str(job->status), job->state);
489
- if (job->reason)
488
+ buffer_sprintf(wb, PLUGINSD_KEYWORD_REPORT_JOB_STATUS " %s %s %s %s %d", plugin_name, module_name, job->name, job_status2str(job->status), job->state);
489
+
490
+ if (job->reason && strlen(job->reason))
491
buffer_sprintf(wb, " \"%s\"", job->reason);
492
493
+ buffer_strcat(wb, "\n");
494
+
495
sender_commit(host->sender, wb, STREAM_TRAFFIC_TYPE_METADATA);
496
497
sender_thread_buffer_free();