@cryptotaxi247 / netdata-1 / commits / ebdd819d6

Remove per chart configuration. (#12728)

After https://github.com/netdata/netdata/pull/12209 per-chart configuration was used for (a) enabling/disabling a chart, and (b) renaming dimensions. Regarding the first use case: We already have component-specific configuration options|flags to finely control how a chart should behave. Eg. "send charts matching" in streaming, "charts to skip from training" in ML, etc. If we really need the concept of a disabled chart, we can add a host-level simple pattern to match these charts. Regarding the second use case: It's not obvious why we'd need to provide support for remapping dimension names through a chart-specific configuration from the core agent. If the need arises, we could add such support at the right place, ie. a exporter/streaming config section. This will allow each flag to act indepentendly from each other and avoid managing flag-state manually at various places, eg: ``` if(unlikely(!rrdset_flag_check(st, RRDSET_FLAG_ENABLED))) { rrdset_flag_clear(st, RRDSET_FLAG_UPSTREAM_SEND); rrdset_flag_set(st, RRDSET_FLAG_UPSTREAM_IGNORE); } ... ```

vkalintiris committed May 3, 2022 at 19:02 UTC ebdd819d6ead44c5bab80c69be4a7d419402fe3c
8 files changed +13 -50
database/rrd.c
+1 -2
@@ -139,8 +139,7 @@ const char *rrdset_type_name(RRDSET_TYPE chart_type) {
139 // ----------------------------------------------------------------------------
140 // RRD - cache directory
141
142 -char *rrdset_cache_dir(RRDHOST *host, const char *id, const char *config_section) {
143 - UNUSED(config_section);
142 +char *rrdset_cache_dir(RRDHOST *host, const char *id) {
143 char *ret = NULL;
144
145 char b[FILENAME_MAX + 1];
database/rrd.h
+4 -5
@@ -436,7 +436,6 @@ struct mem_query_handle {
436 // and may lead to missing information.
437
438 typedef enum rrdset_flags {
439 - RRDSET_FLAG_ENABLED = 1 << 0, // enables or disables a chart
439 RRDSET_FLAG_DETAIL = 1 << 1, // if set, the data set should be considered as a detail of another
440 // (the master data set should be the one that has the same family and is not detail)
441 RRDSET_FLAG_DEBUG = 1 << 2, // enables or disables debugging for a chart
@@ -481,7 +480,7 @@ struct rrdset {
480 // since the config always has a higher priority
481 // (the user overwrites the name of the charts)
482
484 - char *config_section; // the config section for the chart
483 + void *unused_ptr; // Unused field (previously it held the config section of the chart)
484
485 char *type; // the type of graph RRD_TYPE_* (a category, for determining graphing options)
486 char *family; // grouping sets under the same family
@@ -1086,8 +1085,8 @@ extern void rrdset_is_obsolete(RRDSET *st);
1085 extern void rrdset_isnot_obsolete(RRDSET *st);
1086
1087 // checks if the RRDSET should be offered to viewers
1089 -#define rrdset_is_available_for_viewers(st) (rrdset_flag_check(st, RRDSET_FLAG_ENABLED) && !rrdset_flag_check(st, RRDSET_FLAG_HIDDEN) && !rrdset_flag_check(st, RRDSET_FLAG_OBSOLETE) && !rrdset_flag_check(st, RRDSET_FLAG_ARCHIVED) && (st)->dimensions && (st)->rrd_memory_mode != RRD_MEMORY_MODE_NONE)
1090 -#define rrdset_is_available_for_exporting_and_alarms(st) (rrdset_flag_check(st, RRDSET_FLAG_ENABLED) && !rrdset_flag_check(st, RRDSET_FLAG_OBSOLETE) && !rrdset_flag_check(st, RRDSET_FLAG_ARCHIVED) && (st)->dimensions)
1088 +#define rrdset_is_available_for_viewers(st) (!rrdset_flag_check(st, RRDSET_FLAG_HIDDEN) && !rrdset_flag_check(st, RRDSET_FLAG_OBSOLETE) && !rrdset_flag_check(st, RRDSET_FLAG_ARCHIVED) && (st)->dimensions && (st)->rrd_memory_mode != RRD_MEMORY_MODE_NONE)
1089 +#define rrdset_is_available_for_exporting_and_alarms(st) (!rrdset_flag_check(st, RRDSET_FLAG_OBSOLETE) && !rrdset_flag_check(st, RRDSET_FLAG_ARCHIVED) && (st)->dimensions)
1090 #define rrdset_is_archived(st) (rrdset_flag_check(st, RRDSET_FLAG_ARCHIVED) && (st)->dimensions)
1091
1092 // get the total duration in seconds of the round robin database
@@ -1305,7 +1304,7 @@ extern int alarm_compare_name(void *a, void *b);
1304 extern avl_tree_lock rrdhost_root_index;
1305
1306 extern char *rrdset_strncpyz_name(char *to, const char *from, size_t length);
1308 -extern char *rrdset_cache_dir(RRDHOST *host, const char *id, const char *config_section);
1307 +extern char *rrdset_cache_dir(RRDHOST *host, const char *id);
1308
1309 #define rrddim_free(st, rd) rrddim_free_custom(st, rd, 0)
1310 extern void rrddim_free_custom(RRDSET *st, RRDDIM *rd, int db_rotated);
database/rrddim.c
+4 -3
@@ -43,9 +43,10 @@ inline int rrddim_set_name(RRDSET *st, RRDDIM *rd, const char *name) {
43
44 debug(D_RRD_CALLS, "rrddim_set_name() from %s.%s to %s.%s", st->name, rd->name, st->name, name);
45
46 - char varname[CONFIG_MAX_NAME + 1];
47 - snprintfz(varname, CONFIG_MAX_NAME, "dim %s name", rd->id);
48 - rd->name = config_set_default(st->config_section, varname, name);
46 + if (rd->name)
47 + freez((void *) rd->name);
48 +
49 + rd->name = strdupz(name);
50 rd->hash_name = simple_hash(rd->name);
51
52 if (!st->state->is_ar_chart)
database/rrdset.c
+3 -27
@@ -365,11 +365,6 @@ void rrdset_free(RRDSET *st) {
365 debug(D_RRD_CALLS, "RRDSET: Cleaning up remaining chart variables for host '%s', chart '%s'", host->hostname, st->id);
366 rrdvar_free_remaining_variables(host, &st->rrdvar_root_index);
367
368 - // ------------------------------------------------------------------------
369 - // remove it from the configuration
370 -
371 - appconfig_section_destroy_non_loaded(&netdata_config, st->config_section);
372 -
368 // ------------------------------------------------------------------------
369 // unlink it from the host
370
@@ -402,7 +397,6 @@ void rrdset_free(RRDSET *st) {
397 freez(st->units);
398 freez(st->context);
399 freez(st->cache_dir);
405 - freez(st->config_section);
400 freez(st->plugin_name);
401 freez(st->module_name);
402 freez(st->state->old_title);
@@ -712,27 +706,15 @@ RRDSET *rrdset_create_custom(
706
707 char fullfilename[FILENAME_MAX + 1];
708
715 - // ------------------------------------------------------------------------
716 - // compose the config_section for this chart
717 -
718 - char config_section[RRD_ID_LENGTH_MAX + GUID_LEN + 2];
719 - if(host == localhost)
720 - strcpy(config_section, fullid);
721 - else
722 - snprintfz(config_section, RRD_ID_LENGTH_MAX + GUID_LEN + 1, "%s/%s", host->machine_guid, fullid);
723 -
709 // ------------------------------------------------------------------------
710 // get the options from the config, we need to create it
711
727 - long entries;
728 - int enabled = config_get_boolean(config_section, "enabled", 1);
729 - if(!enabled || memory_mode == RRD_MEMORY_MODE_DBENGINE)
730 - entries = 5;
731 - else
712 + long entries = 5;
713 + if (memory_mode != RRD_MEMORY_MODE_DBENGINE)
714 entries = align_entries_to_pagesize(memory_mode, history_entries);
715
716 unsigned long size = sizeof(RRDSET);
735 - char *cache_dir = rrdset_cache_dir(host, fullid, config_section);
717 + char *cache_dir = rrdset_cache_dir(host, fullid);
718
719 time_t now = now_realtime_sec();
720
@@ -758,7 +740,6 @@ RRDSET *rrdset_create_custom(
740 memset(&st->rrdset_rwlock, 0, sizeof(netdata_rwlock_t));
741
742 st->name = NULL;
761 - st->config_section = NULL;
743 st->type = NULL;
744 st->family = NULL;
745 st->title = NULL;
@@ -831,7 +812,6 @@ RRDSET *rrdset_create_custom(
812 st->plugin_name = plugin?strdupz(plugin):NULL;
813 st->module_name = module?strdupz(module):NULL;
814
834 - st->config_section = strdupz(config_section);
815 st->rrdhost = host;
816 st->memsize = size;
817 st->entries = entries;
@@ -866,10 +846,6 @@ RRDSET *rrdset_create_custom(
846 st->hash_context = simple_hash(st->context);
847
848 st->priority = priority;
869 - if(enabled)
870 - rrdset_flag_set(st, RRDSET_FLAG_ENABLED);
871 - else
872 - rrdset_flag_clear(st, RRDSET_FLAG_ENABLED);
849
850 rrdset_flag_set(st, RRDSET_FLAG_SYNC_CLOCK);
851
exporting/tests/exporting_fixtures.c
-1
@@ -58,7 +58,6 @@ int setup_rrdhost()
58 st->rrdhost = localhost;
59 strcpy(st->id, "chart_id");
60 st->name = strdupz("chart_name");
61 - st->flags |= RRDSET_FLAG_ENABLED;
61 st->rrd_memory_mode |= RRD_MEMORY_MODE_SAVE;
62 st->update_every = 1;
63
health/health.c
-5
@@ -514,11 +514,6 @@ static inline int rrdcalc_isrunnable(RRDCALC *rc, time_t now, time_t *next_run)
514 return 0;
515 }
516
517 - if(unlikely(!rrdset_flag_check(rc->rrdset, RRDSET_FLAG_ENABLED))) {
518 - debug(D_HEALTH, "Health not running alarm '%s.%s'. The chart is not enabled", rc->chart?rc->chart:"NOCHART", rc->name);
519 - return 0;
520 - }
521 -
517 if(unlikely(rrdset_flag_check(rc->rrdset, RRDSET_FLAG_ARCHIVED))) {
518 debug(D_HEALTH, "Health not running alarm '%s.%s'. The chart has been marked as archived", rc->chart?rc->chart:"NOCHART", rc->name);
519 return 0;
streaming/rrdpush.c
+1 -5
@@ -136,11 +136,7 @@ static inline int should_send_chart_matching(RRDSET *st) {
136 if (rrdset_flag_check(st, RRDSET_FLAG_ANOMALY_DETECTION))
137 return ml_streaming_enabled();
138
139 - if(unlikely(!rrdset_flag_check(st, RRDSET_FLAG_ENABLED))) {
140 - rrdset_flag_clear(st, RRDSET_FLAG_UPSTREAM_SEND);
141 - rrdset_flag_set(st, RRDSET_FLAG_UPSTREAM_IGNORE);
142 - }
143 - else if(!rrdset_flag_check(st, RRDSET_FLAG_UPSTREAM_SEND|RRDSET_FLAG_UPSTREAM_IGNORE)) {
139 + if(!rrdset_flag_check(st, RRDSET_FLAG_UPSTREAM_SEND|RRDSET_FLAG_UPSTREAM_IGNORE)) {
140 RRDHOST *host = st->rrdhost;
141
142 if(simple_pattern_matches(host->rrdpush_send_charts_matching, st->id) ||
web/api/formatters/rrdset2json.c
-2
@@ -52,7 +52,6 @@ void rrdset2json(RRDSET *st, BUFFER *wb, size_t *dimensions_count, size_t *memor
52 "\t\t\t\"priority\": %ld,\n"
53 "\t\t\t\"plugin\": \"%s\",\n"
54 "\t\t\t\"module\": \"%s\",\n"
55 - "\t\t\t\"enabled\": %s,\n"
55 "\t\t\t\"units\": \"%s\",\n"
56 "\t\t\t\"data_url\": \"/api/v1/data?chart=%s\",\n"
57 "\t\t\t\"chart_type\": \"%s\",\n",
@@ -66,7 +65,6 @@ void rrdset2json(RRDSET *st, BUFFER *wb, size_t *dimensions_count, size_t *memor
65 st->priority,
66 st->plugin_name ? st->plugin_name : "",
67 st->module_name ? st->module_name : "",
69 - rrdset_flag_check(st, RRDSET_FLAG_ENABLED) ? "true" : "false",
68 st->units,
69 st->name,
70 rrdset_type_name(st->chart_type));