make 'send charts matching' behave the same as 'filter' (#12832)
Ilya Mashchenko committed
May 6, 2022 at 17:31 UTC
11bd54a49552f6d4d4ae5313cefe4f8e4f5804c0
1 file changed
+21
-21
exporting/prometheus/prometheus.c
+21
-21
@@ -7,6 +7,13 @@
7
// PROMETHEUS
8
// /api/v1/allmetrics?format=prometheus and /api/v1/allmetrics?format=prometheus_all_hosts
9
10
+static int is_matches_rrdset(struct instance *instance, RRDSET *st, SIMPLE_PATTERN *filter) {
11
+ if (instance->config.options & EXPORTING_OPTION_SEND_NAMES) {
12
+ return simple_pattern_matches(filter, st->name);
13
+ }
14
+ return simple_pattern_matches(filter, st->id);
15
+}
16
+
17
/**
18
* Check if a chart can be sent to Prometheus
19
*
@@ -29,28 +36,21 @@ inline int can_send_rrdset(struct instance *instance, RRDSET *st, SIMPLE_PATTERN
36
return 0;
37
38
if (filter) {
32
- if (instance->config.options & EXPORTING_OPTION_SEND_NAMES) {
33
- if (!simple_pattern_matches(filter, st->name))
34
- return 0;
35
- } else {
36
- if (!simple_pattern_matches(filter, st->id))
37
- return 0;
39
+ if (!is_matches_rrdset(instance, st, filter)) {
40
+ return 0;
41
}
39
- } else {
40
- if (unlikely(!rrdset_flag_check(st, RRDSET_FLAG_EXPORTING_SEND))) {
41
- // we have not checked this chart
42
- if (simple_pattern_matches(instance->config.charts_pattern, st->id) ||
43
- simple_pattern_matches(instance->config.charts_pattern, st->name))
44
- rrdset_flag_set(st, RRDSET_FLAG_EXPORTING_SEND);
45
- else {
46
- rrdset_flag_set(st, RRDSET_FLAG_EXPORTING_IGNORE);
47
- debug(
48
- D_EXPORTING,
49
- "EXPORTING: not sending chart '%s' of host '%s', because it is disabled for exporting.",
50
- st->id,
51
- host->hostname);
52
- return 0;
53
- }
42
+ } else if (unlikely(!rrdset_flag_check(st, RRDSET_FLAG_EXPORTING_SEND))) {
43
+ // we have not checked this chart
44
+ if (is_matches_rrdset(instance, st, instance->config.charts_pattern)) {
45
+ rrdset_flag_set(st, RRDSET_FLAG_EXPORTING_SEND);
46
+ } else {
47
+ rrdset_flag_set(st, RRDSET_FLAG_EXPORTING_IGNORE);
48
+ debug(
49
+ D_EXPORTING,
50
+ "EXPORTING: not sending chart '%s' of host '%s', because it is disabled for exporting.",
51
+ st->id,
52
+ host->hostname);
53
+ return 0;
54
}
55
}
56