diff options
author | Markos Fountoulakis <44345837+mfundul@users.noreply.github.com> | 2020-07-11 17:27:37 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-11 17:27:37 +0300 |
commit | 822880265e88a8f6a6d35d00eb0d0b5072d7ac1c (patch) | |
tree | 1c5b20ec1ee9af929dd6a98c0072fb05d75f7cbb /database | |
parent | 04b7e098810aeb8d1b708d0da2e1ae8153dedf0e (diff) |
Remove health from archived metrics (#9520)
* Disassociate health variables and alarms from archived charts and dimensions.
* Ignore archived charts during health reload.
Diffstat (limited to 'database')
-rw-r--r-- | database/rrddim.c | 5 | ||||
-rw-r--r-- | database/rrdhost.c | 6 | ||||
-rw-r--r-- | database/rrdset.c | 30 |
3 files changed, 33 insertions, 8 deletions
diff --git a/database/rrddim.c b/database/rrddim.c index bb76e332f6..05eb46040c 100644 --- a/database/rrddim.c +++ b/database/rrddim.c @@ -209,6 +209,9 @@ RRDDIM *rrddim_add_custom(RRDSET *st, const char *id, const char *name, collecte if (!is_archived && rrddim_flag_check(rd, RRDDIM_FLAG_ARCHIVED)) { rd->state->collect_ops.init(rd); rrddim_flag_clear(rd, RRDDIM_FLAG_ARCHIVED); + rrddimvar_create(rd, RRDVAR_TYPE_CALCULATED, NULL, NULL, &rd->last_stored_value, RRDVAR_OPTION_DEFAULT); + rrddimvar_create(rd, RRDVAR_TYPE_COLLECTED, NULL, "_raw", &rd->last_collected_value, RRDVAR_OPTION_DEFAULT); + rrddimvar_create(rd, RRDVAR_TYPE_TIME_T, NULL, "_last_collected_t", &rd->last_collected_time.tv_sec, RRDVAR_OPTION_DEFAULT); } // DBENGINE available and activated? #ifdef ENABLE_DBENGINE @@ -413,7 +416,7 @@ RRDDIM *rrddim_add_custom(RRDSET *st, const char *id, const char *name, collecte td->next = rd; } - if(host->health_enabled) { + if(host->health_enabled && !is_archived) { rrddimvar_create(rd, RRDVAR_TYPE_CALCULATED, NULL, NULL, &rd->last_stored_value, RRDVAR_OPTION_DEFAULT); rrddimvar_create(rd, RRDVAR_TYPE_COLLECTED, NULL, "_raw", &rd->last_collected_value, RRDVAR_OPTION_DEFAULT); rrddimvar_create(rd, RRDVAR_TYPE_TIME_T, NULL, "_last_collected_t", &rd->last_collected_time.tv_sec, RRDVAR_OPTION_DEFAULT); diff --git a/database/rrdhost.c b/database/rrdhost.c index 6c909197d2..4e8488534f 100644 --- a/database/rrdhost.c +++ b/database/rrdhost.c @@ -1415,6 +1415,12 @@ restart_after_removal: #ifdef ENABLE_DBENGINE if(st->rrd_memory_mode == RRD_MEMORY_MODE_DBENGINE) { rrdset_flag_set(st, RRDSET_FLAG_ARCHIVED); + while(st->variables) rrdsetvar_free(st->variables); + while(st->alarms) rrdsetcalc_unlink(st->alarms); + + debug(D_RRD_CALLS, "RRDSET: Cleaning up remaining chart variables for host '%s', chart '%s'", host->hostname, st->id); + rrdvar_free_remaining_variables(host, &st->rrdvar_root_index); + rrdset_flag_clear(st, RRDSET_FLAG_OBSOLETE); if (st->dimensions) { /* If the chart still has dimensions don't delete it from the metadata log */ diff --git a/database/rrdset.c b/database/rrdset.c index 9fdfdf16b5..bf9175a614 100644 --- a/database/rrdset.c +++ b/database/rrdset.c @@ -536,11 +536,13 @@ RRDSET *rrdset_create_custom( RRDSET *st = rrdset_find_on_create(host, fullid); if (st) { + int changed_from_archived_to_active = 0; int mark_rebuild = 0; rrdset_flag_set(st, RRDSET_FLAG_SYNC_CLOCK); rrdset_flag_clear(st, RRDSET_FLAG_UPSTREAM_EXPOSED); if (!is_archived && rrdset_flag_check(st, RRDSET_FLAG_ARCHIVED)) { rrdset_flag_clear(st, RRDSET_FLAG_ARCHIVED); + changed_from_archived_to_active = 1; mark_rebuild |= META_CHART_ACTIVATED; } char *old_plugin = NULL, *old_module = NULL, *old_title = NULL, *old_family = NULL, *old_context = NULL, @@ -659,19 +661,28 @@ RRDSET *rrdset_create_custom( metalog_commit_update_chart(st); } #endif - return st; + /* Fall-through during switch from archived to active so that the host lock is taken and health is linked */ + if (!changed_from_archived_to_active) + return st; } rrdhost_wrlock(host); st = rrdset_find_on_create(host, fullid); if(st) { - rrdhost_unlock(host); - rrdset_flag_set(st, RRDSET_FLAG_SYNC_CLOCK); - rrdset_flag_clear(st, RRDSET_FLAG_UPSTREAM_EXPOSED); if (!is_archived && rrdset_flag_check(st, RRDSET_FLAG_ARCHIVED)) { rrdset_flag_clear(st, RRDSET_FLAG_ARCHIVED); + rrdsetvar_create(st, "last_collected_t", RRDVAR_TYPE_TIME_T, &st->last_collected_time.tv_sec, RRDVAR_OPTION_DEFAULT); + rrdsetvar_create(st, "collected_total_raw", RRDVAR_TYPE_TOTAL, &st->last_collected_total, RRDVAR_OPTION_DEFAULT); + rrdsetvar_create(st, "green", RRDVAR_TYPE_CALCULATED, &st->green, RRDVAR_OPTION_DEFAULT); + rrdsetvar_create(st, "red", RRDVAR_TYPE_CALCULATED, &st->red, RRDVAR_OPTION_DEFAULT); + rrdsetvar_create(st, "update_every", RRDVAR_TYPE_INT, &st->update_every, RRDVAR_OPTION_DEFAULT); + rrdsetcalc_link_matching(st); + rrdcalctemplate_link_matching(st); } + rrdhost_unlock(host); + rrdset_flag_set(st, RRDSET_FLAG_SYNC_CLOCK); + rrdset_flag_clear(st, RRDSET_FLAG_UPSTREAM_EXPOSED); return st; } @@ -895,7 +906,7 @@ RRDSET *rrdset_create_custom( st->next = host->rrdset_root; host->rrdset_root = st; - if(host->health_enabled) { + if(host->health_enabled && !is_archived) { rrdsetvar_create(st, "last_collected_t", RRDVAR_TYPE_TIME_T, &st->last_collected_time.tv_sec, RRDVAR_OPTION_DEFAULT); rrdsetvar_create(st, "collected_total_raw", RRDVAR_TYPE_TOTAL, &st->last_collected_total, RRDVAR_OPTION_DEFAULT); rrdsetvar_create(st, "green", RRDVAR_TYPE_CALCULATED, &st->green, RRDVAR_OPTION_DEFAULT); @@ -906,8 +917,10 @@ RRDSET *rrdset_create_custom( if(unlikely(rrdset_index_add(host, st) != st)) error("RRDSET: INTERNAL ERROR: attempt to index duplicate chart '%s'", st->id); - rrdsetcalc_link_matching(st); - rrdcalctemplate_link_matching(st); + if (!is_archived) { + rrdsetcalc_link_matching(st); + rrdcalctemplate_link_matching(st); + } #ifdef ENABLE_DBENGINE if (st->rrd_memory_mode == RRD_MEMORY_MODE_DBENGINE) { int replace_instead_of_generate = 0; @@ -1894,6 +1907,9 @@ void rrdset_done(RRDSET *st) { #ifdef ENABLE_DBENGINE if (rd->rrd_memory_mode == RRD_MEMORY_MODE_DBENGINE) { rrddim_flag_set(rd, RRDDIM_FLAG_ARCHIVED); + while(rd->variables) + rrddimvar_free(rd->variables); + rrddim_flag_clear(rd, RRDDIM_FLAG_OBSOLETE); /* only a collector can mark a chart as obsolete, so we must remove the reference */ uint8_t can_delete_metric = rd->state->collect_ops.finalize(rd); |