@cryptotaxi247 / netdata-1 / commits / 04ecb7285

fix chart definition end time_t printing and parsing (#13942)

* fix chart definition end time_t printing and parsing * properly check parameters to chart definition end

Costa Tsaousis committed Nov 2, 2022 at 20:23 UTC 04ecb72856e0559459bb468c40ad87d5779d9ec9
3 files changed +41 -3
collectors/plugins.d/pluginsd_parser.c
+16 -2
@@ -261,8 +261,16 @@ PARSER_RC pluginsd_chart(char **words, size_t num_words, void *user)
261
262 PARSER_RC pluginsd_chart_definition_end(char **words, size_t num_words, void *user)
263 {
264 - long first_entry_child = str2l(get_word(words, num_words, 1));
265 - long last_entry_child = str2l(get_word(words, num_words, 2));
264 + const char *first_entry_txt = get_word(words, num_words, 1);
265 + const char *last_entry_txt = get_word(words, num_words, 2);
266 +
267 + if(unlikely(!first_entry_txt || !last_entry_txt)) {
268 + error("REPLAY: received " PLUGINSD_KEYWORD_CHART_DEFINITION_END " command without first or last entry. Disabling it.");
269 + return PARSER_RC_ERROR;
270 + }
271 +
272 + long first_entry_child = str2l(first_entry_txt);
273 + long last_entry_child = str2l(last_entry_txt);
274
275 PARSER_USER_OBJECT *user_object = (PARSER_USER_OBJECT *) user;
276
@@ -273,6 +281,12 @@ PARSER_RC pluginsd_chart_definition_end(char **words, size_t num_words, void *us
281 return PARSER_RC_ERROR;
282 }
283
284 + internal_error(
285 + (first_entry_child != 0 || last_entry_child != 0)
286 + && (first_entry_child == 0 || last_entry_child == 0),
287 + "REPLAY: received " PLUGINSD_KEYWORD_CHART_DEFINITION_END " with malformed timings (first time %llu, last time %llu).",
288 + (unsigned long long)first_entry_child, (unsigned long long)last_entry_child);
289 +
290 rrdset_flag_clear(st, RRDSET_FLAG_RECEIVER_REPLICATION_FINISHED);
291
292 bool ok = replicate_chart_request(send_to_plugin, user_object->parser, host, st, first_entry_child, last_entry_child, 0, 0);
streaming/replication.c
+7
@@ -170,6 +170,13 @@ bool replicate_chart_response(RRDHOST *host, RRDSET *st, bool start_streaming, t
170
171 // find the latest entry we have
172 time_t last_entry_local = st->last_updated.tv_sec;
173 + if(!last_entry_local) {
174 + internal_error(true,
175 + "RRDSET: '%s' last updated time zero. Querying db for last updated time.",
176 + rrdset_id(st));
177 + last_entry_local = rrdset_last_entry_t(st);
178 + }
179 +
180 if(last_entry_local > now) {
181 internal_error(true,
182 "RRDSET: '%s' last updated time %llu is in the future (now is %llu)",
streaming/rrdpush.c
+18 -1
@@ -310,7 +310,24 @@ static inline void rrdpush_send_chart_definition(BUFFER *wb, RRDSET *st) {
310 if (stream_has_capability(host->sender, STREAM_CAP_REPLICATION)) {
311 time_t first_entry_local = rrdset_first_entry_t(st);
312 time_t last_entry_local = st->last_updated.tv_sec;
313 - buffer_sprintf(wb, "CHART_DEFINITION_END %ld %ld\n", first_entry_local, last_entry_local);
313 +
314 + if(!last_entry_local) {
315 + internal_error(true,
316 + "RRDSET: '%s' last updated time zero. Querying db for last updated time.",
317 + rrdset_id(st));
318 +
319 + last_entry_local = rrdset_last_entry_t(st);
320 + time_t now = now_realtime_sec();
321 + if(last_entry_local > now) {
322 + internal_error(true,
323 + "RRDSET: '%s' last updated time %llu is in the future (now is %llu)",
324 + rrdset_id(st), (unsigned long long)last_entry_local, (unsigned long long)now);
325 + last_entry_local = now;
326 + }
327 + }
328 +
329 + buffer_sprintf(wb, PLUGINSD_KEYWORD_CHART_DEFINITION_END " %llu %llu\n",
330 + (unsigned long long)first_entry_local, (unsigned long long)last_entry_local);
331 }
332
333 st->upstream_resync_time = st->last_collected_time.tv_sec + (remote_clock_resync_iterations * st->update_every);