diff options
author | vkalintiris <vasilis@netdata.cloud> | 2022-02-24 10:57:30 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-24 10:57:30 +0200 |
commit | 69ea17d6ec534e1ed796a92fd042bd76a3ca9215 (patch) | |
tree | 4345e3405b2ac1e37a9be1615d6dad799e15327d /database | |
parent | 8756eb80c77caf411f7fae605d3f1bb03dd60b76 (diff) |
Track anomaly rates with DBEngine. (#12083)
* Track anomaly rates with DBEngine.
This commit adds support for tracking anomaly rates with DBEngine. We
do so by creating a single chart with id "anomaly_detection.anomaly_rates" for
each trainable/predictable host, which is responsible for tracking the anomaly
rate of each dimension that we train/predict for that host.
The rrdset->state->is_ar_chart boolean flag is set to true only for anomaly
rates charts. We use this flag to:
- Disable exposing the anomaly rates charts through the functionality
in backends/, exporting/ and streaming/.
- Skip generation of configuration options for the name, algorithm,
multiplier, divisor of each dimension in an anomaly rates chart.
- Skip the creation of health variables for anomaly rates dimensions.
- Skip the chart/dim queue of ACLK.
- Post-process the RRDR result of an anomaly rates chart, so that we can
return a sorted, trimmed number of anomalous dimensions.
In a child/parent configuration where both the child and the parent run
ML for the child, we want to be able to stream the rest of the ML-related
charts to the parent. To be able to do this without any chart name collisions,
the charts are now created on localhost and their IDs and titles have the node's
machine_guid and hostname as a suffix, respectively.
* Fix exporting_engine tests.
* Restore default ML configuration.
The reverted changes where meant for local testing only. This commit
restores the default values that we want to have when someone runs
anomaly detection on their node.
* Set context for anomaly_detection.* charts.
* Check for anomaly rates chart only with a valid pointer.
* Remove duplicate code.
* Use a more descriptive name for id/title pair variable
Diffstat (limited to 'database')
-rw-r--r-- | database/rrd.h | 1 | ||||
-rw-r--r-- | database/rrddim.c | 10 | ||||
-rw-r--r-- | database/rrdhost.c | 12 | ||||
-rw-r--r-- | database/rrdset.c | 15 | ||||
-rw-r--r-- | database/sqlite/sqlite_aclk_node.c | 4 |
5 files changed, 27 insertions, 15 deletions
diff --git a/database/rrd.h b/database/rrd.h index 680a4a055d..1137983794 100644 --- a/database/rrd.h +++ b/database/rrd.h @@ -436,6 +436,7 @@ struct rrdset_volatile { uuid_t hash_id; struct label *new_labels; struct label_index labels; + bool is_ar_chart; }; // ---------------------------------------------------------------------------- diff --git a/database/rrddim.c b/database/rrddim.c index 9a2837b2b4..6829cbb3d4 100644 --- a/database/rrddim.c +++ b/database/rrddim.c @@ -73,9 +73,15 @@ inline int rrddim_set_name(RRDSET *st, RRDDIM *rd, const char *name) { snprintfz(varname, CONFIG_MAX_NAME, "dim %s name", rd->id); rd->name = config_set_default(st->config_section, varname, name); rd->hash_name = simple_hash(rd->name); - rrddimvar_rename_all(rd); + + if (!st->state->is_ar_chart) + rrddimvar_rename_all(rd); + rd->exposed = 0; rrdset_flag_clear(st, RRDSET_FLAG_UPSTREAM_EXPOSED); + + ml_dimension_update_name(st, rd, name); + return 1; } @@ -438,7 +444,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 && !st->state->is_ar_chart) { 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 dcdde6388d..b33b749b24 100644 --- a/database/rrdhost.c +++ b/database/rrdhost.c @@ -385,17 +385,15 @@ RRDHOST *rrdhost_create(const char *hostname, // ------------------------------------------------------------------------ // init new ML host and update system_info to let upstreams know // about ML functionality + // - ml_new_host(host); if (is_localhost && host->system_info) { -#ifndef ENABLE_ML - host->system_info->ml_capable = 0; -#else - host->system_info->ml_capable = 1; -#endif - host->system_info->ml_enabled = host->ml_host != NULL; + host->system_info->ml_capable = ml_capable(); + host->system_info->ml_enabled = ml_enabled(host); } + ml_new_host(host); + info("Host '%s' (at registry as '%s') with guid '%s' initialized" ", os '%s'" ", timezone '%s'" diff --git a/database/rrdset.c b/database/rrdset.c index edd7ce4ab8..385d7b4d01 100644 --- a/database/rrdset.c +++ b/database/rrdset.c @@ -847,9 +847,12 @@ RRDSET *rrdset_create_custom( st->type = strdupz(type); st->state = callocz(1, sizeof(*st->state)); + st->family = family ? strdupz(family) : strdupz(st->type); json_fix_string(st->family); + st->state->is_ar_chart = strcmp(st->id, ML_ANOMALY_RATES_CHART_ID) == 0; + st->units = units ? strdupz(units) : strdupz(""); json_fix_string(st->units); @@ -1395,10 +1398,12 @@ void rrdset_done(RRDSET *st) { rrdset_rdlock(st); #ifdef ENABLE_ACLK - if (unlikely(!rrdset_flag_check(st, RRDSET_FLAG_ACLK))) { - if (st->counter_done >= RRDSET_MINIMUM_LIVE_COUNT && st->dimensions) { - if (likely(!queue_chart_to_aclk(st))) - rrdset_flag_set(st, RRDSET_FLAG_ACLK); + if (likely(!st->state->is_ar_chart)) { + if (unlikely(!rrdset_flag_check(st, RRDSET_FLAG_ACLK))) { + if (st->counter_done >= RRDSET_MINIMUM_LIVE_COUNT && st->dimensions) { + if (likely(!queue_chart_to_aclk(st))) + rrdset_flag_set(st, RRDSET_FLAG_ACLK); + } } } #endif @@ -1825,6 +1830,7 @@ after_second_database_work: continue; #if defined(ENABLE_ACLK) && defined(ENABLE_NEW_CLOUD_PROTOCOL) + if (likely(!st->state->is_ar_chart)) { if (!rrddim_flag_check(rd, RRDDIM_FLAG_HIDDEN)) { int live = ((mark - rd->last_collected_time.tv_sec) < (RRDSET_MINIMUM_LIVE_COUNT * rd->update_every)); if (unlikely(live != rd->state->aclk_live_status)) { @@ -1836,6 +1842,7 @@ after_second_database_work: } } } + } #endif if(unlikely(!rd->updated)) continue; diff --git a/database/sqlite/sqlite_aclk_node.c b/database/sqlite/sqlite_aclk_node.c index 6261b9af56..9464c41f27 100644 --- a/database/sqlite/sqlite_aclk_node.c +++ b/database/sqlite/sqlite_aclk_node.c @@ -22,8 +22,8 @@ void sql_build_node_info(struct aclk_database_worker_config *wc, struct aclk_dat node_info.claim_id = is_agent_claimed(); node_info.machine_guid = wc->host_guid; node_info.child = (wc->host != localhost); - node_info.ml_info.ml_capable = localhost->system_info->ml_capable; - node_info.ml_info.ml_enabled = wc->host->ml_host != NULL; + node_info.ml_info.ml_capable = ml_capable(localhost); + node_info.ml_info.ml_enabled = ml_enabled(wc->host); now_realtime_timeval(&node_info.updated_at); RRDHOST *host = wc->host; |