@cryptotaxi247 / netdata-1 / commits / a5c712209

Don't expose the chart definition to streaming if there is no metadata change (#12990)

* Only clear the RRDSET_FLAG_UPSTREAM_EXPOSED chart flag if metadata has changed * Handle modification of units as well * Initialize old_units in the chart state

Stelios Fragkakis committed May 24, 2022 at 22:27 UTC a5c712209281d969c6aba1d456829d24672a566a
2 files changed +22 -3
database/rrd.h
+1
@@ -399,6 +399,7 @@ struct rrddim_volatile {
399 // volatile state per chart
400 struct rrdset_volatile {
401 char *old_title;
402 + char *old_units;
403 char *old_context;
404 uuid_t hash_id;
405 struct label *new_labels;
database/rrdset.c
+21 -3
@@ -400,6 +400,7 @@ void rrdset_free(RRDSET *st) {
400 freez(st->plugin_name);
401 freez(st->module_name);
402 freez(st->state->old_title);
403 + freez(st->state->old_units);
404 freez(st->state->old_context);
405 free_label_list(st->state->labels.head);
406 freez(st->state);
@@ -561,15 +562,13 @@ RRDSET *rrdset_create_custom(
562 RRDSET *st = rrdset_find_on_create(host, fullid);
563 if (st) {
564 int mark_rebuild = 0;
564 - rrdset_flag_set(st, RRDSET_FLAG_SYNC_CLOCK);
565 - rrdset_flag_clear(st, RRDSET_FLAG_UPSTREAM_EXPOSED);
565 if (rrdset_flag_check(st, RRDSET_FLAG_ARCHIVED)) {
566 rrdset_flag_clear(st, RRDSET_FLAG_ARCHIVED);
567 changed_from_archived_to_active = 1;
568 mark_rebuild |= META_CHART_ACTIVATED;
569 }
570 char *old_plugin = NULL, *old_module = NULL, *old_title = NULL, *old_context = NULL,
572 - *old_title_v = NULL, *old_context_v = NULL;
571 + *old_title_v = NULL, *old_context_v = NULL, *old_units_v = NULL, *old_units = NULL;
572 int rc;
573
574 if(unlikely(name))
@@ -629,6 +628,17 @@ RRDSET *rrdset_create_custom(
628 mark_rebuild |= META_CHART_UPDATED;
629 }
630
631 + if (unlikely(units && st->state->old_units && strcmp(st->state->old_units, units))) {
632 + char *new_units = strdupz(units);
633 + old_units_v = st->state->old_units;
634 + st->state->old_units = strdupz(units);
635 + json_fix_string(new_units);
636 + old_units= st->units;
637 + st->units = new_units;
638 + mark_rebuild |= META_CHART_UPDATED;
639 + }
640 +
641 +
642 if (st->chart_type != chart_type) {
643 st->chart_type = chart_type;
644 mark_rebuild |= META_CHART_UPDATED;
@@ -665,8 +675,10 @@ RRDSET *rrdset_create_custom(
675 freez(old_plugin);
676 freez(old_module);
677 freez(old_title);
678 + freez(old_units);
679 freez(old_context);
680 freez(old_title_v);
681 + freez(old_units_v);
682 freez(old_context_v);
683 if (mark_rebuild != META_CHART_ACTIVATED) {
684 info("Collector updated metadata for chart %s", st->id);
@@ -678,6 +690,11 @@ RRDSET *rrdset_create_custom(
690 int rc = update_chart_metadata(st->chart_uuid, st, id, name);
691 if (unlikely(rc))
692 error_report("Failed to update chart metadata in the database");
693 +
694 + if (!changed_from_archived_to_active) {
695 + rrdset_flag_set(st, RRDSET_FLAG_SYNC_CLOCK);
696 + rrdset_flag_clear(st, RRDSET_FLAG_UPSTREAM_EXPOSED);
697 + }
698 }
699 /* Fall-through during switch from archived to active so that the host lock is taken and health is linked */
700 if (!changed_from_archived_to_active)
@@ -838,6 +855,7 @@ RRDSET *rrdset_create_custom(
855 st->state->is_ar_chart = strcmp(st->id, ML_ANOMALY_RATES_CHART_ID) == 0;
856
857 st->units = units ? strdupz(units) : strdupz("");
858 + st->state->old_units = strdupz(st->units);
859 json_fix_string(st->units);
860
861 st->context = context ? strdupz(context) : strdupz(st->id);