@cryptotaxi247 / netdata-1 / commits / d600ae20c

Fix issue with chart metadata sent multiple times over ACLK (#10381)

* Add a flag RRDSET_FLAG_ACLK to mark that a chart needs to go to the cloud * Change calls to aclk_update_chart to set the RRDSET_FLAG_ACLK instead Make the call to aclk_update_chart only in rrdset_done (and in case the chart is deleted) * Fix compilation error when cloud is disabled * Skip netdata_cloud_setting check when setting the flag / calling aclk_update_chart (checked in there)

Stelios Fragkakis committed Dec 14, 2020 at 17:32 UTC d600ae20c0456e23277850ecd5ad4542e465b00b
3 files changed +20 -19
database/rrd.h
+2 -1
@@ -450,7 +450,8 @@ typedef enum rrdset_flags {
450 RRDSET_FLAG_OBSOLETE_DIMENSIONS = 1 << 14, // this is marked by the collector/module when a chart has obsolete dimensions
451 // No new values have been collected for this chart since agent start or it was marked RRDSET_FLAG_OBSOLETE at
452 // least rrdset_free_obsolete_time seconds ago.
453 - RRDSET_FLAG_ARCHIVED = 1 << 15
453 + RRDSET_FLAG_ARCHIVED = 1 << 15,
454 + RRDSET_FLAG_ACLK = 1 << 16
455 } RRDSET_FLAGS;
456
457 #ifdef HAVE_C___ATOMIC
database/rrddim.c
+8 -14
@@ -210,8 +210,7 @@ void rrdcalc_link_to_rrddim(RRDDIM *rd, RRDSET *st, RRDHOST *host) {
210 }
211 }
212 #ifdef ENABLE_ACLK
213 - if (netdata_cloud_setting)
214 - aclk_update_chart(st->rrdhost, st->id, ACLK_CMD_CHART);
213 + rrdset_flag_set(st, RRDSET_FLAG_ACLK);
214 #endif
215 }
216
@@ -459,8 +458,7 @@ RRDDIM *rrddim_add_custom(RRDSET *st, const char *id, const char *name, collecte
458
459 rrdset_unlock(st);
460 #ifdef ENABLE_ACLK
462 - if (netdata_cloud_setting)
463 - aclk_update_chart(host, st->id, ACLK_CMD_CHART);
461 + rrdset_flag_set(st, RRDSET_FLAG_ACLK);
462 #endif
463 return(rd);
464 }
@@ -534,8 +532,8 @@ void rrddim_free_custom(RRDSET *st, RRDDIM *rd, int db_rotated)
532 break;
533 }
534 #ifdef ENABLE_ACLK
537 - if ((netdata_cloud_setting) && (db_rotated || RRD_MEMORY_MODE_DBENGINE != rrd_memory_mode))
538 - aclk_update_chart(st->rrdhost, st->id, ACLK_CMD_CHART);
535 + if (db_rotated || RRD_MEMORY_MODE_DBENGINE != rrd_memory_mode)
536 + rrdset_flag_set(st, RRDSET_FLAG_ACLK);
537 #endif
538 }
539
@@ -556,8 +554,7 @@ int rrddim_hide(RRDSET *st, const char *id) {
554
555 rrddim_flag_set(rd, RRDDIM_FLAG_HIDDEN);
556 #ifdef ENABLE_ACLK
559 - if (netdata_cloud_setting)
560 - aclk_update_chart(st->rrdhost, st->id, ACLK_CMD_CHART);
557 + rrdset_flag_set(st, RRDSET_FLAG_ACLK);
558 #endif
559 return 0;
560 }
@@ -574,8 +571,7 @@ int rrddim_unhide(RRDSET *st, const char *id) {
571
572 rrddim_flag_clear(rd, RRDDIM_FLAG_HIDDEN);
573 #ifdef ENABLE_ACLK
577 - if (netdata_cloud_setting)
578 - aclk_update_chart(st->rrdhost, st->id, ACLK_CMD_CHART);
574 + rrdset_flag_set(st, RRDSET_FLAG_ACLK);
575 #endif
576 return 0;
577 }
@@ -590,8 +586,7 @@ inline void rrddim_is_obsolete(RRDSET *st, RRDDIM *rd) {
586 rrddim_flag_set(rd, RRDDIM_FLAG_OBSOLETE);
587 rrdset_flag_set(st, RRDSET_FLAG_OBSOLETE_DIMENSIONS);
588 #ifdef ENABLE_ACLK
593 - if (netdata_cloud_setting)
594 - aclk_update_chart(st->rrdhost, st->id, ACLK_CMD_CHART);
589 + rrdset_flag_set(st, RRDSET_FLAG_ACLK);
590 #endif
591 }
592
@@ -600,8 +595,7 @@ inline void rrddim_isnot_obsolete(RRDSET *st __maybe_unused, RRDDIM *rd) {
595
596 rrddim_flag_clear(rd, RRDDIM_FLAG_OBSOLETE);
597 #ifdef ENABLE_ACLK
603 - if (netdata_cloud_setting)
604 - aclk_update_chart(st->rrdhost, st->id, ACLK_CMD_CHART);
598 + rrdset_flag_set(st, RRDSET_FLAG_ACLK);
599 #endif
600 }
601
database/rrdset.c
+10 -4
@@ -647,7 +647,7 @@ RRDSET *rrdset_create_custom(
647 aclk_add_collector(host, st->plugin_name, st->module_name);
648 }
649 }
650 - aclk_update_chart(host, st->id, ACLK_CMD_CHART);
650 + rrdset_flag_set(st, RRDSET_FLAG_ACLK);
651 }
652 #endif
653 freez(old_plugin);
@@ -944,10 +944,9 @@ RRDSET *rrdset_create_custom(
944
945 rrdhost_unlock(host);
946 #ifdef ENABLE_ACLK
947 - if (netdata_cloud_setting) {
947 + if (netdata_cloud_setting)
948 aclk_add_collector(host, plugin, module);
949 - aclk_update_chart(host, st->id, ACLK_CMD_CHART);
950 - }
949 + rrdset_flag_set(st, RRDSET_FLAG_ACLK);
950 #endif
951 return(st);
952 }
@@ -1383,6 +1382,13 @@ void rrdset_done(RRDSET *st) {
1382 // a read lock is OK here
1383 rrdset_rdlock(st);
1384
1385 +#ifdef ENABLE_ACLK
1386 + if (unlikely(rrdset_flag_check(st, RRDSET_FLAG_ACLK))) {
1387 + rrdset_flag_clear(st, RRDSET_FLAG_ACLK);
1388 + aclk_update_chart(st->rrdhost, st->id, ACLK_CMD_CHART);
1389 + }
1390 +#endif
1391 +
1392 if(unlikely(rrdset_flag_check(st, RRDSET_FLAG_OBSOLETE))) {
1393 error("Chart '%s' has the OBSOLETE flag set, but it is collected.", st->id);
1394 rrdset_isnot_obsolete(st);