mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-22 16:36:27 +01:00
622000797a
- Expose stats.seriesFetched at `/api/v1/query_range` responses too for the sake of consistency. - Initialize QueryStats when it is needed and pass it to EvalConfig then. This guarantees that the QueryStats is properly collected when the query contains some subqueries.
44 lines
1.2 KiB
Plaintext
44 lines
1.2 KiB
Plaintext
{% 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(rs []netstorage.Result, qt *querytracer.Tracer, qtDone func(), qs *promql.QueryStats) %}
|
|
{
|
|
{% code seriesCount := len(rs) %}
|
|
"status":"success",
|
|
"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":{
|
|
"seriesFetched": "{%d qs.SeriesFetched %}"
|
|
}
|
|
{% code
|
|
qt.Printf("generate /api/v1/query response for series=%d", seriesCount)
|
|
qtDone()
|
|
%}
|
|
{%= dumpQueryTrace(qt) %}
|
|
}
|
|
{% endfunc %}
|
|
{% endstripspace %}
|