mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-01 14:47:38 +00:00
ae9b4c94bc
vmalert expects string value for stats.seriesFetched, so it is impossible switching to number without breaking compatibility with old vmalert releases :( It is still unclear why stats.seriesFetched has string type in the first place...
55 lines
1.6 KiB
Text
55 lines
1.6 KiB
Text
{% import (
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmselect/netstorage"
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmselect/promql"
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/querytracer"
|
|
) %}
|
|
|
|
{% stripspace %}
|
|
QueryRangeResponse generates response for /api/v1/query_range.
|
|
See https://prometheus.io/docs/prometheus/latest/querying/api/#range-queries
|
|
{% func QueryRangeResponse(isPartial bool, rs []netstorage.Result, qt *querytracer.Tracer, qtDone func(), qs *promql.QueryStats) %}
|
|
{
|
|
{% code
|
|
seriesCount := len(rs)
|
|
pointsCount := 0
|
|
%}
|
|
"status":"success",
|
|
"isPartial":{% if isPartial %}true{% else %}false{% endif %},
|
|
"data":{
|
|
"resultType":"matrix",
|
|
"result":[
|
|
{% if len(rs) > 0 %}
|
|
{%= queryRangeLine(&rs[0]) %}
|
|
{% code pointsCount += len(rs[0].Values) %}
|
|
{% code rs = rs[1:] %}
|
|
{% for i := range rs %}
|
|
,{%= queryRangeLine(&rs[i]) %}
|
|
{% code pointsCount += len(rs[i].Values) %}
|
|
{% endfor %}
|
|
{% endif %}
|
|
]
|
|
},
|
|
"stats":{
|
|
{% code
|
|
// seriesFetched is string instead of int because of historical reasons.
|
|
// It cannot be converted to int without breaking backwards compatibility at vmalert :(
|
|
%}
|
|
"seriesFetched": "{%dl qs.SeriesFetched %}",
|
|
"executionTimeMsec": {%dl qs.ExecutionTimeMsec %}
|
|
}
|
|
{% code
|
|
qt.Printf("generate /api/v1/query_range response for series=%d, points=%d", seriesCount, pointsCount)
|
|
qtDone()
|
|
%}
|
|
{%= dumpQueryTrace(qt) %}
|
|
}
|
|
{% endfunc %}
|
|
|
|
{% func queryRangeLine(r *netstorage.Result) %}
|
|
{
|
|
"metric": {%= metricNameObject(&r.MetricName) %},
|
|
"values": {%= valuesWithTimestamps(r.Values, r.Timestamps) %}
|
|
}
|
|
{% endfunc %}
|
|
|
|
{% endstripspace %}
|