diff options
author | Vladimir Kobal <vlad@prokk.net> | 2020-12-14 16:25:13 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-14 16:25:13 +0200 |
commit | 81968dea3a411aed2f451a941354283b945a35de (patch) | |
tree | 58f9d1331a9bd7df27adc2e04e426220be9c0f07 | |
parent | c3b1528bb91250958c9947a33bb26c3a8e04bd38 (diff) |
Fix hostname configuration in the exporting engine (#10361)
-rw-r--r-- | exporting/clean_connectors.c | 1 | ||||
-rw-r--r-- | exporting/exporting_engine.h | 1 | ||||
-rw-r--r-- | exporting/graphite/graphite.c | 6 | ||||
-rw-r--r-- | exporting/json/json.c | 6 | ||||
-rw-r--r-- | exporting/opentsdb/opentsdb.c | 12 | ||||
-rw-r--r-- | exporting/prometheus/remote_write/remote_write.c | 10 | ||||
-rw-r--r-- | exporting/read_config.c | 2 | ||||
-rw-r--r-- | exporting/tests/exporting_doubles.c | 3 | ||||
-rw-r--r-- | exporting/tests/exporting_fixtures.c | 1 | ||||
-rw-r--r-- | exporting/tests/test_exporting_engine.c | 4 |
10 files changed, 22 insertions, 24 deletions
diff --git a/exporting/clean_connectors.c b/exporting/clean_connectors.c index 459777f0fd..890e8daac7 100644 --- a/exporting/clean_connectors.c +++ b/exporting/clean_connectors.c @@ -16,6 +16,7 @@ static void clean_instance_config(struct instance_config *config) freez((void *)config->name); freez((void *)config->destination); freez((void *)config->prefix); + freez((void *)config->hostname); simple_pattern_free(config->charts_pattern); diff --git a/exporting/exporting_engine.h b/exporting/exporting_engine.h index e0993c98f8..1d9feb7dd4 100644 --- a/exporting/exporting_engine.h +++ b/exporting/exporting_engine.h @@ -67,6 +67,7 @@ struct instance_config { const char *name; const char *destination; const char *prefix; + const char *hostname; int update_every; int buffer_on_failures; diff --git a/exporting/graphite/graphite.c b/exporting/graphite/graphite.c index 23e40c369e..dac1d7682e 100644 --- a/exporting/graphite/graphite.c +++ b/exporting/graphite/graphite.c @@ -127,7 +127,6 @@ int format_host_labels_graphite_plaintext(struct instance *instance, RRDHOST *ho */ int format_dimension_collected_graphite_plaintext(struct instance *instance, RRDDIM *rd) { - struct engine *engine = instance->engine; RRDSET *st = rd->rrdset; RRDHOST *host = st->rrdhost; @@ -147,7 +146,7 @@ int format_dimension_collected_graphite_plaintext(struct instance *instance, RRD instance->buffer, "%s.%s.%s.%s%s%s%s " COLLECTED_NUMBER_FORMAT " %llu\n", instance->config.prefix, - (host == localhost) ? engine->config.hostname : host->hostname, + (host == localhost) ? instance->config.hostname : host->hostname, chart_name, dimension_name, (host->tags) ? ";" : "", @@ -168,7 +167,6 @@ int format_dimension_collected_graphite_plaintext(struct instance *instance, RRD */ int format_dimension_stored_graphite_plaintext(struct instance *instance, RRDDIM *rd) { - struct engine *engine = instance->engine; RRDSET *st = rd->rrdset; RRDHOST *host = st->rrdhost; @@ -194,7 +192,7 @@ int format_dimension_stored_graphite_plaintext(struct instance *instance, RRDDIM instance->buffer, "%s.%s.%s.%s%s%s%s " CALCULATED_NUMBER_FORMAT " %llu\n", instance->config.prefix, - (host == localhost) ? engine->config.hostname : host->hostname, + (host == localhost) ? instance->config.hostname : host->hostname, chart_name, dimension_name, (host->tags) ? ";" : "", diff --git a/exporting/json/json.c b/exporting/json/json.c index 458e7e8cce..e746d64ae0 100644 --- a/exporting/json/json.c +++ b/exporting/json/json.c @@ -154,7 +154,6 @@ int format_host_labels_json_plaintext(struct instance *instance, RRDHOST *host) */ int format_dimension_collected_json_plaintext(struct instance *instance, RRDDIM *rd) { - struct engine *engine = instance->engine; RRDSET *st = rd->rrdset; RRDHOST *host = st->rrdhost; @@ -200,7 +199,7 @@ int format_dimension_collected_json_plaintext(struct instance *instance, RRDDIM "\"timestamp\":%llu}", instance->config.prefix, - (host == localhost) ? engine->config.hostname : host->hostname, + (host == localhost) ? instance->config.hostname : host->hostname, tags_pre, tags, tags_post, @@ -235,7 +234,6 @@ int format_dimension_collected_json_plaintext(struct instance *instance, RRDDIM */ int format_dimension_stored_json_plaintext(struct instance *instance, RRDDIM *rd) { - struct engine *engine = instance->engine; RRDSET *st = rd->rrdset; RRDHOST *host = st->rrdhost; @@ -286,7 +284,7 @@ int format_dimension_stored_json_plaintext(struct instance *instance, RRDDIM *rd "\"timestamp\": %llu}", instance->config.prefix, - (host == localhost) ? engine->config.hostname : host->hostname, + (host == localhost) ? instance->config.hostname : host->hostname, tags_pre, tags, tags_post, diff --git a/exporting/opentsdb/opentsdb.c b/exporting/opentsdb/opentsdb.c index 4ee1e3a6f3..4d00f893e3 100644 --- a/exporting/opentsdb/opentsdb.c +++ b/exporting/opentsdb/opentsdb.c @@ -178,7 +178,6 @@ int format_host_labels_opentsdb_telnet(struct instance *instance, RRDHOST *host) */ int format_dimension_collected_opentsdb_telnet(struct instance *instance, RRDDIM *rd) { - struct engine *engine = instance->engine; RRDSET *st = rd->rrdset; RRDHOST *host = st->rrdhost; @@ -202,7 +201,7 @@ int format_dimension_collected_opentsdb_telnet(struct instance *instance, RRDDIM dimension_name, (unsigned long long)rd->last_collected_time.tv_sec, rd->last_collected_value, - (host == localhost) ? engine->config.hostname : host->hostname, + (host == localhost) ? instance->config.hostname : host->hostname, (host->tags) ? " " : "", (host->tags) ? host->tags : "", (instance->labels) ? buffer_tostring(instance->labels) : ""); @@ -219,7 +218,6 @@ int format_dimension_collected_opentsdb_telnet(struct instance *instance, RRDDIM */ int format_dimension_stored_opentsdb_telnet(struct instance *instance, RRDDIM *rd) { - struct engine *engine = instance->engine; RRDSET *st = rd->rrdset; RRDHOST *host = st->rrdhost; @@ -249,7 +247,7 @@ int format_dimension_stored_opentsdb_telnet(struct instance *instance, RRDDIM *r dimension_name, (unsigned long long)last_t, value, - (host == localhost) ? engine->config.hostname : host->hostname, + (host == localhost) ? instance->config.hostname : host->hostname, (host->tags) ? " " : "", (host->tags) ? host->tags : "", (instance->labels) ? buffer_tostring(instance->labels) : ""); @@ -326,7 +324,6 @@ int format_host_labels_opentsdb_http(struct instance *instance, RRDHOST *host) */ int format_dimension_collected_opentsdb_http(struct instance *instance, RRDDIM *rd) { - struct engine *engine = instance->engine; RRDSET *st = rd->rrdset; RRDHOST *host = st->rrdhost; @@ -360,7 +357,7 @@ int format_dimension_collected_opentsdb_http(struct instance *instance, RRDDIM * dimension_name, (unsigned long long)rd->last_collected_time.tv_sec, rd->last_collected_value, - (host == localhost) ? engine->config.hostname : host->hostname, + (host == localhost) ? instance->config.hostname : host->hostname, (host->tags) ? " " : "", (host->tags) ? host->tags : "", instance->labels ? buffer_tostring(instance->labels) : ""); @@ -377,7 +374,6 @@ int format_dimension_collected_opentsdb_http(struct instance *instance, RRDDIM * */ int format_dimension_stored_opentsdb_http(struct instance *instance, RRDDIM *rd) { - struct engine *engine = instance->engine; RRDSET *st = rd->rrdset; RRDHOST *host = st->rrdhost; @@ -417,7 +413,7 @@ int format_dimension_stored_opentsdb_http(struct instance *instance, RRDDIM *rd) dimension_name, (unsigned long long)last_t, value, - (host == localhost) ? engine->config.hostname : host->hostname, + (host == localhost) ? instance->config.hostname : host->hostname, (host->tags) ? " " : "", (host->tags) ? host->tags : "", instance->labels ? buffer_tostring(instance->labels) : ""); diff --git a/exporting/prometheus/remote_write/remote_write.c b/exporting/prometheus/remote_write/remote_write.c index b75f3546e8..bd7ff48f20 100644 --- a/exporting/prometheus/remote_write/remote_write.c +++ b/exporting/prometheus/remote_write/remote_write.c @@ -147,7 +147,7 @@ int format_host_prometheus_remote_write(struct instance *instance, RRDHOST *host char hostname[PROMETHEUS_ELEMENT_MAX + 1]; prometheus_label_copy( hostname, - (host == localhost) ? instance->engine->config.hostname : host->hostname, + (host == localhost) ? instance->config.hostname : host->hostname, PROMETHEUS_ELEMENT_MAX); add_host_info( @@ -236,7 +236,7 @@ int format_dimension_prometheus_remote_write(struct instance *instance, RRDDIM * "EXPORTING: not sending dimension '%s' of chart '%s' from host '%s', " "its last data collection (%lu) is not within our timeframe (%lu to %lu)", rd->id, rd->rrdset->id, - (host == localhost) ? instance->engine->config.hostname : host->hostname, + (host == localhost) ? instance->config.hostname : host->hostname, (unsigned long)rd->last_collected_time.tv_sec, (unsigned long)instance->after, (unsigned long)instance->before); @@ -256,7 +256,7 @@ int format_dimension_prometheus_remote_write(struct instance *instance, RRDDIM * add_metric( connector_specific_data->write_request, name, chart, family, dimension, - (host == localhost) ? instance->engine->config.hostname : host->hostname, + (host == localhost) ? instance->config.hostname : host->hostname, rd->last_collected_value, timeval_msec(&rd->last_collected_time)); } else { // the dimensions of the chart, do not have the same algorithm, multiplier or divisor @@ -273,7 +273,7 @@ int format_dimension_prometheus_remote_write(struct instance *instance, RRDDIM * add_metric( connector_specific_data->write_request, name, chart, family, NULL, - (host == localhost) ? instance->engine->config.hostname : host->hostname, + (host == localhost) ? instance->config.hostname : host->hostname, rd->last_collected_value, timeval_msec(&rd->last_collected_time)); } } else { @@ -298,7 +298,7 @@ int format_dimension_prometheus_remote_write(struct instance *instance, RRDDIM * add_metric( connector_specific_data->write_request, name, chart, family, dimension, - (host == localhost) ? instance->engine->config.hostname : host->hostname, + (host == localhost) ? instance->config.hostname : host->hostname, value, last_t * MSEC_PER_SEC); } } diff --git a/exporting/read_config.c b/exporting/read_config.c index 3ace9c26e1..0cba4ad2c4 100644 --- a/exporting/read_config.c +++ b/exporting/read_config.c @@ -445,6 +445,8 @@ struct engine *read_exporting_config() tmp_instance->config.prefix = strdupz(exporter_get(instance_name, "prefix", "netdata")); + tmp_instance->config.hostname = strdupz(exporter_get(instance_name, "hostname", engine->config.hostname)); + #ifdef ENABLE_HTTPS #define STR_GRAPHITE_HTTPS "graphite:https" diff --git a/exporting/tests/exporting_doubles.c b/exporting/tests/exporting_doubles.c index 7560069c0a..3c73e0327c 100644 --- a/exporting/tests/exporting_doubles.c +++ b/exporting/tests/exporting_doubles.c @@ -12,7 +12,7 @@ struct engine *__wrap_read_exporting_config() struct engine *__mock_read_exporting_config() { struct engine *engine = calloc(1, sizeof(struct engine)); - engine->config.hostname = strdupz("test-host"); + engine->config.hostname = strdupz("test_engine_host"); engine->config.update_every = 3; @@ -23,6 +23,7 @@ struct engine *__mock_read_exporting_config() instance->config.name = strdupz("instance_name"); instance->config.destination = strdupz("localhost"); instance->config.prefix = strdupz("netdata"); + instance->config.hostname = strdupz("test-host"); instance->config.update_every = 1; instance->config.buffer_on_failures = 10; instance->config.timeoutms = 10000; diff --git a/exporting/tests/exporting_fixtures.c b/exporting/tests/exporting_fixtures.c index 06a9cfe067..42a8e5a749 100644 --- a/exporting/tests/exporting_fixtures.c +++ b/exporting/tests/exporting_fixtures.c @@ -20,6 +20,7 @@ int teardown_configured_engine(void **state) free((void *)instance->config.destination); free((void *)instance->config.name); free((void *)instance->config.prefix); + free((void *)instance->config.hostname); simple_pattern_free(instance->config.charts_pattern); simple_pattern_free(instance->config.hosts_pattern); free(instance); diff --git a/exporting/tests/test_exporting_engine.c b/exporting/tests/test_exporting_engine.c index f76784f4c4..b2065a26d8 100644 --- a/exporting/tests/test_exporting_engine.c +++ b/exporting/tests/test_exporting_engine.c @@ -10,7 +10,7 @@ netdata_rwlock_t rrd_rwlock; struct config netdata_config; char *netdata_configured_user_config_dir = "."; char *netdata_configured_stock_config_dir = "."; -char *netdata_configured_hostname = "test_host"; +char *netdata_configured_hostname = "test_global_host"; char log_line[MAX_LOG_LINE + 1]; @@ -80,7 +80,7 @@ static void test_read_exporting_config(void **state) *state = engine; assert_ptr_not_equal(engine, NULL); - assert_string_equal(engine->config.hostname, "test-host"); + assert_string_equal(engine->config.hostname, "test_engine_host"); assert_int_equal(engine->config.update_every, 3); assert_int_equal(engine->instance_num, 0); |