VictoriaMetrics/app/vmselect/prometheus/query_response.qtpl

41 lines
1.1 KiB
Plaintext
Raw Normal View History

2019-05-22 23:16:55 +02:00
{% import (
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmselect/netstorage"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/querytracer"
2019-05-22 23:16:55 +02:00
) %}
{% stripspace %}
QueryResponse generates response for /api/v1/query.
See https://prometheus.io/docs/prometheus/latest/querying/api/#instant-queries
{% func QueryResponse(isPartial bool, rs []netstorage.Result, qt *querytracer.Tracer, qtDone func()) %}
2019-05-22 23:16:55 +02:00
{
{% code seriesCount := len(rs) %}
2019-05-22 23:16:55 +02:00
"status":"success",
"isPartial":{% if isPartial %}true{% else %}false{% endif %},
2019-05-22 23:16:55 +02:00
"data":{
"resultType":"vector",
"result":[
{% if len(rs) > 0 %}
{
"metric": {%= metricNameObject(&rs[0].MetricName) %},
"value": {%= metricRow(rs[0].Timestamps[0], rs[0].Values[0]) %}
}
{% code rs = rs[1:] %}
{% for i := range rs %}
{% code r := &rs[i] %}
,{
"metric": {%= metricNameObject(&r.MetricName) %},
"value": {%= metricRow(r.Timestamps[0], r.Values[0]) %}
}
{% endfor %}
{% endif %}
]
}
{% code
qt.Printf("generate /api/v1/query response for series=%d", seriesCount)
qtDone()
%}
{%= dumpQueryTrace(qt) %}
2019-05-22 23:16:55 +02:00
}
{% endfunc %}
{% endstripspace %}