@cryptotaxi247 / netdata-1 / commits / 157fb5860

Backend chart filtering backward compatibility fix (#11002)

Vladimir Kobal committed Apr 21, 2021 at 10:50 UTC 157fb5860a61c4472c2bc3ba11f2dd8712d9c845
10 files changed +40 -20
backends/backends.c
+5 -1
@@ -26,6 +26,7 @@
26 //
27
28 const char *global_backend_prefix = "netdata";
29 +const char *global_backend_send_charts_matching = "*";
30 int global_backend_update_every = 10;
31 BACKEND_OPTIONS global_backend_options = BACKEND_SOURCE_DATA_AVERAGE | BACKEND_OPTION_SEND_NAMES;
32 const char *global_backend_source = NULL;
@@ -517,7 +518,10 @@ void *backends_main(void *ptr) {
518 else
519 global_backend_options &= ~BACKEND_OPTION_SEND_NAMES;
520
520 - charts_pattern = simple_pattern_create(config_get(CONFIG_SECTION_BACKEND, "send charts matching", "*"), NULL, SIMPLE_PATTERN_EXACT);
521 + charts_pattern = simple_pattern_create(
522 + global_backend_send_charts_matching = config_get(CONFIG_SECTION_BACKEND, "send charts matching", "*"),
523 + NULL,
524 + SIMPLE_PATTERN_EXACT);
525 hosts_pattern = simple_pattern_create(config_get(CONFIG_SECTION_BACKEND, "send hosts matching", "localhost *"), NULL, SIMPLE_PATTERN_EXACT);
526
527 #if ENABLE_PROMETHEUS_REMOTE_WRITE
backends/backends.h
+1
@@ -37,6 +37,7 @@ extern int global_backend_update_every;
37 extern BACKEND_OPTIONS global_backend_options;
38 extern const char *global_backend_source;
39 extern const char *global_backend_prefix;
40 +extern const char *global_backend_send_charts_matching;
41
42 extern void *backends_main(void *ptr);
43 BACKEND_TYPE backend_select_type(const char *type);
database/rrd.h
+5 -3
@@ -454,8 +454,8 @@ typedef enum rrdset_flags {
454 // (the master data set should be the one that has the same family and is not detail)
455 RRDSET_FLAG_DEBUG = 1 << 2, // enables or disables debugging for a chart
456 RRDSET_FLAG_OBSOLETE = 1 << 3, // this is marked by the collector/module as obsolete
457 - RRDSET_FLAG_BACKEND_SEND = 1 << 4, // if set, this chart should be sent to backends
458 - RRDSET_FLAG_BACKEND_IGNORE = 1 << 5, // if set, this chart should not be sent to backends
457 + RRDSET_FLAG_EXPORTING_SEND = 1 << 4, // if set, this chart should be sent to Prometheus web API
458 + RRDSET_FLAG_EXPORTING_IGNORE = 1 << 5, // if set, this chart should not be sent to Prometheus web API
459 RRDSET_FLAG_UPSTREAM_SEND = 1 << 6, // if set, this chart should be sent upstream (streaming)
460 RRDSET_FLAG_UPSTREAM_IGNORE = 1 << 7, // if set, this chart should not be sent upstream (streaming)
461 RRDSET_FLAG_UPSTREAM_EXPOSED = 1 << 8, // if set, we have sent this chart definition to netdata parent (streaming)
@@ -468,7 +468,9 @@ typedef enum rrdset_flags {
468 // No new values have been collected for this chart since agent start or it was marked RRDSET_FLAG_OBSOLETE at
469 // least rrdset_free_obsolete_time seconds ago.
470 RRDSET_FLAG_ARCHIVED = 1 << 15,
471 - RRDSET_FLAG_ACLK = 1 << 16
471 + RRDSET_FLAG_ACLK = 1 << 16,
472 + RRDSET_FLAG_BACKEND_SEND = 1 << 17, // if set, this chart should be sent to backends
473 + RRDSET_FLAG_BACKEND_IGNORE = 1 << 18 // if set, this chart should not be sent to backends
474 } RRDSET_FLAGS;
475
476 #ifdef HAVE_C___ATOMIC
database/rrdset.c
+4
@@ -175,6 +175,8 @@ int rrdset_set_name(RRDSET *st, const char *name) {
175 if(unlikely(rrdset_index_add_name(host, st) != st))
176 error("RRDSET: INTERNAL ERROR: attempted to index duplicate chart name '%s'", st->name);
177
178 + rrdset_flag_clear(st, RRDSET_FLAG_EXPORTING_SEND);
179 + rrdset_flag_clear(st, RRDSET_FLAG_EXPORTING_IGNORE);
180 rrdset_flag_clear(st, RRDSET_FLAG_BACKEND_SEND);
181 rrdset_flag_clear(st, RRDSET_FLAG_BACKEND_IGNORE);
182 rrdset_flag_clear(st, RRDSET_FLAG_UPSTREAM_SEND);
@@ -858,6 +860,8 @@ RRDSET *rrdset_create_custom(
860 rrdset_flag_clear(st, RRDSET_FLAG_DETAIL);
861 rrdset_flag_clear(st, RRDSET_FLAG_DEBUG);
862 rrdset_flag_clear(st, RRDSET_FLAG_OBSOLETE);
863 + rrdset_flag_clear(st, RRDSET_FLAG_EXPORTING_SEND);
864 + rrdset_flag_clear(st, RRDSET_FLAG_EXPORTING_IGNORE);
865 rrdset_flag_clear(st, RRDSET_FLAG_BACKEND_SEND);
866 rrdset_flag_clear(st, RRDSET_FLAG_BACKEND_IGNORE);
867 rrdset_flag_clear(st, RRDSET_FLAG_UPSTREAM_SEND);
exporting/check_filters.c
+4 -4
@@ -50,15 +50,15 @@ int rrdset_is_exportable(struct instance *instance, RRDSET *st)
50
51 RRDSET_FLAGS *flags = &st->exporting_flags[instance->index];
52
53 - if(unlikely(*flags & RRDSET_FLAG_BACKEND_IGNORE))
53 + if(unlikely(*flags & RRDSET_FLAG_EXPORTING_IGNORE))
54 return 0;
55
56 - if(unlikely(!(*flags & RRDSET_FLAG_BACKEND_SEND))) {
56 + if(unlikely(!(*flags & RRDSET_FLAG_EXPORTING_SEND))) {
57 // we have not checked this chart
58 if(simple_pattern_matches(instance->config.charts_pattern, st->id) || simple_pattern_matches(instance->config.charts_pattern, st->name))
59 - *flags |= RRDSET_FLAG_BACKEND_SEND;
59 + *flags |= RRDSET_FLAG_EXPORTING_SEND;
60 else {
61 - *flags |= RRDSET_FLAG_BACKEND_IGNORE;
61 + *flags |= RRDSET_FLAG_EXPORTING_IGNORE;
62 debug(D_BACKEND, "BACKEND: not sending chart '%s' of host '%s', because it is disabled for backends.", st->id, host->hostname);
63 return 0;
64 }
exporting/exporting_engine.h
+2
@@ -77,6 +77,8 @@ struct instance_config {
77 SIMPLE_PATTERN *charts_pattern;
78 SIMPLE_PATTERN *hosts_pattern;
79
80 + int initialized;
81 +
82 void *connector_specific_config;
83 };
84
exporting/prometheus/prometheus.c
+6 -6
@@ -18,16 +18,16 @@ inline int can_send_rrdset(struct instance *instance, RRDSET *st)
18 {
19 RRDHOST *host = st->rrdhost;
20
21 - if (unlikely(rrdset_flag_check(st, RRDSET_FLAG_BACKEND_IGNORE)))
21 + if (unlikely(rrdset_flag_check(st, RRDSET_FLAG_EXPORTING_IGNORE)))
22 return 0;
23
24 - if (unlikely(!rrdset_flag_check(st, RRDSET_FLAG_BACKEND_SEND))) {
24 + if (unlikely(!rrdset_flag_check(st, RRDSET_FLAG_EXPORTING_SEND))) {
25 // we have not checked this chart
26 if (simple_pattern_matches(instance->config.charts_pattern, st->id) ||
27 simple_pattern_matches(instance->config.charts_pattern, st->name))
28 - rrdset_flag_set(st, RRDSET_FLAG_BACKEND_SEND);
28 + rrdset_flag_set(st, RRDSET_FLAG_EXPORTING_SEND);
29 else {
30 - rrdset_flag_set(st, RRDSET_FLAG_BACKEND_IGNORE);
30 + rrdset_flag_set(st, RRDSET_FLAG_EXPORTING_IGNORE);
31 debug(
32 D_BACKEND,
33 "EXPORTING: not sending chart '%s' of host '%s', because it is disabled for exporting.",
@@ -855,7 +855,7 @@ void rrd_stats_api_v1_charts_allmetrics_prometheus_single_host(
855 EXPORTING_OPTIONS exporting_options,
856 PROMETHEUS_OUTPUT_OPTIONS output_options)
857 {
858 - if (unlikely(!prometheus_exporter_instance))
858 + if (unlikely(!prometheus_exporter_instance || !prometheus_exporter_instance->config.initialized))
859 return;
860
861 prometheus_exporter_instance->before = now_realtime_sec();
@@ -892,7 +892,7 @@ void rrd_stats_api_v1_charts_allmetrics_prometheus_all_hosts(
892 EXPORTING_OPTIONS exporting_options,
893 PROMETHEUS_OUTPUT_OPTIONS output_options)
894 {
895 - if (unlikely(!prometheus_exporter_instance))
895 + if (unlikely(!prometheus_exporter_instance || !prometheus_exporter_instance->config.initialized))
896 return;
897
898 prometheus_exporter_instance->before = now_realtime_sec();
exporting/read_config.c
+6 -2
@@ -267,12 +267,16 @@ struct engine *read_exporting_config()
267 else
268 prometheus_exporter_instance->config.options &= ~EXPORTING_OPTION_SEND_AUTOMATIC_LABELS;
269
270 - prometheus_exporter_instance->config.charts_pattern =
271 - simple_pattern_create(prometheus_config_get("send charts matching", "*"), NULL, SIMPLE_PATTERN_EXACT);
270 + prometheus_exporter_instance->config.charts_pattern = simple_pattern_create(
271 + prometheus_config_get("send charts matching", global_backend_send_charts_matching),
272 + NULL,
273 + SIMPLE_PATTERN_EXACT);
274 prometheus_exporter_instance->config.hosts_pattern = simple_pattern_create(
275 prometheus_config_get("send hosts matching", "localhost *"), NULL, SIMPLE_PATTERN_EXACT);
276
277 prometheus_exporter_instance->config.prefix = prometheus_config_get("prefix", global_backend_prefix);
278 +
279 + prometheus_exporter_instance->config.initialized = 1;
280 }
281
282 // TODO: change BACKEND to EXPORTING
exporting/tests/exporting_fixtures.c
+2
@@ -146,6 +146,8 @@ int setup_prometheus(void **state)
146 prometheus_exporter_instance->config.charts_pattern = simple_pattern_create("*", NULL, SIMPLE_PATTERN_EXACT);
147 prometheus_exporter_instance->config.hosts_pattern = simple_pattern_create("*", NULL, SIMPLE_PATTERN_EXACT);
148
149 + prometheus_exporter_instance->config.initialized = 1;
150 +
151 return 0;
152 }
153
exporting/tests/test_exporting_engine.c
+5 -4
@@ -17,6 +17,7 @@ char log_line[MAX_LOG_LINE + 1];
17 BACKEND_OPTIONS global_backend_options = 0;
18 const char *global_backend_source = "average";
19 const char *global_backend_prefix = "netdata";
20 +const char *global_backend_send_charts_matching = "*";
21
22 void init_connectors_in_tests(struct engine *engine)
23 {
@@ -268,7 +269,7 @@ static void test_rrdset_is_exportable(void **state)
269 assert_int_equal(__real_rrdset_is_exportable(instance, st), 1);
270
271 assert_ptr_not_equal(st->exporting_flags, NULL);
271 - assert_int_equal(st->exporting_flags[0], RRDSET_FLAG_BACKEND_SEND);
272 + assert_int_equal(st->exporting_flags[0], RRDSET_FLAG_EXPORTING_SEND);
273 }
274
275 static void test_false_rrdset_is_exportable(void **state)
@@ -285,7 +286,7 @@ static void test_false_rrdset_is_exportable(void **state)
286 assert_int_equal(__real_rrdset_is_exportable(instance, st), 0);
287
288 assert_ptr_not_equal(st->exporting_flags, NULL);
288 - assert_int_equal(st->exporting_flags[0], RRDSET_FLAG_BACKEND_IGNORE);
289 + assert_int_equal(st->exporting_flags[0], RRDSET_FLAG_EXPORTING_IGNORE);
290 }
291
292 static void test_exporting_calculate_value_from_stored_data(void **state)
@@ -993,9 +994,9 @@ static void test_can_send_rrdset(void **state)
994
995 assert_int_equal(can_send_rrdset(prometheus_exporter_instance, localhost->rrdset_root), 1);
996
996 - rrdset_flag_set(localhost->rrdset_root, RRDSET_FLAG_BACKEND_IGNORE);
997 + rrdset_flag_set(localhost->rrdset_root, RRDSET_FLAG_EXPORTING_IGNORE);
998 assert_int_equal(can_send_rrdset(prometheus_exporter_instance, localhost->rrdset_root), 0);
998 - rrdset_flag_clear(localhost->rrdset_root, RRDSET_FLAG_BACKEND_IGNORE);
999 + rrdset_flag_clear(localhost->rrdset_root, RRDSET_FLAG_EXPORTING_IGNORE);
1000
1001 // TODO: test with a denying simple pattern
1002