@cryptotaxi247 / netdata-1 / commits / 0c954d225

Move host tags to netdata_info (#13358)

Vladimir Kobal committed Jul 11, 2022 at 20:05 UTC 0c954d2257fe3f87cb928fbc35841d07ce3a3fea
2 files changed +17 -71
exporting/prometheus/prometheus.c
+14 -62
@@ -525,74 +525,26 @@ static void rrd_stats_api_v1_charts_allmetrics_prometheus(
525
526 format_host_labels_prometheus(instance, host);
527
528 + buffer_sprintf(
529 + wb,
530 + "netdata_info{instance=\"%s\",application=\"%s\",version=\"%s\"",
531 + hostname,
532 + host->program_name,
533 + host->program_version);
534 +
535 + if (instance->labels_buffer && *buffer_tostring(instance->labels_buffer)) {
536 + buffer_sprintf(wb, ",%s", buffer_tostring(instance->labels_buffer));
537 + }
538 +
539 if (output_options & PROMETHEUS_OUTPUT_TIMESTAMPS)
529 - buffer_sprintf(
530 - wb,
531 - "netdata_info{instance=\"%s\",application=\"%s\",version=\"%s\"} 1 %llu\n",
532 - hostname,
533 - host->program_name,
534 - host->program_version,
535 - now_realtime_usec() / USEC_PER_MS);
540 + buffer_sprintf(wb, "} 1 %llu\n", now_realtime_usec() / USEC_PER_MS);
541 else
537 - buffer_sprintf(
538 - wb,
539 - "netdata_info{instance=\"%s\",application=\"%s\",version=\"%s\"} 1\n",
540 - hostname,
541 - host->program_name,
542 - host->program_version);
542 + buffer_sprintf(wb, "} 1\n");
543
544 char labels[PROMETHEUS_LABELS_MAX + 1] = "";
545 if (allhosts) {
546 - if (instance->labels_buffer && buffer_tostring(instance->labels_buffer)) {
547 - if (output_options & PROMETHEUS_OUTPUT_TIMESTAMPS) {
548 - buffer_sprintf(
549 - wb,
550 - "netdata_host_tags_info{instance=\"%s\",%s} 1 %llu\n",
551 - hostname,
552 - buffer_tostring(instance->labels_buffer),
553 - now_realtime_usec() / USEC_PER_MS);
554 -
555 - // deprecated, exists only for compatibility with older queries
556 - buffer_sprintf(
557 - wb,
558 - "netdata_host_tags{instance=\"%s\",%s} 1 %llu\n",
559 - hostname,
560 - buffer_tostring(instance->labels_buffer),
561 - now_realtime_usec() / USEC_PER_MS);
562 - } else {
563 - buffer_sprintf(
564 - wb, "netdata_host_tags_info{instance=\"%s\",%s} 1\n", hostname, buffer_tostring(instance->labels_buffer));
565 -
566 - // deprecated, exists only for compatibility with older queries
567 - buffer_sprintf(
568 - wb, "netdata_host_tags{instance=\"%s\",%s} 1\n", hostname, buffer_tostring(instance->labels_buffer));
569 - }
570 - }
571 -
546 snprintfz(labels, PROMETHEUS_LABELS_MAX, ",instance=\"%s\"", hostname);
573 - } else {
574 - if (instance->labels_buffer && buffer_tostring(instance->labels_buffer)) {
575 - if (output_options & PROMETHEUS_OUTPUT_TIMESTAMPS) {
576 - buffer_sprintf(
577 - wb,
578 - "netdata_host_tags_info{%s} 1 %llu\n",
579 - buffer_tostring(instance->labels_buffer),
580 - now_realtime_usec() / USEC_PER_MS);
581 -
582 - // deprecated, exists only for compatibility with older queries
583 - buffer_sprintf(
584 - wb,
585 - "netdata_host_tags{%s} 1 %llu\n",
586 - buffer_tostring(instance->labels_buffer),
587 - now_realtime_usec() / USEC_PER_MS);
588 - } else {
589 - buffer_sprintf(wb, "netdata_host_tags_info{%s} 1\n", buffer_tostring(instance->labels_buffer));
590 -
591 - // deprecated, exists only for compatibility with older queries
592 - buffer_sprintf(wb, "netdata_host_tags{%s} 1\n", buffer_tostring(instance->labels_buffer));
593 - }
594 - }
595 - }
547 + }
548
549 if (instance->labels_buffer)
550 buffer_flush(instance->labels_buffer);
exporting/tests/test_exporting_engine.c
+3 -9
@@ -1069,9 +1069,7 @@ static void rrd_stats_api_v1_charts_allmetrics_prometheus(void **state)
1069
1070 assert_string_equal(
1071 buffer_tostring(buffer),
1072 - "netdata_info{instance=\"test_hostname\",application=\"(null)\",version=\"(null)\"} 1\n"
1073 - "netdata_host_tags_info{key1=\"value1\",key2=\"value2\"} 1\n"
1074 - "netdata_host_tags{key1=\"value1\",key2=\"value2\"} 1\n"
1072 + "netdata_info{instance=\"test_hostname\",application=\"(null)\",version=\"(null)\",key1=\"value1\",key2=\"value2\"} 1\n"
1073 "test_prefix_test_context{chart=\"chart_id\",family=\"test_family\",dimension=\"dimension_id\"} 690565856.0000000\n");
1074
1075 buffer_flush(buffer);
@@ -1087,9 +1085,7 @@ static void rrd_stats_api_v1_charts_allmetrics_prometheus(void **state)
1085
1086 assert_string_equal(
1087 buffer_tostring(buffer),
1090 - "netdata_info{instance=\"test_hostname\",application=\"(null)\",version=\"(null)\"} 1\n"
1091 - "netdata_host_tags_info{key1=\"value1\",key2=\"value2\"} 1\n"
1092 - "netdata_host_tags{key1=\"value1\",key2=\"value2\"} 1\n"
1088 + "netdata_info{instance=\"test_hostname\",application=\"(null)\",version=\"(null)\",key1=\"value1\",key2=\"value2\"} 1\n"
1089 "# TYPE test_prefix_test_context gauge\n"
1090 "test_prefix_test_context{chart=\"chart_name\",family=\"test_family\",dimension=\"dimension_name\"} 690565856.0000000\n");
1091
@@ -1105,9 +1101,7 @@ static void rrd_stats_api_v1_charts_allmetrics_prometheus(void **state)
1101
1102 assert_string_equal(
1103 buffer_tostring(buffer),
1108 - "netdata_info{instance=\"test_hostname\",application=\"(null)\",version=\"(null)\"} 1\n"
1109 - "netdata_host_tags_info{instance=\"test_hostname\",key1=\"value1\",key2=\"value2\"} 1\n"
1110 - "netdata_host_tags{instance=\"test_hostname\",key1=\"value1\",key2=\"value2\"} 1\n"
1104 + "netdata_info{instance=\"test_hostname\",application=\"(null)\",version=\"(null)\",key1=\"value1\",key2=\"value2\"} 1\n"
1105 "test_prefix_test_context{chart=\"chart_id\",family=\"test_family\",dimension=\"dimension_id\",instance=\"test_hostname\"} 690565856.0000000\n");
1106
1107 free(localhost->rrdset_root->context);