@cryptotaxi247 / netdata-1 / commits / 822880265

Remove health from archived metrics (#9520)

* Disassociate health variables and alarms from archived charts and dimensions. * Ignore archived charts during health reload.

Markos Fountoulakis committed Jul 11, 2020 at 17:27 UTC 822880265e88a8f6a6d35d00eb0d0b5072d7ac1c
4 files changed +35 -8
database/rrddim.c
+4 -1
@@ -209,6 +209,9 @@ RRDDIM *rrddim_add_custom(RRDSET *st, const char *id, const char *name, collecte
209 if (!is_archived && rrddim_flag_check(rd, RRDDIM_FLAG_ARCHIVED)) {
210 rd->state->collect_ops.init(rd);
211 rrddim_flag_clear(rd, RRDDIM_FLAG_ARCHIVED);
212 + rrddimvar_create(rd, RRDVAR_TYPE_CALCULATED, NULL, NULL, &rd->last_stored_value, RRDVAR_OPTION_DEFAULT);
213 + rrddimvar_create(rd, RRDVAR_TYPE_COLLECTED, NULL, "_raw", &rd->last_collected_value, RRDVAR_OPTION_DEFAULT);
214 + rrddimvar_create(rd, RRDVAR_TYPE_TIME_T, NULL, "_last_collected_t", &rd->last_collected_time.tv_sec, RRDVAR_OPTION_DEFAULT);
215 }
216 // DBENGINE available and activated?
217 #ifdef ENABLE_DBENGINE
@@ -413,7 +416,7 @@ RRDDIM *rrddim_add_custom(RRDSET *st, const char *id, const char *name, collecte
416 td->next = rd;
417 }
418
416 - if(host->health_enabled) {
419 + if(host->health_enabled && !is_archived) {
420 rrddimvar_create(rd, RRDVAR_TYPE_CALCULATED, NULL, NULL, &rd->last_stored_value, RRDVAR_OPTION_DEFAULT);
421 rrddimvar_create(rd, RRDVAR_TYPE_COLLECTED, NULL, "_raw", &rd->last_collected_value, RRDVAR_OPTION_DEFAULT);
422 rrddimvar_create(rd, RRDVAR_TYPE_TIME_T, NULL, "_last_collected_t", &rd->last_collected_time.tv_sec, RRDVAR_OPTION_DEFAULT);
database/rrdhost.c
+6
@@ -1415,6 +1415,12 @@ restart_after_removal:
1415 #ifdef ENABLE_DBENGINE
1416 if(st->rrd_memory_mode == RRD_MEMORY_MODE_DBENGINE) {
1417 rrdset_flag_set(st, RRDSET_FLAG_ARCHIVED);
1418 + while(st->variables) rrdsetvar_free(st->variables);
1419 + while(st->alarms) rrdsetcalc_unlink(st->alarms);
1420 +
1421 + debug(D_RRD_CALLS, "RRDSET: Cleaning up remaining chart variables for host '%s', chart '%s'", host->hostname, st->id);
1422 + rrdvar_free_remaining_variables(host, &st->rrdvar_root_index);
1423 +
1424 rrdset_flag_clear(st, RRDSET_FLAG_OBSOLETE);
1425 if (st->dimensions) {
1426 /* If the chart still has dimensions don't delete it from the metadata log */
database/rrdset.c
+23 -7
@@ -536,11 +536,13 @@ RRDSET *rrdset_create_custom(
536
537 RRDSET *st = rrdset_find_on_create(host, fullid);
538 if (st) {
539 + int changed_from_archived_to_active = 0;
540 int mark_rebuild = 0;
541 rrdset_flag_set(st, RRDSET_FLAG_SYNC_CLOCK);
542 rrdset_flag_clear(st, RRDSET_FLAG_UPSTREAM_EXPOSED);
543 if (!is_archived && rrdset_flag_check(st, RRDSET_FLAG_ARCHIVED)) {
544 rrdset_flag_clear(st, RRDSET_FLAG_ARCHIVED);
545 + changed_from_archived_to_active = 1;
546 mark_rebuild |= META_CHART_ACTIVATED;
547 }
548 char *old_plugin = NULL, *old_module = NULL, *old_title = NULL, *old_family = NULL, *old_context = NULL,
@@ -659,19 +661,28 @@ RRDSET *rrdset_create_custom(
661 metalog_commit_update_chart(st);
662 }
663 #endif
662 - return st;
664 + /* Fall-through during switch from archived to active so that the host lock is taken and health is linked */
665 + if (!changed_from_archived_to_active)
666 + return st;
667 }
668
669 rrdhost_wrlock(host);
670
671 st = rrdset_find_on_create(host, fullid);
672 if(st) {
669 - rrdhost_unlock(host);
670 - rrdset_flag_set(st, RRDSET_FLAG_SYNC_CLOCK);
671 - rrdset_flag_clear(st, RRDSET_FLAG_UPSTREAM_EXPOSED);
673 if (!is_archived && rrdset_flag_check(st, RRDSET_FLAG_ARCHIVED)) {
674 rrdset_flag_clear(st, RRDSET_FLAG_ARCHIVED);
675 + rrdsetvar_create(st, "last_collected_t", RRDVAR_TYPE_TIME_T, &st->last_collected_time.tv_sec, RRDVAR_OPTION_DEFAULT);
676 + rrdsetvar_create(st, "collected_total_raw", RRDVAR_TYPE_TOTAL, &st->last_collected_total, RRDVAR_OPTION_DEFAULT);
677 + rrdsetvar_create(st, "green", RRDVAR_TYPE_CALCULATED, &st->green, RRDVAR_OPTION_DEFAULT);
678 + rrdsetvar_create(st, "red", RRDVAR_TYPE_CALCULATED, &st->red, RRDVAR_OPTION_DEFAULT);
679 + rrdsetvar_create(st, "update_every", RRDVAR_TYPE_INT, &st->update_every, RRDVAR_OPTION_DEFAULT);
680 + rrdsetcalc_link_matching(st);
681 + rrdcalctemplate_link_matching(st);
682 }
683 + rrdhost_unlock(host);
684 + rrdset_flag_set(st, RRDSET_FLAG_SYNC_CLOCK);
685 + rrdset_flag_clear(st, RRDSET_FLAG_UPSTREAM_EXPOSED);
686 return st;
687 }
688
@@ -895,7 +906,7 @@ RRDSET *rrdset_create_custom(
906 st->next = host->rrdset_root;
907 host->rrdset_root = st;
908
898 - if(host->health_enabled) {
909 + if(host->health_enabled && !is_archived) {
910 rrdsetvar_create(st, "last_collected_t", RRDVAR_TYPE_TIME_T, &st->last_collected_time.tv_sec, RRDVAR_OPTION_DEFAULT);
911 rrdsetvar_create(st, "collected_total_raw", RRDVAR_TYPE_TOTAL, &st->last_collected_total, RRDVAR_OPTION_DEFAULT);
912 rrdsetvar_create(st, "green", RRDVAR_TYPE_CALCULATED, &st->green, RRDVAR_OPTION_DEFAULT);
@@ -906,8 +917,10 @@ RRDSET *rrdset_create_custom(
917 if(unlikely(rrdset_index_add(host, st) != st))
918 error("RRDSET: INTERNAL ERROR: attempt to index duplicate chart '%s'", st->id);
919
909 - rrdsetcalc_link_matching(st);
910 - rrdcalctemplate_link_matching(st);
920 + if (!is_archived) {
921 + rrdsetcalc_link_matching(st);
922 + rrdcalctemplate_link_matching(st);
923 + }
924 #ifdef ENABLE_DBENGINE
925 if (st->rrd_memory_mode == RRD_MEMORY_MODE_DBENGINE) {
926 int replace_instead_of_generate = 0;
@@ -1894,6 +1907,9 @@ void rrdset_done(RRDSET *st) {
1907 #ifdef ENABLE_DBENGINE
1908 if (rd->rrd_memory_mode == RRD_MEMORY_MODE_DBENGINE) {
1909 rrddim_flag_set(rd, RRDDIM_FLAG_ARCHIVED);
1910 + while(rd->variables)
1911 + rrddimvar_free(rd->variables);
1912 +
1913 rrddim_flag_clear(rd, RRDDIM_FLAG_OBSOLETE);
1914 /* only a collector can mark a chart as obsolete, so we must remove the reference */
1915 uint8_t can_delete_metric = rd->state->collect_ops.finalize(rd);
health/health.c
+2
@@ -199,6 +199,8 @@ void health_reload_host(RRDHOST *host) {
199 // link the loaded alarms to their charts
200 RRDDIM *rd;
201 rrdset_foreach_write(st, host) {
202 + if (rrdset_flag_check(st, RRDSET_FLAG_ARCHIVED))
203 + continue;
204 rrdsetcalc_link_matching(st);
205 rrdcalctemplate_link_matching(st);
206