summaryrefslogtreecommitdiffstats
path: root/database/rrdset.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2022-06-09 04:52:47 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2022-06-09 04:52:57 +0000
commit00151562145df50cc65e9902d52d5fa77f89fe50 (patch)
tree2737716802f6725a5074d606ec8fe5422c58a83c /database/rrdset.c
parentReleasing debian version 1.34.1-1. (diff)
downloadnetdata-00151562145df50cc65e9902d52d5fa77f89fe50.tar.xz
netdata-00151562145df50cc65e9902d52d5fa77f89fe50.zip
Merging upstream version 1.35.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'database/rrdset.c')
-rw-r--r--database/rrdset.c118
1 files changed, 48 insertions, 70 deletions
diff --git a/database/rrdset.c b/database/rrdset.c
index f8e471be7..e7cb89df0 100644
--- a/database/rrdset.c
+++ b/database/rrdset.c
@@ -125,7 +125,7 @@ char *rrdset_strncpyz_name(char *to, const char *from, size_t length) {
char c, *p = to;
while (length-- && (c = *from++)) {
- if(c != '.' && !isalnum(c))
+ if(c != '.' && c != '-' && !isalnum(c))
c = '_';
*p++ = c;
@@ -366,11 +366,6 @@ void rrdset_free(RRDSET *st) {
rrdvar_free_remaining_variables(host, &st->rrdvar_root_index);
// ------------------------------------------------------------------------
- // remove it from the configuration
-
- appconfig_section_destroy_non_loaded(&netdata_config, st->config_section);
-
- // ------------------------------------------------------------------------
// unlink it from the host
if(st == host->rrdset_root) {
@@ -402,10 +397,10 @@ void rrdset_free(RRDSET *st) {
freez(st->units);
freez(st->context);
freez(st->cache_dir);
- freez(st->config_section);
freez(st->plugin_name);
freez(st->module_name);
freez(st->state->old_title);
+ freez(st->state->old_units);
freez(st->state->old_context);
free_label_list(st->state->labels.head);
freez(st->state);
@@ -557,6 +552,10 @@ RRDSET *rrdset_create_custom(
return NULL;
}
+ if (host != localhost) {
+ host->senders_last_chart_command = now_realtime_sec();
+ }
+
// ------------------------------------------------------------------------
// check if it already exists
@@ -567,15 +566,13 @@ RRDSET *rrdset_create_custom(
RRDSET *st = rrdset_find_on_create(host, fullid);
if (st) {
int mark_rebuild = 0;
- rrdset_flag_set(st, RRDSET_FLAG_SYNC_CLOCK);
- rrdset_flag_clear(st, RRDSET_FLAG_UPSTREAM_EXPOSED);
if (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_context = NULL,
- *old_title_v = NULL, *old_context_v = NULL;
+ *old_title_v = NULL, *old_context_v = NULL, *old_units_v = NULL, *old_units = NULL;
int rc;
if(unlikely(name))
@@ -635,6 +632,17 @@ RRDSET *rrdset_create_custom(
mark_rebuild |= META_CHART_UPDATED;
}
+ if (unlikely(units && st->state->old_units && strcmp(st->state->old_units, units))) {
+ char *new_units = strdupz(units);
+ old_units_v = st->state->old_units;
+ st->state->old_units = strdupz(units);
+ json_fix_string(new_units);
+ old_units= st->units;
+ st->units = new_units;
+ mark_rebuild |= META_CHART_UPDATED;
+ }
+
+
if (st->chart_type != chart_type) {
st->chart_type = chart_type;
mark_rebuild |= META_CHART_UPDATED;
@@ -671,8 +679,10 @@ RRDSET *rrdset_create_custom(
freez(old_plugin);
freez(old_module);
freez(old_title);
+ freez(old_units);
freez(old_context);
freez(old_title_v);
+ freez(old_units_v);
freez(old_context_v);
if (mark_rebuild != META_CHART_ACTIVATED) {
info("Collector updated metadata for chart %s", st->id);
@@ -684,6 +694,11 @@ RRDSET *rrdset_create_custom(
int rc = update_chart_metadata(st->chart_uuid, st, id, name);
if (unlikely(rc))
error_report("Failed to update chart metadata in the database");
+
+ if (!changed_from_archived_to_active) {
+ rrdset_flag_set(st, RRDSET_FLAG_SYNC_CLOCK);
+ rrdset_flag_clear(st, RRDSET_FLAG_UPSTREAM_EXPOSED);
+ }
}
/* 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)
@@ -713,26 +728,14 @@ RRDSET *rrdset_create_custom(
char fullfilename[FILENAME_MAX + 1];
// ------------------------------------------------------------------------
- // compose the config_section for this chart
-
- char config_section[RRD_ID_LENGTH_MAX + GUID_LEN + 2];
- if(host == localhost)
- strcpy(config_section, fullid);
- else
- snprintfz(config_section, RRD_ID_LENGTH_MAX + GUID_LEN + 1, "%s/%s", host->machine_guid, fullid);
-
- // ------------------------------------------------------------------------
// get the options from the config, we need to create it
- long entries;
- int enabled = config_get_boolean(config_section, "enabled", 1);
- if(!enabled || memory_mode == RRD_MEMORY_MODE_DBENGINE)
- entries = 5;
- else
+ long entries = 5;
+ if (memory_mode != RRD_MEMORY_MODE_DBENGINE)
entries = align_entries_to_pagesize(memory_mode, history_entries);
unsigned long size = sizeof(RRDSET);
- char *cache_dir = rrdset_cache_dir(host, fullid, config_section);
+ char *cache_dir = rrdset_cache_dir(host, fullid);
time_t now = now_realtime_sec();
@@ -744,12 +747,11 @@ RRDSET *rrdset_create_custom(
snprintfz(fullfilename, FILENAME_MAX, "%s/main.db", cache_dir);
if(memory_mode == RRD_MEMORY_MODE_SAVE || memory_mode == RRD_MEMORY_MODE_MAP ||
memory_mode == RRD_MEMORY_MODE_RAM) {
- st = (RRDSET *) mymmap(
- (memory_mode == RRD_MEMORY_MODE_RAM) ? NULL : fullfilename
- , size
- , ((memory_mode == RRD_MEMORY_MODE_MAP) ? MAP_SHARED : MAP_PRIVATE)
- , 0
- );
+ st = (RRDSET *)netdata_mmap(
+ (memory_mode == RRD_MEMORY_MODE_RAM) ? NULL : fullfilename,
+ size,
+ ((memory_mode == RRD_MEMORY_MODE_MAP) ? MAP_SHARED : MAP_PRIVATE),
+ 0);
if(st) {
memset(&st->avl, 0, sizeof(avl_t));
@@ -759,7 +761,6 @@ RRDSET *rrdset_create_custom(
memset(&st->rrdset_rwlock, 0, sizeof(netdata_rwlock_t));
st->name = NULL;
- st->config_section = NULL;
st->type = NULL;
st->family = NULL;
st->title = NULL;
@@ -832,7 +833,6 @@ RRDSET *rrdset_create_custom(
st->plugin_name = plugin?strdupz(plugin):NULL;
st->module_name = module?strdupz(module):NULL;
- st->config_section = strdupz(config_section);
st->rrdhost = host;
st->memsize = size;
st->entries = entries;
@@ -859,6 +859,7 @@ RRDSET *rrdset_create_custom(
st->state->is_ar_chart = strcmp(st->id, ML_ANOMALY_RATES_CHART_ID) == 0;
st->units = units ? strdupz(units) : strdupz("");
+ st->state->old_units = strdupz(st->units);
json_fix_string(st->units);
st->context = context ? strdupz(context) : strdupz(st->id);
@@ -867,27 +868,9 @@ RRDSET *rrdset_create_custom(
st->hash_context = simple_hash(st->context);
st->priority = priority;
- if(enabled)
- rrdset_flag_set(st, RRDSET_FLAG_ENABLED);
- else
- rrdset_flag_clear(st, RRDSET_FLAG_ENABLED);
- rrdset_flag_clear(st, RRDSET_FLAG_DETAIL);
- rrdset_flag_clear(st, RRDSET_FLAG_DEBUG);
- rrdset_flag_clear(st, RRDSET_FLAG_OBSOLETE);
- rrdset_flag_clear(st, RRDSET_FLAG_EXPORTING_SEND);
- rrdset_flag_clear(st, RRDSET_FLAG_EXPORTING_IGNORE);
- rrdset_flag_clear(st, RRDSET_FLAG_UPSTREAM_SEND);
- rrdset_flag_clear(st, RRDSET_FLAG_UPSTREAM_IGNORE);
- rrdset_flag_clear(st, RRDSET_FLAG_UPSTREAM_EXPOSED);
rrdset_flag_set(st, RRDSET_FLAG_SYNC_CLOCK);
- // if(!strcmp(st->id, "disk_util.dm-0")) {
- // st->debug = 1;
- // error("enabled debugging for '%s'", st->id);
- // }
- // else error("not enabled debugging for '%s'", st->id);
-
st->green = NAN;
st->red = NAN;
@@ -960,7 +943,7 @@ RRDSET *rrdset_create_custom(
// RRDSET - data collection iteration control
inline void rrdset_next_usec_unfiltered(RRDSET *st, usec_t microseconds) {
- if(unlikely(!st->last_collected_time.tv_sec || !microseconds || (rrdset_flag_check_noatomic(st, RRDSET_FLAG_SYNC_CLOCK)))) {
+ if(unlikely(!st->last_collected_time.tv_sec || !microseconds || (rrdset_flag_check(st, RRDSET_FLAG_SYNC_CLOCK)))) {
// call the full next_usec() function
rrdset_next_usec(st, microseconds);
return;
@@ -978,7 +961,7 @@ inline void rrdset_next_usec(RRDSET *st, usec_t microseconds) {
usec_t discarded = microseconds;
#endif
- if(unlikely(rrdset_flag_check_noatomic(st, RRDSET_FLAG_SYNC_CLOCK))) {
+ if(unlikely(rrdset_flag_check(st, RRDSET_FLAG_SYNC_CLOCK))) {
// the chart needs to be re-synced to current time
rrdset_flag_clear(st, RRDSET_FLAG_SYNC_CLOCK);
@@ -1010,7 +993,9 @@ inline void rrdset_next_usec(RRDSET *st, usec_t microseconds) {
if(unlikely(since_last_usec < 0)) {
// oops! the database is in the future
+ #ifdef NETDATA_INTERNAL_CHECKS
info("RRD database for chart '%s' on host '%s' is %0.5" LONG_DOUBLE_MODIFIER " secs in the future (counter #%zu, update #%zu). Adjusting it to current time.", st->id, st->rrdhost->hostname, (LONG_DOUBLE)-since_last_usec / USEC_PER_SEC, st->counter, st->counter_done);
+ #endif
st->last_collected_time.tv_sec = now.tv_sec - st->update_every;
st->last_collected_time.tv_usec = now.tv_usec;
@@ -1027,7 +1012,9 @@ inline void rrdset_next_usec(RRDSET *st, usec_t microseconds) {
}
else if(unlikely((usec_t)since_last_usec > (usec_t)(st->update_every * 5 * USEC_PER_SEC))) {
// oops! the database is too far behind
+ #ifdef NETDATA_INTERNAL_CHECKS
info("RRD database for chart '%s' on host '%s' is %0.5" LONG_DOUBLE_MODIFIER " secs in the past (counter #%zu, update #%zu). Adjusting it to current time.", st->id, st->rrdhost->hostname, (LONG_DOUBLE)since_last_usec / USEC_PER_SEC, st->counter, st->counter_done);
+ #endif
microseconds = (usec_t)since_last_usec;
#ifdef NETDATA_INTERNAL_CHECKS
@@ -1403,8 +1390,9 @@ void rrdset_done(RRDSET *st) {
#ifdef ENABLE_ACLK
if (likely(!st->state->is_ar_chart)) {
if (unlikely(!rrdset_flag_check(st, RRDSET_FLAG_ACLK))) {
- if (likely(st->dimensions && st->counter_done && !queue_chart_to_aclk(st)))
+ if (likely(st->dimensions && st->counter_done && !queue_chart_to_aclk(st))) {
rrdset_flag_set(st, RRDSET_FLAG_ACLK);
+ }
}
}
#endif
@@ -1823,7 +1811,7 @@ after_first_database_work:
after_second_database_work:
st->last_collected_total = st->collected_total;
-#ifdef ENABLE_NEW_CLOUD_PROTOCOL
+#if defined(ENABLE_ACLK) && defined(ENABLE_NEW_CLOUD_PROTOCOL)
time_t mark = now_realtime_sec();
#endif
rrddim_foreach_read(rd, st) {
@@ -1831,20 +1819,10 @@ 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_DIM_LIVE_MULTIPLIER * rd->update_every);
- if (unlikely(live != rd->state->aclk_live_status)) {
- if (likely(rrdset_flag_check(st, RRDSET_FLAG_ACLK))) {
- if (likely(!queue_dimension_to_aclk(rd))) {
- rd->state->aclk_live_status = live;
- rrddim_flag_set(rd, RRDDIM_FLAG_ACLK);
- }
- }
- }
+ if (likely(!st->state->is_ar_chart)) {
+ if (!rrddim_flag_check(rd, RRDDIM_FLAG_HIDDEN) && likely(rrdset_flag_check(st, RRDSET_FLAG_ACLK)))
+ queue_dimension_to_aclk(rd, calc_dimension_liveness(rd, mark));
}
- }
#endif
if(unlikely(!rd->updated))
continue;
@@ -1946,7 +1924,7 @@ after_second_database_work:
} else {
/* Do not delete this dimension */
#if defined(ENABLE_ACLK) && defined(ENABLE_NEW_CLOUD_PROTOCOL)
- aclk_send_dimension_update(rd);
+ queue_dimension_to_aclk(rd, calc_dimension_liveness(rd, mark));
#endif
last = rd;
rd = rd->next;
@@ -1996,7 +1974,7 @@ void rrdset_finalize_labels(RRDSET *st)
replace_label_list(labels, new_labels);
}
- netdata_rwlock_wrlock(&labels->labels_rwlock);
+ netdata_rwlock_rdlock(&labels->labels_rwlock);
struct label *lbl = labels->head;
while (lbl) {
sql_store_chart_label(st->chart_uuid, (int)lbl->label_source, lbl->key, lbl->value);