Read the prefix option from instance config sections (#9463)
Vladimir Kobal committed
Jul 2, 2020 at 15:33 UTC
4f2de8d5107dbab1e845ae7d33da51ad58467978
11 files changed
+18
-18
exporting/clean_connectors.c
+1
@@ -15,6 +15,7 @@ static void clean_instance_config(struct instance_config *config)
15
freez((void *)config->type_name);
16
freez((void *)config->name);
17
freez((void *)config->destination);
18
+ freez((void *)config->prefix);
19
20
simple_pattern_free(config->charts_pattern);
21
exporting/exporting_engine.c
-1
@@ -36,7 +36,6 @@ static void exporting_clean_engine()
36
clean_instance(current_instance);
37
}
38
39
- freez((void *)engine->config.prefix);
39
freez((void *)engine->config.hostname);
40
freez(engine);
41
}
exporting/exporting_engine.h
+1
-1
@@ -64,6 +64,7 @@ struct instance_config {
64
65
const char *name;
66
const char *destination;
67
+ const char *prefix;
68
69
int update_every;
70
int buffer_on_failures;
@@ -102,7 +103,6 @@ struct mongodb_specific_config {
103
};
104
105
struct engine_config {
105
- const char *prefix;
106
const char *hostname;
107
int update_every;
108
};
exporting/graphite/graphite.c
+2
-2
@@ -128,7 +128,7 @@ int format_dimension_collected_graphite_plaintext(struct instance *instance, RRD
128
buffer_sprintf(
129
instance->buffer,
130
"%s.%s.%s.%s%s%s%s " COLLECTED_NUMBER_FORMAT " %llu\n",
131
- engine->config.prefix,
131
+ instance->config.prefix,
132
(host == localhost) ? engine->config.hostname : host->hostname,
133
chart_name,
134
dimension_name,
@@ -175,7 +175,7 @@ int format_dimension_stored_graphite_plaintext(struct instance *instance, RRDDIM
175
buffer_sprintf(
176
instance->buffer,
177
"%s.%s.%s.%s%s%s%s " CALCULATED_NUMBER_FORMAT " %llu\n",
178
- engine->config.prefix,
178
+ instance->config.prefix,
179
(host == localhost) ? engine->config.hostname : host->hostname,
180
chart_name,
181
dimension_name,
exporting/json/json.c
+2
-2
@@ -133,7 +133,7 @@ int format_dimension_collected_json_plaintext(struct instance *instance, RRDDIM
133
134
"\"timestamp\":%llu}\n",
135
136
- engine->config.prefix,
136
+ instance->config.prefix,
137
(host == localhost) ? engine->config.hostname : host->hostname,
138
tags_pre,
139
tags,
@@ -210,7 +210,7 @@ int format_dimension_stored_json_plaintext(struct instance *instance, RRDDIM *rd
210
211
"\"timestamp\": %llu}\n",
212
213
- engine->config.prefix,
213
+ instance->config.prefix,
214
(host == localhost) ? engine->config.hostname : host->hostname,
215
tags_pre,
216
tags,
exporting/opentsdb/opentsdb.c
+4
-4
@@ -179,7 +179,7 @@ int format_dimension_collected_opentsdb_telnet(struct instance *instance, RRDDIM
179
buffer_sprintf(
180
instance->buffer,
181
"put %s.%s.%s %llu " COLLECTED_NUMBER_FORMAT " host=%s%s%s%s\n",
182
- engine->config.prefix,
182
+ instance->config.prefix,
183
chart_name,
184
dimension_name,
185
(unsigned long long)rd->last_collected_time.tv_sec,
@@ -226,7 +226,7 @@ int format_dimension_stored_opentsdb_telnet(struct instance *instance, RRDDIM *r
226
buffer_sprintf(
227
instance->buffer,
228
"put %s.%s.%s %llu " CALCULATED_NUMBER_FORMAT " host=%s%s%s%s\n",
229
- engine->config.prefix,
229
+ instance->config.prefix,
230
chart_name,
231
dimension_name,
232
(unsigned long long)last_t,
@@ -336,7 +336,7 @@ int format_dimension_collected_opentsdb_http(struct instance *instance, RRDDIM *
336
" \"host\": \"%s%s%s\"%s"
337
" }"
338
"}",
339
- engine->config.prefix,
339
+ instance->config.prefix,
340
chart_name,
341
dimension_name,
342
(unsigned long long)rd->last_collected_time.tv_sec,
@@ -396,7 +396,7 @@ int format_dimension_stored_opentsdb_http(struct instance *instance, RRDDIM *rd)
396
" \"host\": \"%s%s%s\"%s"
397
" }"
398
"}",
399
- engine->config.prefix,
399
+ instance->config.prefix,
400
chart_name,
401
dimension_name,
402
(unsigned long long)last_t,
exporting/prometheus/remote_write/remote_write.c
+3
-3
@@ -258,7 +258,7 @@ int format_dimension_prometheus_remote_write(struct instance *instance, RRDDIM *
258
dimension,
259
(instance->config.options & EXPORTING_OPTION_SEND_NAMES && rd->name) ? rd->name : rd->id,
260
PROMETHEUS_ELEMENT_MAX);
261
- snprintf(name, PROMETHEUS_LABELS_MAX, "%s_%s%s", instance->engine->config.prefix, context, suffix);
261
+ snprintf(name, PROMETHEUS_LABELS_MAX, "%s_%s%s", instance->config.prefix, context, suffix);
262
263
add_metric(
264
connector_specific_data->write_request,
@@ -274,7 +274,7 @@ int format_dimension_prometheus_remote_write(struct instance *instance, RRDDIM *
274
(instance->config.options & EXPORTING_OPTION_SEND_NAMES && rd->name) ? rd->name : rd->id,
275
PROMETHEUS_ELEMENT_MAX);
276
snprintf(
277
- name, PROMETHEUS_LABELS_MAX, "%s_%s_%s%s", instance->engine->config.prefix, context, dimension,
277
+ name, PROMETHEUS_LABELS_MAX, "%s_%s_%s%s", instance->config.prefix, context, dimension,
278
suffix);
279
280
add_metric(
@@ -300,7 +300,7 @@ int format_dimension_prometheus_remote_write(struct instance *instance, RRDDIM *
300
(instance->config.options & EXPORTING_OPTION_SEND_NAMES && rd->name) ? rd->name : rd->id,
301
PROMETHEUS_ELEMENT_MAX);
302
snprintf(
303
- name, PROMETHEUS_LABELS_MAX, "%s_%s%s%s", instance->engine->config.prefix, context, units, suffix);
303
+ name, PROMETHEUS_LABELS_MAX, "%s_%s%s%s", instance->config.prefix, context, units, suffix);
304
305
add_metric(
306
connector_specific_data->write_request,
exporting/read_config.c
+2
-2
@@ -282,7 +282,6 @@ struct engine *read_exporting_config()
282
if (exporting_config_exists) {
283
engine->config.hostname =
284
strdupz(exporter_get(CONFIG_SECTION_EXPORTING, "hostname", netdata_configured_hostname));
285
- engine->config.prefix = strdupz(exporter_get(CONFIG_SECTION_EXPORTING, "prefix", "netdata"));
285
engine->config.update_every = exporter_get_number(
286
CONFIG_SECTION_EXPORTING, EXPORTING_UPDATE_EVERY_OPTION_NAME, EXPORTING_UPDATE_EVERY_DEFAULT);
287
}
@@ -430,6 +429,8 @@ struct engine *read_exporting_config()
429
430
tmp_instance->config.destination = strdupz(exporter_get(instance_name, "destination", default_destination));
431
432
+ tmp_instance->config.prefix = strdupz(exporter_get(instance_name, "prefix", "netdata"));
433
+
434
#ifdef ENABLE_HTTPS
435
if (tmp_instance->config.type == EXPORTING_CONNECTOR_TYPE_OPENTSDB_USING_HTTP && !strncmp(tmp_ci_list->local_ci.connector_name, "opentsdb:https", 14)) {
436
tmp_instance->config.options |= EXPORTING_OPTION_USE_TLS;
@@ -448,7 +449,6 @@ struct engine *read_exporting_config()
449
450
if (unlikely(!exporting_config_exists) && !engine->config.hostname) {
451
engine->config.hostname = strdupz(config_get(instance_name, "hostname", netdata_configured_hostname));
451
- engine->config.prefix = strdupz(config_get(instance_name, "prefix", "netdata"));
452
engine->config.update_every =
453
config_get_number(instance_name, EXPORTING_UPDATE_EVERY_OPTION_NAME, EXPORTING_UPDATE_EVERY_DEFAULT);
454
}
exporting/tests/exporting_doubles.c
+1
-1
@@ -12,7 +12,6 @@ struct engine *__wrap_read_exporting_config()
12
struct engine *__mock_read_exporting_config()
13
{
14
struct engine *engine = calloc(1, sizeof(struct engine));
15
- engine->config.prefix = strdupz("netdata");
15
engine->config.hostname = strdupz("test-host");
16
engine->config.update_every = 3;
17
@@ -23,6 +22,7 @@ struct engine *__mock_read_exporting_config()
22
instance->config.type = EXPORTING_CONNECTOR_TYPE_GRAPHITE;
23
instance->config.name = strdupz("instance_name");
24
instance->config.destination = strdupz("localhost");
25
+ instance->config.prefix = strdupz("netdata");
26
instance->config.update_every = 1;
27
instance->config.buffer_on_failures = 10;
28
instance->config.timeoutms = 10000;
exporting/tests/exporting_fixtures.c
+1
-1
@@ -18,11 +18,11 @@ int teardown_configured_engine(void **state)
18
struct instance *instance = engine->instance_root;
19
free((void *)instance->config.destination);
20
free((void *)instance->config.name);
21
+ free((void *)instance->config.prefix);
22
simple_pattern_free(instance->config.charts_pattern);
23
simple_pattern_free(instance->config.hosts_pattern);
24
free(instance);
25
25
- free((void *)engine->config.prefix);
26
free((void *)engine->config.hostname);
27
free(engine);
28
exporting/tests/test_exporting_engine.c
+1
-1
@@ -77,7 +77,6 @@ static void test_read_exporting_config(void **state)
77
*state = engine;
78
79
assert_ptr_not_equal(engine, NULL);
80
- assert_string_equal(engine->config.prefix, "netdata");
80
assert_string_equal(engine->config.hostname, "test-host");
81
assert_int_equal(engine->config.update_every, 3);
82
assert_int_equal(engine->instance_num, 0);
@@ -89,6 +88,7 @@ static void test_read_exporting_config(void **state)
88
assert_ptr_equal(instance->engine, engine);
89
assert_int_equal(instance->config.type, EXPORTING_CONNECTOR_TYPE_GRAPHITE);
90
assert_string_equal(instance->config.destination, "localhost");
91
+ assert_string_equal(instance->config.prefix, "netdata");
92
assert_int_equal(instance->config.update_every, 1);
93
assert_int_equal(instance->config.buffer_on_failures, 10);
94
assert_int_equal(instance->config.timeoutms, 10000);