mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +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...
49 lines
1.5 KiB
Text
49 lines
1.5 KiB
Text
{% import (
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmselect/netstorage"
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmselect/promql"
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/querytracer"
|
|
) %}
|
|
|
|
{% 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(), qs *promql.QueryStats) %}
|
|
{
|
|
{% code seriesCount := len(rs) %}
|
|
"status":"success",
|
|
"isPartial":{% if isPartial %}true{% else %}false{% endif %},
|
|
"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 %}
|
|
]
|
|
},
|
|
"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 response for series=%d", seriesCount)
|
|
qtDone()
|
|
%}
|
|
{%= dumpQueryTrace(qt) %}
|
|
}
|
|
{% endfunc %}
|
|
{% endstripspace %}
|