2019-05-22 21:16:55 +00:00
|
|
|
{% import (
|
2022-10-01 16:47:35 +00:00
|
|
|
"math"
|
|
|
|
|
2019-05-22 21:16:55 +00: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) %}
|
2022-10-01 16:47:35 +00:00
|
|
|
{% 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 21:16:55 +00:00
|
|
|
{%= prometheusMetricName(&rs.MetricName) %}{% space %}
|
2022-10-01 16:47:35 +00:00
|
|
|
{%f= lastValue %}{% space %}
|
|
|
|
{%dl= timestamps[len(timestamps)-1] %}{% newline %}
|
2019-05-22 21:16:55 +00:00
|
|
|
{% endfunc %}
|
|
|
|
|
|
|
|
{% endstripspace %}
|