VictoriaMetrics/app/vmselect/prometheus/federate.qtpl

34 lines
882 B
Plaintext
Raw Normal View History

2019-05-22 23:16:55 +02:00
{% import (
"math"
2019-05-22 23:16:55 +02:00
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmselect/netstorage"
) %}
{% stripspace %}
// Federate writes rs in /federate format.
// See https://prometheus.io/docs/prometheus/latest/federation/
{% func Federate(rs *netstorage.Result) %}
{% code
values := rs.Values
timestamps := rs.Timestamps
%}
{% if len(timestamps) == 0 || len(values) == 0 %}{% return %}{% endif %}
{% code
lastValue := values[len(values)-1]
%}
{% if math.IsNaN(lastValue) %}
{% comment %}
This is most likely a staleness marker.
Return nothing after the staleness marker.
See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3185
{% endcomment %}
{% return %}
{% endif %}
2019-05-22 23:16:55 +02:00
{%= prometheusMetricName(&rs.MetricName) %}{% space %}
{%f= lastValue %}{% space %}
{%dl= timestamps[len(timestamps)-1] %}{% newline %}
2019-05-22 23:16:55 +02:00
{% endfunc %}
{% endstripspace %}