summaryrefslogtreecommitdiffstats
path: root/exporting
diff options
context:
space:
mode:
authorVladimir Kobal <vlad@prokk.net>2022-07-11 20:05:18 +0300
committerGitHub <noreply@github.com>2022-07-11 20:05:18 +0300
commit0c954d2257fe3f87cb928fbc35841d07ce3a3fea (patch)
treee0ac8d4f747107560c66590e6f770552eff2a383 /exporting
parent56a1808d2e72beb2cb08aea847d3e231d4eea823 (diff)
Move host tags to netdata_info (#13358)
Diffstat (limited to 'exporting')
-rw-r--r--exporting/prometheus/prometheus.c76
-rw-r--r--exporting/tests/test_exporting_engine.c12
2 files changed, 17 insertions, 71 deletions
diff --git a/exporting/prometheus/prometheus.c b/exporting/prometheus/prometheus.c
index 1a9c72e8a0..7d632164f6 100644
--- a/exporting/prometheus/prometheus.c
+++ b/exporting/prometheus/prometheus.c
@@ -525,74 +525,26 @@ static void rrd_stats_api_v1_charts_allmetrics_prometheus(
format_host_labels_prometheus(instance, host);
+ buffer_sprintf(
+ wb,
+ "netdata_info{instance=\"%s\",application=\"%s\",version=\"%s\"",
+ hostname,
+ host->program_name,
+ host->program_version);
+
+ if (instance->labels_buffer && *buffer_tostring(instance->labels_buffer)) {
+ buffer_sprintf(wb, ",%s", buffer_tostring(instance->labels_buffer));
+ }
+
if (output_options & PROMETHEUS_OUTPUT_TIMESTAMPS)
- buffer_sprintf(
- wb,
- "netdata_info{instance=\"%s\",application=\"%s\",version=\"%s\"} 1 %llu\n",
- hostname,
- host->program_name,
- host->program_version,
- now_realtime_usec() / USEC_PER_MS);
+ buffer_sprintf(wb, "} 1 %llu\n", now_realtime_usec() / USEC_PER_MS);
else
- buffer_sprintf(
- wb,
- "netdata_info{instance=\"%s\",application=\"%s\",version=\"%s\"} 1\n",
- hostname,
- host->program_name,
- host->program_version);
+ buffer_sprintf(wb, "} 1\n");
char labels[PROMETHEUS_LABELS_MAX + 1] = "";
if (allhosts) {
- if (instance->labels_buffer && buffer_tostring(instance->labels_buffer)) {
- if (output_options & PROMETHEUS_OUTPUT_TIMESTAMPS) {
- buffer_sprintf(
- wb,
- "netdata_host_tags_info{instance=\"%s\",%s} 1 %llu\n",
- hostname,
- buffer_tostring(instance->labels_buffer),
- now_realtime_usec() / USEC_PER_MS);
-
- // deprecated, exists only for compatibility with older queries
- buffer_sprintf(
- wb,
- "netdata_host_tags{instance=\"%s\",%s} 1 %llu\n",
- hostname,
- buffer_tostring(instance->labels_buffer),
- now_realtime_usec() / USEC_PER_MS);
- } else {
- buffer_sprintf(
- wb, "netdata_host_tags_info{instance=\"%s\",%s} 1\n", hostname, buffer_tostring(instance->labels_buffer));
-
- // deprecated, exists only for compatibility with older queries
- buffer_sprintf(
- wb, "netdata_host_tags{instance=\"%s\",%s} 1\n", hostname, buffer_tostring(instance->labels_buffer));
- }
- }
-
snprintfz(labels, PROMETHEUS_LABELS_MAX, ",instance=\"%s\"", hostname);
- } else {
- if (instance->labels_buffer && buffer_tostring(instance->labels_buffer)) {
- if (output_options & PROMETHEUS_OUTPUT_TIMESTAMPS) {
- buffer_sprintf(
- wb,
- "netdata_host_tags_info{%s} 1 %llu\n",
- buffer_tostring(instance->labels_buffer),
- now_realtime_usec() / USEC_PER_MS);
-
- // deprecated, exists only for compatibility with older queries
- buffer_sprintf(
- wb,
- "netdata_host_tags{%s} 1 %llu\n",
- buffer_tostring(instance->labels_buffer),
- now_realtime_usec() / USEC_PER_MS);
- } else {
- buffer_sprintf(wb, "netdata_host_tags_info{%s} 1\n", buffer_tostring(instance->labels_buffer));
-
- // deprecated, exists only for compatibility with older queries
- buffer_sprintf(wb, "netdata_host_tags{%s} 1\n", buffer_tostring(instance->labels_buffer));
- }
- }
- }
+ }
if (instance->labels_buffer)
buffer_flush(instance->labels_buffer);
diff --git a/exporting/tests/test_exporting_engine.c b/exporting/tests/test_exporting_engine.c
index bc00e34e1a..56a28059fb 100644
--- a/exporting/tests/test_exporting_engine.c
+++ b/exporting/tests/test_exporting_engine.c
@@ -1069,9 +1069,7 @@ static void rrd_stats_api_v1_charts_allmetrics_prometheus(void **state)
assert_string_equal(
buffer_tostring(buffer),
- "netdata_info{instance=\"test_hostname\",application=\"(null)\",version=\"(null)\"} 1\n"
- "netdata_host_tags_info{key1=\"value1\",key2=\"value2\"} 1\n"
- "netdata_host_tags{key1=\"value1\",key2=\"value2\"} 1\n"
+ "netdata_info{instance=\"test_hostname\",application=\"(null)\",version=\"(null)\",key1=\"value1\",key2=\"value2\"} 1\n"
"test_prefix_test_context{chart=\"chart_id\",family=\"test_family\",dimension=\"dimension_id\"} 690565856.0000000\n");
buffer_flush(buffer);
@@ -1087,9 +1085,7 @@ static void rrd_stats_api_v1_charts_allmetrics_prometheus(void **state)
assert_string_equal(
buffer_tostring(buffer),
- "netdata_info{instance=\"test_hostname\",application=\"(null)\",version=\"(null)\"} 1\n"
- "netdata_host_tags_info{key1=\"value1\",key2=\"value2\"} 1\n"
- "netdata_host_tags{key1=\"value1\",key2=\"value2\"} 1\n"
+ "netdata_info{instance=\"test_hostname\",application=\"(null)\",version=\"(null)\",key1=\"value1\",key2=\"value2\"} 1\n"
"# TYPE test_prefix_test_context gauge\n"
"test_prefix_test_context{chart=\"chart_name\",family=\"test_family\",dimension=\"dimension_name\"} 690565856.0000000\n");
@@ -1105,9 +1101,7 @@ static void rrd_stats_api_v1_charts_allmetrics_prometheus(void **state)
assert_string_equal(
buffer_tostring(buffer),
- "netdata_info{instance=\"test_hostname\",application=\"(null)\",version=\"(null)\"} 1\n"
- "netdata_host_tags_info{instance=\"test_hostname\",key1=\"value1\",key2=\"value2\"} 1\n"
- "netdata_host_tags{instance=\"test_hostname\",key1=\"value1\",key2=\"value2\"} 1\n"
+ "netdata_info{instance=\"test_hostname\",application=\"(null)\",version=\"(null)\",key1=\"value1\",key2=\"value2\"} 1\n"
"test_prefix_test_context{chart=\"chart_id\",family=\"test_family\",dimension=\"dimension_id\",instance=\"test_hostname\"} 690565856.0000000\n");
free(localhost->rrdset_root->context);