diff options
author | vkalintiris <vasilis@netdata.cloud> | 2022-12-22 13:18:55 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-22 13:18:55 +0200 |
commit | 6f42311c4b32d42798f78de1fd43f53694f24e6e (patch) | |
tree | a48e85baea0d2feabdcddf1426a6a3c8c46c5568 /database | |
parent | c1aec98b30d8a4e80813cfccd636c31999c7ae3e (diff) |
Revert "Refactor ML code and add support for multiple KMeans models. … (#14172)
Diffstat (limited to 'database')
-rw-r--r-- | database/rrd.h | 18 | ||||
-rw-r--r-- | database/rrdcontext.c | 9 | ||||
-rw-r--r-- | database/rrddim.c | 12 | ||||
-rw-r--r-- | database/rrdhost.c | 6 | ||||
-rw-r--r-- | database/rrdset.c | 18 |
5 files changed, 24 insertions, 39 deletions
diff --git a/database/rrd.h b/database/rrd.h index f0d66a02ee..0796ff9012 100644 --- a/database/rrd.h +++ b/database/rrd.h @@ -30,9 +30,8 @@ typedef struct rrdhost_acquired RRDHOST_ACQUIRED; typedef struct rrdset_acquired RRDSET_ACQUIRED; typedef struct rrddim_acquired RRDDIM_ACQUIRED; -typedef struct ml_host ml_host_t; -typedef struct ml_chart ml_chart_t; -typedef struct ml_dimension ml_dimension_t; +typedef void *ml_host_t; +typedef void *ml_dimension_t; typedef enum { QUERY_SOURCE_UNKNOWN, @@ -297,7 +296,7 @@ struct rrddim { // ------------------------------------------------------------------------ // operational state members - ml_dimension_t *ml_dimension; // machine learning data about this dimension + ml_dimension_t ml_dimension; // machine learning data about this dimension // ------------------------------------------------------------------------ // linking to siblings and parents @@ -596,8 +595,6 @@ struct rrdset { DICTIONARY *rrddimvar_root_index; // dimension variables // we use this dictionary to manage their allocation - ml_chart_t *ml_chart; - // ------------------------------------------------------------------------ // operational state members @@ -1031,7 +1028,7 @@ struct rrdhost { // ------------------------------------------------------------------------ // ML handle - ml_host_t *ml_host; + ml_host_t ml_host; // ------------------------------------------------------------------------ // Support for host-level labels @@ -1304,12 +1301,9 @@ void rrdset_isnot_obsolete(RRDSET *st); time_t rrddim_first_entry_t(RRDDIM *rd); time_t rrddim_first_entry_t_of_tier(RRDDIM *rd, size_t tier); time_t rrddim_last_entry_t(RRDDIM *rd); -time_t rrddim_last_entry_t_of_tier(RRDDIM *rd, size_t tier); - -time_t rrdset_first_entry_t(RRDSET *st); -time_t rrdset_first_entry_t_of_tier(RRDSET *st, size_t tier); time_t rrdset_last_entry_t(RRDSET *st); - +time_t rrdset_first_entry_t_of_tier(RRDSET *st, size_t tier); +time_t rrdset_first_entry_t(RRDSET *st); time_t rrdhost_last_entry_t(RRDHOST *h); // ---------------------------------------------------------------------------- diff --git a/database/rrdcontext.c b/database/rrdcontext.c index 2df42ef47b..3413d1ea82 100644 --- a/database/rrdcontext.c +++ b/database/rrdcontext.c @@ -750,6 +750,11 @@ static void rrdinstance_free(RRDINSTANCE *ri) { } static void rrdinstance_insert_callback(const DICTIONARY_ITEM *item __maybe_unused, void *value, void *rrdcontext) { + static STRING *ml_anomaly_rates_id = NULL; + + if(unlikely(!ml_anomaly_rates_id)) + ml_anomaly_rates_id = string_strdupz(ML_ANOMALY_RATES_CHART_ID); + RRDINSTANCE *ri = value; // link it to its parent @@ -776,6 +781,10 @@ static void rrdinstance_insert_callback(const DICTIONARY_ITEM *item __maybe_unus ri->flags &= ~RRD_FLAG_HIDDEN; // no need of atomics at the constructor } + // we need this when loading from SQL + if(unlikely(ri->id == ml_anomaly_rates_id)) + ri->flags |= RRD_FLAG_HIDDEN; // no need of atomics at the constructor + rrdmetrics_create_in_rrdinstance(ri); // signal the react callback to do the job diff --git a/database/rrddim.c b/database/rrddim.c index 07f6c5d9d7..2d909a7015 100644 --- a/database/rrddim.c +++ b/database/rrddim.c @@ -172,7 +172,7 @@ static void rrddim_insert_callback(const DICTIONARY_ITEM *item __maybe_unused, v rrdset_flag_set(st, RRDSET_FLAG_SYNC_CLOCK); rrdset_flag_clear(st, RRDSET_FLAG_UPSTREAM_EXPOSED); - ml_dimension_new(rd); + ml_new_dimension(rd); ctr->react_action = RRDDIM_REACT_NEW; @@ -191,7 +191,7 @@ static void rrddim_delete_callback(const DICTIONARY_ITEM *item __maybe_unused, v rrdcontext_removed_rrddim(rd); - ml_dimension_delete(rd); + ml_delete_dimension(rd); debug(D_RRD_CALLS, "rrddim_free() %s.%s", rrdset_name(st), rrddim_name(rd)); @@ -420,13 +420,7 @@ inline int rrddim_set_divisor(RRDSET *st, RRDDIM *rd, collected_number divisor) // ---------------------------------------------------------------------------- -time_t rrddim_last_entry_t_of_tier(RRDDIM *rd, size_t tier) { - if(unlikely(tier > storage_tiers || !rd->tiers[tier])) - return 0; - - return rd->tiers[tier]->query_ops->latest_time(rd->tiers[tier]->db_metric_handle); -} - +// get the timestamp of the last entry in the round-robin database time_t rrddim_last_entry_t(RRDDIM *rd) { time_t latest = rd->tiers[0]->query_ops->latest_time(rd->tiers[0]->db_metric_handle); diff --git a/database/rrdhost.c b/database/rrdhost.c index 4982683078..5ba13d47be 100644 --- a/database/rrdhost.c +++ b/database/rrdhost.c @@ -518,7 +518,7 @@ int is_legacy = 1; rrdhost_load_rrdcontext_data(host); if (!archived) - ml_host_new(host); + ml_new_host(host); else rrdhost_flag_set(host, RRDHOST_FLAG_ARCHIVED); @@ -629,7 +629,7 @@ void rrdhost_update(RRDHOST *host host->rrdpush_replication_step = rrdpush_replication_step; rrd_hosts_available++; - ml_host_new(host); + ml_new_host(host); rrdhost_load_rrdcontext_data(host); info("Host %s is not in archived mode anymore", rrdhost_hostname(host)); } @@ -1089,7 +1089,7 @@ void rrdhost_free(RRDHOST *host, bool force) { rrd_check_wrlock(); // make sure the RRDs are write locked rrdhost_wrlock(host); - ml_host_delete(host); + ml_delete_host(host); rrdhost_unlock(host); // ------------------------------------------------------------------------ diff --git a/database/rrdset.c b/database/rrdset.c index 8a1cd6d90b..6eb3c7105f 100644 --- a/database/rrdset.c +++ b/database/rrdset.c @@ -178,8 +178,6 @@ static void rrdset_insert_callback(const DICTIONARY_ITEM *item __maybe_unused, v st->red = NAN; ctr->react_action = RRDSET_REACT_NEW; - - ml_chart_new(st); } // the destructor - the dictionary is write locked while this runs @@ -234,9 +232,6 @@ static void rrdset_delete_callback(const DICTIONARY_ITEM *item __maybe_unused, v // 7. destroy the chart labels rrdlabels_destroy(st->rrdlabels); // destroy the labels, after letting the contexts know - // 8. destroy the ml handle - ml_chart_delete(st); - rrdset_memory_file_free(st); // remove files of db mode save and map // ------------------------------------------------------------------------ @@ -1258,8 +1253,6 @@ static inline size_t rrdset_done_interpolate( last_ut = next_store_ut; - ml_chart_update_begin(st); - struct rda_item *rda; size_t dim_id; for(dim_id = 0, rda = rda_base ; dim_id < rda_slots ; ++dim_id, ++rda) { @@ -1339,11 +1332,8 @@ static inline size_t rrdset_done_interpolate( break; } - time_t current_time = (time_t) (next_store_ut / USEC_PER_SEC); - if(unlikely(!store_this_entry)) { - (void) ml_is_anomalous(rd, current_time, 0, false); - + (void) ml_is_anomalous(rd, 0, false); rrddim_store_metric(rd, next_store_ut, NAN, SN_FLAG_NONE); rrdcontext_collected_rrddim(rd); continue; @@ -1352,7 +1342,7 @@ static inline size_t rrdset_done_interpolate( if(likely(rd->updated && rd->collections_counter > 1 && iterations < st->gap_when_lost_iterations_above)) { uint32_t dim_storage_flags = storage_flags; - if (ml_is_anomalous(rd, current_time, new_value, true)) { + if (ml_is_anomalous(rd, new_value, true)) { // clear anomaly bit: 0 -> is anomalous, 1 -> not anomalous dim_storage_flags &= ~((storage_number)SN_FLAG_NOT_ANOMALOUS); } @@ -1362,7 +1352,7 @@ static inline size_t rrdset_done_interpolate( rd->last_stored_value = new_value; } else { - (void) ml_is_anomalous(rd, current_time, 0, false); + (void) ml_is_anomalous(rd, 0, false); rrdset_debug(st, "%s: STORE[%ld] = NON EXISTING ", rrddim_name(rd), current_entry); @@ -1374,8 +1364,6 @@ static inline size_t rrdset_done_interpolate( stored_entries++; } - ml_chart_update_end(st); - // reset the storage flags for the next point, if any; storage_flags = SN_DEFAULT_FLAGS; |