@cryptotaxi247 / netdata-1 / commits / 6d91cedec

Fix exporting config (#10323)

Vladimir Kobal committed Dec 7, 2020 at 16:45 UTC 6d91cedecd5ee3f58e5fe8af48ea5eac33abb967
5 files changed +37 -7
exporting/read_config.c
+4 -1
@@ -238,7 +238,8 @@ struct engine *read_exporting_config()
238 prometheus_exporter_instance->config.update_every =
239 prometheus_config_get_number(EXPORTING_UPDATE_EVERY_OPTION_NAME, EXPORTING_UPDATE_EVERY_DEFAULT);
240
241 - if (prometheus_config_get_boolean("send names instead of ids", CONFIG_BOOLEAN_YES))
241 + if (prometheus_config_get_boolean(
242 + "send names instead of ids", global_backend_options & EXPORTING_OPTION_SEND_NAMES))
243 prometheus_exporter_instance->config.options |= EXPORTING_OPTION_SEND_NAMES;
244 else
245 prometheus_exporter_instance->config.options &= ~EXPORTING_OPTION_SEND_NAMES;
@@ -257,6 +258,8 @@ struct engine *read_exporting_config()
258 simple_pattern_create(prometheus_config_get("send charts matching", "*"), NULL, SIMPLE_PATTERN_EXACT);
259 prometheus_exporter_instance->config.hosts_pattern = simple_pattern_create(
260 prometheus_config_get("send hosts matching", "localhost *"), NULL, SIMPLE_PATTERN_EXACT);
261 +
262 + prometheus_exporter_instance->config.prefix = prometheus_config_get("prefix", global_backend_prefix);
263 }
264
265 // TODO: change BACKEND to EXPORTING
exporting/tests/test_exporting_engine.c
+3
@@ -14,6 +14,9 @@ char *netdata_configured_hostname = "test_host";
14
15 char log_line[MAX_LOG_LINE + 1];
16
17 +BACKEND_OPTIONS global_backend_options = 0;
18 +const char *global_backend_prefix = "netdata";
19 +
20 void init_connectors_in_tests(struct engine *engine)
21 {
22 expect_function_call(__wrap_now_realtime_sec);
web/api/exporters/allmetrics.c
+17 -6
@@ -20,11 +20,22 @@ struct prometheus_output_options {
20 inline int web_client_api_request_v1_allmetrics(RRDHOST *host, struct web_client *w, char *url) {
21 int format = ALLMETRICS_SHELL;
22 const char *prometheus_server = w->client_ip;
23 - uint32_t prometheus_backend_options = global_backend_options;
23 +
24 + uint32_t prometheus_exporting_options;
25 + if (prometheus_exporter_instance)
26 + prometheus_exporting_options = prometheus_exporter_instance->config.options;
27 + else
28 + prometheus_exporting_options = global_backend_options;
29 +
30 PROMETHEUS_OUTPUT_OPTIONS prometheus_output_options =
31 PROMETHEUS_OUTPUT_TIMESTAMPS |
26 - ((global_backend_options & BACKEND_OPTION_SEND_NAMES) ? PROMETHEUS_OUTPUT_NAMES : 0);
27 - const char *prometheus_prefix = global_backend_prefix;
32 + ((prometheus_exporting_options & BACKEND_OPTION_SEND_NAMES) ? PROMETHEUS_OUTPUT_NAMES : 0);
33 +
34 + const char *prometheus_prefix;
35 + if (prometheus_exporter_instance)
36 + prometheus_prefix = prometheus_exporter_instance->config.prefix;
37 + else
38 + prometheus_prefix = global_backend_prefix;
39
40 while(url) {
41 char *value = mystrsep(&url, "&");
@@ -53,7 +64,7 @@ inline int web_client_api_request_v1_allmetrics(RRDHOST *host, struct web_client
64 prometheus_prefix = value;
65 }
66 else if(!strcmp(name, "data") || !strcmp(name, "source") || !strcmp(name, "data source") || !strcmp(name, "data-source") || !strcmp(name, "data_source") || !strcmp(name, "datasource")) {
56 - prometheus_backend_options = backend_parse_data_source(value, prometheus_backend_options);
67 + prometheus_exporting_options = backend_parse_data_source(value, prometheus_exporting_options);
68 }
69 else {
70 int i;
@@ -91,7 +102,7 @@ inline int web_client_api_request_v1_allmetrics(RRDHOST *host, struct web_client
102 , w->response.data
103 , prometheus_server
104 , prometheus_prefix
94 - , prometheus_backend_options
105 + , prometheus_exporting_options
106 , prometheus_output_options
107 );
108 return HTTP_RESP_OK;
@@ -103,7 +114,7 @@ inline int web_client_api_request_v1_allmetrics(RRDHOST *host, struct web_client
114 , w->response.data
115 , prometheus_server
116 , prometheus_prefix
106 - , prometheus_backend_options
117 + , prometheus_exporting_options
118 , prometheus_output_options
119 );
120 return HTTP_RESP_OK;
web/api/tests/valid_urls.c
+7
@@ -7,6 +7,13 @@
7 #include <setjmp.h>
8 #include <cmocka.h>
9 #include <stdbool.h>
10 +
11 +RRDHOST *sql_create_host_by_uuid(char *hostname)
12 +{
13 + (void) hostname;
14 + return NULL;
15 +}
16 +
17 RRDHOST *__wrap_sql_create_host_by_uuid(char *hostname)
18 {
19 (void) hostname;
web/api/tests/web_api.c
+6
@@ -8,6 +8,12 @@
8 #include <cmocka.h>
9 #include <stdbool.h>
10
11 +RRDHOST *sql_create_host_by_uuid(char *hostname)
12 +{
13 + (void) hostname;
14 + return NULL;
15 +}
16 +
17 RRDHOST *__wrap_sql_create_host_by_uuid(char *hostname)
18 {
19 (void) hostname;