2019-05-22 23:16:55 +02:00
|
|
|
{% import (
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmselect/netstorage"
|
2023-03-28 00:11:40 +02:00
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmselect/promql"
|
2022-06-01 01:29:19 +02:00
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/querytracer"
|
2019-05-22 23:16:55 +02:00
|
|
|
) %}
|
|
|
|
|
|
|
|
{% stripspace %}
|
|
|
|
QueryRangeResponse generates response for /api/v1/query_range.
|
|
|
|
See https://prometheus.io/docs/prometheus/latest/querying/api/#range-queries
|
2023-03-28 00:11:40 +02:00
|
|
|
{% func QueryRangeResponse(rs []netstorage.Result, qt *querytracer.Tracer, qtDone func(), qs *promql.QueryStats) %}
|
2019-05-22 23:16:55 +02:00
|
|
|
{
|
2022-06-01 01:29:19 +02:00
|
|
|
{% code
|
|
|
|
seriesCount := len(rs)
|
|
|
|
pointsCount := 0
|
|
|
|
%}
|
2019-05-22 23:16:55 +02:00
|
|
|
"status":"success",
|
|
|
|
"data":{
|
|
|
|
"resultType":"matrix",
|
|
|
|
"result":[
|
|
|
|
{% if len(rs) > 0 %}
|
|
|
|
{%= queryRangeLine(&rs[0]) %}
|
2022-06-01 01:29:19 +02:00
|
|
|
{% code pointsCount += len(rs[0].Values) %}
|
2019-05-22 23:16:55 +02:00
|
|
|
{% code rs = rs[1:] %}
|
|
|
|
{% for i := range rs %}
|
|
|
|
,{%= queryRangeLine(&rs[i]) %}
|
2022-06-01 01:29:19 +02:00
|
|
|
{% code pointsCount += len(rs[i].Values) %}
|
2019-05-22 23:16:55 +02:00
|
|
|
{% endfor %}
|
|
|
|
{% endif %}
|
|
|
|
]
|
2023-03-28 00:11:40 +02:00
|
|
|
},
|
|
|
|
"stats":{
|
2023-11-01 17:46:50 +01: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 01:44:19 +01:00
|
|
|
"seriesFetched": "{%dl qs.SeriesFetched.Load() %}",
|
|
|
|
"executionTimeMsec": {%dl qs.ExecutionTimeMsec.Load() %}
|
2019-05-22 23:16:55 +02:00
|
|
|
}
|
2022-06-01 01:29:19 +02:00
|
|
|
{% code
|
|
|
|
qt.Printf("generate /api/v1/query_range response for series=%d, points=%d", seriesCount, pointsCount)
|
|
|
|
qtDone()
|
|
|
|
%}
|
|
|
|
{%= dumpQueryTrace(qt) %}
|
2019-05-22 23:16:55 +02:00
|
|
|
}
|
|
|
|
{% endfunc %}
|
|
|
|
|
|
|
|
{% func queryRangeLine(r *netstorage.Result) %}
|
|
|
|
{
|
|
|
|
"metric": {%= metricNameObject(&r.MetricName) %},
|
|
|
|
"values": {%= valuesWithTimestamps(r.Values, r.Timestamps) %}
|
|
|
|
}
|
|
|
|
{% endfunc %}
|
|
|
|
|
|
|
|
{% endstripspace %}
|