summaryrefslogtreecommitdiffstats
path: root/exporting
diff options
context:
space:
mode:
authorVladimir Kobal <vlad@prokk.net>2021-04-21 10:50:06 +0300
committerGitHub <noreply@github.com>2021-04-21 10:50:06 +0300
commit157fb5860a61c4472c2bc3ba11f2dd8712d9c845 (patch)
treeb3ad0d016f1765dc9b00fffb055d06aebb6c0c4a /exporting
parent9d481060489110db52dcd0f8d7e22196c70742c0 (diff)
Backend chart filtering backward compatibility fix (#11002)
Diffstat (limited to 'exporting')
-rw-r--r--exporting/check_filters.c8
-rw-r--r--exporting/exporting_engine.h2
-rw-r--r--exporting/prometheus/prometheus.c12
-rw-r--r--exporting/read_config.c8
-rw-r--r--exporting/tests/exporting_fixtures.c2
-rw-r--r--exporting/tests/test_exporting_engine.c9
6 files changed, 25 insertions, 16 deletions
diff --git a/exporting/check_filters.c b/exporting/check_filters.c
index 8d70c6f68d..64ced7238c 100644
--- a/exporting/check_filters.c
+++ b/exporting/check_filters.c
@@ -50,15 +50,15 @@ int rrdset_is_exportable(struct instance *instance, RRDSET *st)
RRDSET_FLAGS *flags = &st->exporting_flags[instance->index];
- if(unlikely(*flags & RRDSET_FLAG_BACKEND_IGNORE))
+ if(unlikely(*flags & RRDSET_FLAG_EXPORTING_IGNORE))
return 0;
- if(unlikely(!(*flags & RRDSET_FLAG_BACKEND_SEND))) {
+ if(unlikely(!(*flags & RRDSET_FLAG_EXPORTING_SEND))) {
// we have not checked this chart
if(simple_pattern_matches(instance->config.charts_pattern, st->id) || simple_pattern_matches(instance->config.charts_pattern, st->name))
- *flags |= RRDSET_FLAG_BACKEND_SEND;
+ *flags |= RRDSET_FLAG_EXPORTING_SEND;
else {
- *flags |= RRDSET_FLAG_BACKEND_IGNORE;
+ *flags |= RRDSET_FLAG_EXPORTING_IGNORE;
debug(D_BACKEND, "BACKEND: not sending chart '%s' of host '%s', because it is disabled for backends.", st->id, host->hostname);
return 0;
}
diff --git a/exporting/exporting_engine.h b/exporting/exporting_engine.h
index 1d9feb7dd4..1edd283f78 100644
--- a/exporting/exporting_engine.h
+++ b/exporting/exporting_engine.h
@@ -77,6 +77,8 @@ struct instance_config {
SIMPLE_PATTERN *charts_pattern;
SIMPLE_PATTERN *hosts_pattern;
+ int initialized;
+
void *connector_specific_config;
};
diff --git a/exporting/prometheus/prometheus.c b/exporting/prometheus/prometheus.c
index c10d94b90a..4222dce568 100644
--- a/exporting/prometheus/prometheus.c
+++ b/exporting/prometheus/prometheus.c
@@ -18,16 +18,16 @@ inline int can_send_rrdset(struct instance *instance, RRDSET *st)
{
RRDHOST *host = st->rrdhost;
- if (unlikely(rrdset_flag_check(st, RRDSET_FLAG_BACKEND_IGNORE)))
+ if (unlikely(rrdset_flag_check(st, RRDSET_FLAG_EXPORTING_IGNORE)))
return 0;
- if (unlikely(!rrdset_flag_check(st, RRDSET_FLAG_BACKEND_SEND))) {
+ if (unlikely(!rrdset_flag_check(st, RRDSET_FLAG_EXPORTING_SEND))) {
// we have not checked this chart
if (simple_pattern_matches(instance->config.charts_pattern, st->id) ||
simple_pattern_matches(instance->config.charts_pattern, st->name))
- rrdset_flag_set(st, RRDSET_FLAG_BACKEND_SEND);
+ rrdset_flag_set(st, RRDSET_FLAG_EXPORTING_SEND);
else {
- rrdset_flag_set(st, RRDSET_FLAG_BACKEND_IGNORE);
+ rrdset_flag_set(st, RRDSET_FLAG_EXPORTING_IGNORE);
debug(
D_BACKEND,
"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(
EXPORTING_OPTIONS exporting_options,
PROMETHEUS_OUTPUT_OPTIONS output_options)
{
- if (unlikely(!prometheus_exporter_instance))
+ if (unlikely(!prometheus_exporter_instance || !prometheus_exporter_instance->config.initialized))
return;
prometheus_exporter_instance->before = now_realtime_sec();
@@ -892,7 +892,7 @@ void rrd_stats_api_v1_charts_allmetrics_prometheus_all_hosts(
EXPORTING_OPTIONS exporting_options,
PROMETHEUS_OUTPUT_OPTIONS output_options)
{
- if (unlikely(!prometheus_exporter_instance))
+ if (unlikely(!prometheus_exporter_instance || !prometheus_exporter_instance->config.initialized))
return;
prometheus_exporter_instance->before = now_realtime_sec();
diff --git a/exporting/read_config.c b/exporting/read_config.c
index 995ba578f8..ea50fa0f6f 100644
--- a/exporting/read_config.c
+++ b/exporting/read_config.c
@@ -267,12 +267,16 @@ struct engine *read_exporting_config()
else
prometheus_exporter_instance->config.options &= ~EXPORTING_OPTION_SEND_AUTOMATIC_LABELS;
- prometheus_exporter_instance->config.charts_pattern =
- simple_pattern_create(prometheus_config_get("send charts matching", "*"), NULL, SIMPLE_PATTERN_EXACT);
+ prometheus_exporter_instance->config.charts_pattern = simple_pattern_create(
+ prometheus_config_get("send charts matching", global_backend_send_charts_matching),
+ NULL,
+ SIMPLE_PATTERN_EXACT);
prometheus_exporter_instance->config.hosts_pattern = simple_pattern_create(
prometheus_config_get("send hosts matching", "localhost *"), NULL, SIMPLE_PATTERN_EXACT);
prometheus_exporter_instance->config.prefix = prometheus_config_get("prefix", global_backend_prefix);
+
+ prometheus_exporter_instance->config.initialized = 1;
}
// TODO: change BACKEND to EXPORTING
diff --git a/exporting/tests/exporting_fixtures.c b/exporting/tests/exporting_fixtures.c
index 00bb0ed0f2..b5b0ce8165 100644
--- a/exporting/tests/exporting_fixtures.c
+++ b/exporting/tests/exporting_fixtures.c
@@ -146,6 +146,8 @@ int setup_prometheus(void **state)
prometheus_exporter_instance->config.charts_pattern = simple_pattern_create("*", NULL, SIMPLE_PATTERN_EXACT);
prometheus_exporter_instance->config.hosts_pattern = simple_pattern_create("*", NULL, SIMPLE_PATTERN_EXACT);
+ prometheus_exporter_instance->config.initialized = 1;
+
return 0;
}
diff --git a/exporting/tests/test_exporting_engine.c b/exporting/tests/test_exporting_engine.c
index 774d1a2659..beb5691d8f 100644
--- a/exporting/tests/test_exporting_engine.c
+++ b/exporting/tests/test_exporting_engine.c
@@ -17,6 +17,7 @@ char log_line[MAX_LOG_LINE + 1];
BACKEND_OPTIONS global_backend_options = 0;
const char *global_backend_source = "average";
const char *global_backend_prefix = "netdata";
+const char *global_backend_send_charts_matching = "*";
void init_connectors_in_tests(struct engine *engine)
{
@@ -268,7 +269,7 @@ static void test_rrdset_is_exportable(void **state)
assert_int_equal(__real_rrdset_is_exportable(instance, st), 1);
assert_ptr_not_equal(st->exporting_flags, NULL);
- assert_int_equal(st->exporting_flags[0], RRDSET_FLAG_BACKEND_SEND);
+ assert_int_equal(st->exporting_flags[0], RRDSET_FLAG_EXPORTING_SEND);
}
static void test_false_rrdset_is_exportable(void **state)
@@ -285,7 +286,7 @@ static void test_false_rrdset_is_exportable(void **state)
assert_int_equal(__real_rrdset_is_exportable(instance, st), 0);
assert_ptr_not_equal(st->exporting_flags, NULL);
- assert_int_equal(st->exporting_flags[0], RRDSET_FLAG_BACKEND_IGNORE);
+ assert_int_equal(st->exporting_flags[0], RRDSET_FLAG_EXPORTING_IGNORE);
}
static void test_exporting_calculate_value_from_stored_data(void **state)
@@ -993,9 +994,9 @@ static void test_can_send_rrdset(void **state)
assert_int_equal(can_send_rrdset(prometheus_exporter_instance, localhost->rrdset_root), 1);
- rrdset_flag_set(localhost->rrdset_root, RRDSET_FLAG_BACKEND_IGNORE);
+ rrdset_flag_set(localhost->rrdset_root, RRDSET_FLAG_EXPORTING_IGNORE);
assert_int_equal(can_send_rrdset(prometheus_exporter_instance, localhost->rrdset_root), 0);
- rrdset_flag_clear(localhost->rrdset_root, RRDSET_FLAG_BACKEND_IGNORE);
+ rrdset_flag_clear(localhost->rrdset_root, RRDSET_FLAG_EXPORTING_IGNORE);
// TODO: test with a denying simple pattern