2019-05-22 21:16:55 +00:00
|
|
|
{% import (
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmselect/netstorage"
|
2023-03-27 22:11:40 +00:00
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmselect/promql"
|
2022-05-31 23:31:40 +00:00
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/querytracer"
|
2019-05-22 21:16:55 +00:00
|
|
|
) %}
|
|
|
|
|
|
|
|
{% stripspace %}
|
|
|
|
QueryResponse generates response for /api/v1/query.
|
|
|
|
See https://prometheus.io/docs/prometheus/latest/querying/api/#instant-queries
|
2023-03-27 22:11:40 +00:00
|
|
|
{% func QueryResponse(isPartial bool, rs []netstorage.Result, qt *querytracer.Tracer, qtDone func(), qs *promql.QueryStats) %}
|
2019-05-22 21:16:55 +00:00
|
|
|
{
|
2022-05-31 23:31:40 +00:00
|
|
|
{% code seriesCount := len(rs) %}
|
2019-05-22 21:16:55 +00:00
|
|
|
"status":"success",
|
2020-11-14 10:36:21 +00:00
|
|
|
"isPartial":{% if isPartial %}true{% else %}false{% endif %},
|
2019-05-22 21:16:55 +00: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 %}
|
|
|
|
]
|
2023-03-27 15:51:33 +00:00
|
|
|
},
|
|
|
|
"stats":{
|
2023-11-01 16:46:50 +00:00
|
|
|
{% code
|
|
|
|
// seriesFetched is string instead of int because of historical reasons.
|
|
|
|
// It cannot be converted to int without breaking backwards compatibility at vmalert :(
|
|
|
|
%}
|
2024-02-24 00:44:19 +00:00
|
|
|
"seriesFetched": "{%dl qs.SeriesFetched.Load() %}",
|
|
|
|
"executionTimeMsec": {%dl qs.ExecutionTimeMsec.Load() %}
|
2019-05-22 21:16:55 +00:00
|
|
|
}
|
2022-05-31 23:31:40 +00:00
|
|
|
{% code
|
|
|
|
qt.Printf("generate /api/v1/query response for series=%d", seriesCount)
|
|
|
|
qtDone()
|
|
|
|
%}
|
|
|
|
{%= dumpQueryTrace(qt) %}
|
2019-05-22 21:16:55 +00:00
|
|
|
}
|
|
|
|
{% endfunc %}
|
|
|
|
{% endstripspace %}
|