Browse Source

Fix issue #9085: Prometheus TYPE lines incorrectly formatted (when enabled via query parm) (#9086)

Jeff Gehlbach 4 years ago
parent
commit
a35a951e39

+ 2 - 0
backends/prometheus/README.md

@@ -388,6 +388,8 @@ To save bandwidth, and because prometheus does not use them anyway, `# TYPE` and
 wanted they can be re-enabled via `types=yes` and `help=yes`, e.g.
 `/api/v1/allmetrics?format=prometheus&types=yes&help=yes`
 
+Note that if enabled, the `# TYPE` and `# HELP` lines are repeated for every occurrence of a metric, which goes against the Prometheus documentation's [specification for these lines](https://github.com/prometheus/docs/blob/master/content/docs/instrumenting/exposition_formats.md#comments-help-text-and-type-information).
+
 ### Names and IDs
 
 Netdata supports names and IDs for charts and dimensions. Usually IDs are unique identifiers as read by the system and

+ 3 - 3
backends/prometheus/backend_prometheus.c

@@ -374,7 +374,7 @@ static void rrd_stats_api_v1_charts_allmetrics_prometheus(RRDHOST *host, BUFFER
                                 );
 
                             if(unlikely(output_options & BACKENDS_PROMETHEUS_OUTPUT_TYPES))
-                                buffer_sprintf(wb, "# COMMENT TYPE %s_%s%s %s\n"
+                                buffer_sprintf(wb, "# TYPE %s_%s%s %s\n"
                                                , prefix
                                                , context
                                                , suffix
@@ -432,7 +432,7 @@ static void rrd_stats_api_v1_charts_allmetrics_prometheus(RRDHOST *host, BUFFER
                                 );
 
                             if(unlikely(output_options & BACKENDS_PROMETHEUS_OUTPUT_TYPES))
-                                buffer_sprintf(wb, "# COMMENT TYPE %s_%s_%s%s %s\n"
+                                buffer_sprintf(wb, "# TYPE %s_%s_%s%s %s\n"
                                                , prefix
                                                , context
                                                , dimension
@@ -495,7 +495,7 @@ static void rrd_stats_api_v1_charts_allmetrics_prometheus(RRDHOST *host, BUFFER
                                 );
 
                             if (unlikely(output_options & BACKENDS_PROMETHEUS_OUTPUT_TYPES))
-                                buffer_sprintf(wb, "# COMMENT TYPE %s_%s%s%s gauge\n"
+                                buffer_sprintf(wb, "# TYPE %s_%s%s%s gauge\n"
                                                , prefix
                                                , context
                                                , units

+ 2 - 0
exporting/prometheus/README.md

@@ -389,6 +389,8 @@ To save bandwidth, and because Prometheus does not use them anyway, `# TYPE` and
 wanted they can be re-enabled via `types=yes` and `help=yes`, e.g.
 `/api/v1/allmetrics?format=prometheus&types=yes&help=yes`
 
+Note that if enabled, the `# TYPE` and `# HELP` lines are repeated for every occurrence of a metric, which goes against the Prometheus documentation's [specification for these lines](https://github.com/prometheus/docs/blob/master/content/docs/instrumenting/exposition_formats.md#comments-help-text-and-type-information).
+
 ### Names and IDs
 
 Netdata supports names and IDs for charts and dimensions. Usually IDs are unique identifiers as read by the system and

+ 3 - 3
exporting/prometheus/prometheus.c

@@ -565,7 +565,7 @@ static void rrd_stats_api_v1_charts_allmetrics_prometheus(
                                     t);
 
                             if (unlikely(output_options & PROMETHEUS_OUTPUT_TYPES))
-                                buffer_sprintf(wb, "# COMMENT TYPE %s_%s%s %s\n", prefix, context, suffix, t);
+                                buffer_sprintf(wb, "# TYPE %s_%s%s %s\n", prefix, context, suffix, t);
 
                             if (output_options & PROMETHEUS_OUTPUT_TIMESTAMPS)
                                 buffer_sprintf(
@@ -624,7 +624,7 @@ static void rrd_stats_api_v1_charts_allmetrics_prometheus(
 
                             if (unlikely(output_options & PROMETHEUS_OUTPUT_TYPES))
                                 buffer_sprintf(
-                                    wb, "# COMMENT TYPE %s_%s_%s%s %s\n", prefix, context, dimension, suffix, t);
+                                    wb, "# TYPE %s_%s_%s%s %s\n", prefix, context, dimension, suffix, t);
 
                             if (output_options & PROMETHEUS_OUTPUT_TIMESTAMPS)
                                 buffer_sprintf(
@@ -684,7 +684,7 @@ static void rrd_stats_api_v1_charts_allmetrics_prometheus(
                                     (unsigned long long)last_time);
 
                             if (unlikely(output_options & PROMETHEUS_OUTPUT_TYPES))
-                                buffer_sprintf(wb, "# COMMENT TYPE %s_%s%s%s gauge\n", prefix, context, units, suffix);
+                                buffer_sprintf(wb, "# TYPE %s_%s%s%s gauge\n", prefix, context, units, suffix);
 
                             if (output_options & PROMETHEUS_OUTPUT_TIMESTAMPS)
                                 buffer_sprintf(