summaryrefslogtreecommitdiffstats
path: root/exporting/read_config.c
diff options
context:
space:
mode:
authorAustin S. Hemmelgarn <austin@netdata.cloud>2020-04-13 08:39:52 -0400
committerAustin S. Hemmelgarn <austin@netdata.cloud>2020-04-13 08:42:22 -0400
commite2874320fc027f7ab51ab3e115d5b1889b8fd747 (patch)
treecd755ef9b8522634c61aed9888239c9b67394157 /exporting/read_config.c
parent353780082c0ac8525e5b52aa8a29bbf5b70871e8 (diff)
Revert changes since v1.21 in pereparation for hotfix release.
Diffstat (limited to 'exporting/read_config.c')
-rw-r--r--exporting/read_config.c183
1 files changed, 84 insertions, 99 deletions
diff --git a/exporting/read_config.c b/exporting/read_config.c
index 122ceef79d..a9590659e0 100644
--- a/exporting/read_config.c
+++ b/exporting/read_config.c
@@ -2,19 +2,18 @@
#include "exporting_engine.h"
-struct config exporting_config = { .first_section = NULL,
- .last_section = NULL,
- .mutex = NETDATA_MUTEX_INITIALIZER,
- .index = { .avl_tree = { .root = NULL, .compar = appconfig_section_compare },
- .rwlock = AVL_LOCK_INITIALIZER } };
+struct config exporting_config = {.first_section = NULL,
+ .last_section = NULL,
+ .mutex = NETDATA_MUTEX_INITIALIZER,
+ .index = {.avl_tree = {.root = NULL, .compar = appconfig_section_compare},
+ .rwlock = AVL_LOCK_INITIALIZER}};
-struct instance *prometheus_exporter_instance = NULL;
static _CONNECTOR_INSTANCE *find_instance(const char *section)
{
_CONNECTOR_INSTANCE *local_ci;
- local_ci = add_connector_instance(NULL, NULL); // Get root section
+ local_ci = add_connector_instance(NULL, NULL); // Get root section
if (unlikely(!local_ci))
return local_ci;
@@ -39,10 +38,12 @@ char *expconfig_get(struct config *root, const char *section, const char *name,
local_ci = find_instance(section);
if (!local_ci)
- return NULL; // TODO: Check if it is meaningful to return default_value
+ return NULL; // TODO: Check if it is meaningful to return default_value
return appconfig_get(
- root, local_ci->instance_name, name,
+ root,
+ local_ci->instance_name,
+ name,
appconfig_get(
root, local_ci->connector_name, name, appconfig_get(root, CONFIG_SECTION_EXPORTING, name, default_value)));
}
@@ -57,12 +58,16 @@ int expconfig_get_boolean(struct config *root, const char *section, const char *
local_ci = find_instance(section);
if (!local_ci)
- return 0; // TODO: Check if it is meaningful to return default_value
+ return 0; // TODO: Check if it is meaningful to return default_value
return appconfig_get_boolean(
- root, local_ci->instance_name, name,
+ root,
+ local_ci->instance_name,
+ name,
appconfig_get_boolean(
- root, local_ci->connector_name, name,
+ root,
+ local_ci->connector_name,
+ name,
appconfig_get_boolean(root, CONFIG_SECTION_EXPORTING, name, default_value)));
}
@@ -76,12 +81,16 @@ long long expconfig_get_number(struct config *root, const char *section, const c
local_ci = find_instance(section);
if (!local_ci)
- return 0; // TODO: Check if it is meaningful to return default_value
+ return 0; // TODO: Check if it is meaningful to return default_value
return appconfig_get_number(
- root, local_ci->instance_name, name,
+ root,
+ local_ci->instance_name,
+ name,
appconfig_get_number(
- root, local_ci->connector_name, name,
+ root,
+ local_ci->connector_name,
+ name,
appconfig_get_number(root, CONFIG_SECTION_EXPORTING, name, default_value)));
}
@@ -99,7 +108,7 @@ int get_connector_instance(struct connector_instance *target_ci)
static _CONNECTOR_INSTANCE *local_ci = NULL;
_CONNECTOR_INSTANCE *global_connector_instance;
- global_connector_instance = find_instance(NULL); // Fetch head of instances
+ global_connector_instance = find_instance(NULL); // Fetch head of instances
if (unlikely(!global_connector_instance))
return 0;
@@ -131,39 +140,40 @@ int get_connector_instance(struct connector_instance *target_ci)
*
* @return It returns the connector id.
*/
-EXPORTING_CONNECTOR_TYPE exporting_select_type(const char *type)
+BACKEND_TYPE exporting_select_type(const char *type)
{
if (!strcmp(type, "graphite") || !strcmp(type, "graphite:plaintext")) {
- return EXPORTING_CONNECTOR_TYPE_GRAPHITE;
+ return BACKEND_TYPE_GRAPHITE;
} else if (!strcmp(type, "opentsdb") || !strcmp(type, "opentsdb:telnet")) {
- return EXPORTING_CONNECTOR_TYPE_OPENTSDB_USING_TELNET;
+ return BACKEND_TYPE_OPENTSDB_USING_TELNET;
} else if (!strcmp(type, "opentsdb:http") || !strcmp(type, "opentsdb:https")) {
- return EXPORTING_CONNECTOR_TYPE_OPENTSDB_USING_HTTP;
+ return BACKEND_TYPE_OPENTSDB_USING_HTTP;
} else if (!strcmp(type, "json") || !strcmp(type, "json:plaintext")) {
- return EXPORTING_CONNECTOR_TYPE_JSON;
+ return BACKEND_TYPE_JSON;
} else if (!strcmp(type, "prometheus_remote_write")) {
- return EXPORTING_CONNECTOR_TYPE_PROMETHEUS_REMOTE_WRITE;
+ return BACKEND_TYPE_PROMETHEUS_REMOTE_WRITE;
} else if (!strcmp(type, "kinesis") || !strcmp(type, "kinesis:plaintext")) {
- return EXPORTING_CONNECTOR_TYPE_KINESIS;
+ return BACKEND_TYPE_KINESIS;
} else if (!strcmp(type, "mongodb") || !strcmp(type, "mongodb:plaintext"))
- return EXPORTING_CONNECTOR_TYPE_MONGODB;
+ return BACKEND_TYPE_MONGODB;
- return EXPORTING_CONNECTOR_TYPE_UNKNOWN;
+ return BACKEND_TYPE_UNKNOWN;
}
-EXPORTING_OPTIONS exporting_parse_data_source(const char *data_source, EXPORTING_OPTIONS exporting_options)
-{
- if (!strcmp(data_source, "raw") || !strcmp(data_source, "as collected") || !strcmp(data_source, "as-collected") ||
- !strcmp(data_source, "as_collected") || !strcmp(data_source, "ascollected")) {
+EXPORTING_OPTIONS exporting_parse_data_source(const char *data_source, EXPORTING_OPTIONS exporting_options) {
+ if(!strcmp(data_source, "raw") || !strcmp(data_source, "as collected") || !strcmp(data_source, "as-collected") || !strcmp(data_source, "as_collected") || !strcmp(data_source, "ascollected")) {
exporting_options |= EXPORTING_SOURCE_DATA_AS_COLLECTED;
exporting_options &= ~(EXPORTING_OPTIONS_SOURCE_BITS ^ EXPORTING_SOURCE_DATA_AS_COLLECTED);
- } else if (!strcmp(data_source, "average")) {
+ }
+ else if(!strcmp(data_source, "average")) {
exporting_options |= EXPORTING_SOURCE_DATA_AVERAGE;
exporting_options &= ~(EXPORTING_OPTIONS_SOURCE_BITS ^ EXPORTING_SOURCE_DATA_AVERAGE);
- } else if (!strcmp(data_source, "sum") || !strcmp(data_source, "volume")) {
+ }
+ else if(!strcmp(data_source, "sum") || !strcmp(data_source, "volume")) {
exporting_options |= EXPORTING_SOURCE_DATA_SUM;
exporting_options &= ~(EXPORTING_OPTIONS_SOURCE_BITS ^ EXPORTING_SOURCE_DATA_SUM);
- } else {
+ }
+ else {
error("EXPORTING: invalid data data_source method '%s'.", data_source);
}
@@ -185,7 +195,7 @@ struct engine *read_exporting_config()
static struct engine *engine = NULL;
struct connector_instance_list {
struct connector_instance local_ci;
- EXPORTING_CONNECTOR_TYPE backend_type;
+ BACKEND_TYPE backend_type;
struct connector_instance_list *next;
};
@@ -210,46 +220,6 @@ struct engine *read_exporting_config()
freez(filename);
-#define prometheus_config_get(name, value) \
- appconfig_get( \
- &exporting_config, CONFIG_SECTION_PROMETHEUS, name, \
- appconfig_get(&exporting_config, CONFIG_SECTION_EXPORTING, name, value))
-#define prometheus_config_get_number(name, value) \
- appconfig_get_number( \
- &exporting_config, CONFIG_SECTION_PROMETHEUS, name, \
- appconfig_get_number(&exporting_config, CONFIG_SECTION_EXPORTING, name, value))
-#define prometheus_config_get_boolean(name, value) \
- appconfig_get_boolean( \
- &exporting_config, CONFIG_SECTION_PROMETHEUS, name, \
- appconfig_get_boolean(&exporting_config, CONFIG_SECTION_EXPORTING, name, value))
-
- if (!prometheus_exporter_instance) {
- prometheus_exporter_instance = callocz(1, sizeof(struct instance));
-
- prometheus_exporter_instance->config.update_every =
- prometheus_config_get_number(EXPORTING_UPDATE_EVERY_OPTION_NAME, EXPORTING_UPDATE_EVERY_DEFAULT);
-
- if (prometheus_config_get_boolean("send names instead of ids", CONFIG_BOOLEAN_YES))
- prometheus_exporter_instance->config.options |= EXPORTING_OPTION_SEND_NAMES;
- else
- prometheus_exporter_instance->config.options &= ~EXPORTING_OPTION_SEND_NAMES;
-
- if (prometheus_config_get_boolean("send configured labels", CONFIG_BOOLEAN_YES))
- prometheus_exporter_instance->config.options |= EXPORTING_OPTION_SEND_CONFIGURED_LABELS;
- else
- prometheus_exporter_instance->config.options &= ~EXPORTING_OPTION_SEND_CONFIGURED_LABELS;
-
- if (prometheus_config_get_boolean("send automatic labels", CONFIG_BOOLEAN_NO))
- prometheus_exporter_instance->config.options |= EXPORTING_OPTION_SEND_AUTOMATIC_LABELS;
- 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.hosts_pattern = simple_pattern_create(
- prometheus_config_get("send hosts matching", "localhost *"), NULL, SIMPLE_PATTERN_EXACT);
- }
-
// TODO: change BACKEND to EXPORTING
while (get_connector_instance(&local_ci)) {
info("Processing connector instance (%s)", local_ci.instance_name);
@@ -257,7 +227,8 @@ struct engine *read_exporting_config()
if (exporter_get_boolean(local_ci.instance_name, "enabled", 0)) {
info(
"Instance (%s) on connector (%s) is enabled and scheduled for activation",
- local_ci.instance_name, local_ci.connector_name);
+ local_ci.instance_name,
+ local_ci.connector_name);
tmp_ci_list = (struct connector_instance_list *)callocz(1, sizeof(struct connector_instance_list));
memcpy(&tmp_ci_list->local_ci, &local_ci, sizeof(local_ci));
@@ -281,8 +252,8 @@ struct engine *read_exporting_config()
engine->config.hostname =
strdupz(exporter_get(CONFIG_SECTION_EXPORTING, "hostname", netdata_configured_hostname));
engine->config.prefix = strdupz(exporter_get(CONFIG_SECTION_EXPORTING, "prefix", "netdata"));
- engine->config.update_every = exporter_get_number(
- CONFIG_SECTION_EXPORTING, EXPORTING_UPDATE_EVERY_OPTION_NAME, EXPORTING_UPDATE_EVERY_DEFAULT);
+ engine->config.update_every =
+ exporter_get_number(CONFIG_SECTION_EXPORTING, EXPORTING_UPDATE_EVERY_OPTION_NAME, EXPORTING_UPDATE_EVERY_DEFAULT);
}
while (tmp_ci_list) {
@@ -291,27 +262,27 @@ struct engine *read_exporting_config()
info("Instance %s on %s", tmp_ci_list->local_ci.instance_name, tmp_ci_list->local_ci.connector_name);
- if (tmp_ci_list->backend_type == EXPORTING_CONNECTOR_TYPE_UNKNOWN) {
+ if (tmp_ci_list->backend_type == BACKEND_TYPE_UNKNOWN) {
error("Unknown exporting connector type");
goto next_connector_instance;
}
#ifndef ENABLE_PROMETHEUS_REMOTE_WRITE
- if (tmp_ci_list->backend_type == EXPORTING_CONNECTOR_TYPE_PROMETHEUS_REMOTE_WRITE) {
+ if (tmp_ci_list->backend_type == BACKEND_TYPE_PROMETHEUS_REMOTE_WRITE) {
error("Prometheus Remote Write support isn't compiled");
goto next_connector_instance;
}
#endif
#ifndef HAVE_KINESIS
- if (tmp_ci_list->backend_type == EXPORTING_CONNECTOR_TYPE_KINESIS) {
+ if (tmp_ci_list->backend_type == BACKEND_TYPE_KINESIS) {
error("AWS Kinesis support isn't compiled");
goto next_connector_instance;
}
#endif
#ifndef HAVE_MONGOC
- if (tmp_ci_list->backend_type == EXPORTING_CONNECTOR_TYPE_MONGODB) {
+ if (tmp_ci_list->backend_type == BACKEND_TYPE_MONGODB) {
error("MongoDB support isn't compiled");
goto next_connector_instance;
}
@@ -328,31 +299,41 @@ struct engine *read_exporting_config()
tmp_instance->config.name = strdupz(tmp_ci_list->local_ci.instance_name);
- tmp_instance->config.destination = strdupz(exporter_get(instance_name, "destination", "localhost"));
+ tmp_instance->config.destination =
+ strdupz(exporter_get(instance_name, "destination", "localhost"));
tmp_instance->config.update_every =
exporter_get_number(instance_name, EXPORTING_UPDATE_EVERY_OPTION_NAME, EXPORTING_UPDATE_EVERY_DEFAULT);
- tmp_instance->config.buffer_on_failures = exporter_get_number(instance_name, "buffer on failures", 10);
+ tmp_instance->config.buffer_on_failures =
+ exporter_get_number(instance_name, "buffer on failures", 10);
- tmp_instance->config.timeoutms = exporter_get_number(instance_name, "timeout ms", 10000);
+ tmp_instance->config.timeoutms =
+ exporter_get_number(instance_name, "timeout ms", 10000);
- tmp_instance->config.charts_pattern =
- simple_pattern_create(exporter_get(instance_name, "send charts matching", "*"), NULL, SIMPLE_PATTERN_EXACT);
+ tmp_instance->config.charts_pattern = simple_pattern_create(
+ exporter_get(instance_name, "send charts matching", "*"),
+ NULL,
+ SIMPLE_PATTERN_EXACT);
tmp_instance->config.hosts_pattern = simple_pattern_create(
- exporter_get(instance_name, "send hosts matching", "localhost *"), NULL, SIMPLE_PATTERN_EXACT);
+ exporter_get(instance_name, "send hosts matching", "localhost *"),
+ NULL,
+ SIMPLE_PATTERN_EXACT);
- char *data_source = exporter_get(instance_name, "data source", "average");
+ char *data_source =
+ exporter_get(instance_name, "data source", "average");
tmp_instance->config.options = exporting_parse_data_source(data_source, tmp_instance->config.options);
- if (exporter_get_boolean(instance_name, "send configured labels", CONFIG_BOOLEAN_YES))
+ if (exporter_get_boolean(
+ instance_name, "send configured labels", CONFIG_BOOLEAN_YES))
tmp_instance->config.options |= EXPORTING_OPTION_SEND_CONFIGURED_LABELS;
else
tmp_instance->config.options &= ~EXPORTING_OPTION_SEND_CONFIGURED_LABELS;
- if (exporter_get_boolean(instance_name, "send automatic labels", CONFIG_BOOLEAN_NO))
+ if (exporter_get_boolean(
+ instance_name, "send automatic labels", CONFIG_BOOLEAN_NO))
tmp_instance->config.options |= EXPORTING_OPTION_SEND_AUTOMATIC_LABELS;
else
tmp_instance->config.options &= ~EXPORTING_OPTION_SEND_AUTOMATIC_LABELS;
@@ -362,30 +343,33 @@ struct engine *read_exporting_config()
else
tmp_instance->config.options &= ~EXPORTING_OPTION_SEND_NAMES;
- if (tmp_instance->config.type == EXPORTING_CONNECTOR_TYPE_PROMETHEUS_REMOTE_WRITE) {
+ if (tmp_instance->config.type == BACKEND_TYPE_PROMETHEUS_REMOTE_WRITE) {
struct prometheus_remote_write_specific_config *connector_specific_config =
callocz(1, sizeof(struct prometheus_remote_write_specific_config));
tmp_instance->config.connector_specific_config = connector_specific_config;
- connector_specific_config->remote_write_path =
- strdupz(exporter_get(instance_name, "remote write URL path", "/receive"));
+ connector_specific_config->remote_write_path = strdupz(exporter_get(
+ instance_name, "remote write URL path", "/receive"));
}
- if (tmp_instance->config.type == EXPORTING_CONNECTOR_TYPE_KINESIS) {
+ if (tmp_instance->config.type == BACKEND_TYPE_KINESIS) {
struct aws_kinesis_specific_config *connector_specific_config =
callocz(1, sizeof(struct aws_kinesis_specific_config));
tmp_instance->config.connector_specific_config = connector_specific_config;
- connector_specific_config->stream_name = strdupz(exporter_get(instance_name, "stream name", "netdata"));
+ connector_specific_config->stream_name = strdupz(exporter_get(
+ instance_name, "stream name", "netdata"));
- connector_specific_config->auth_key_id = strdupz(exporter_get(instance_name, "aws_access_key_id", ""));
+ connector_specific_config->auth_key_id = strdupz(exporter_get(
+ instance_name, "aws_access_key_id", ""));
- connector_specific_config->secure_key = strdupz(exporter_get(instance_name, "aws_secret_access_key", ""));
+ connector_specific_config->secure_key = strdupz(exporter_get(
+ instance_name, "aws_secret_access_key", ""));
}
- if (tmp_instance->config.type == EXPORTING_CONNECTOR_TYPE_MONGODB) {
+ if (tmp_instance->config.type == BACKEND_TYPE_MONGODB) {
struct mongodb_specific_config *connector_specific_config =
callocz(1, sizeof(struct mongodb_specific_config));
@@ -409,13 +393,14 @@ struct engine *read_exporting_config()
#endif
if (unlikely(!exporting_config_exists) && !engine->config.hostname) {
- engine->config.hostname = strdupz(config_get(instance_name, "hostname", netdata_configured_hostname));
+ engine->config.hostname =
+ strdupz(config_get(instance_name, "hostname", netdata_configured_hostname));
engine->config.prefix = strdupz(config_get(instance_name, "prefix", "netdata"));
engine->config.update_every =
config_get_number(instance_name, EXPORTING_UPDATE_EVERY_OPTION_NAME, EXPORTING_UPDATE_EVERY_DEFAULT);
}
- next_connector_instance:
+next_connector_instance:
tmp_ci_list1 = tmp_ci_list->next;
freez(tmp_ci_list);
tmp_ci_list = tmp_ci_list1;