mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-27 02:46:47 +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.
50 lines
1.3 KiB
Plaintext
50 lines
1.3 KiB
Plaintext
{% 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(rs []netstorage.Result, qt *querytracer.Tracer, qtDone func(), qs *promql.QueryStats) %}
|
|
{
|
|
{% code
|
|
seriesCount := len(rs)
|
|
pointsCount := 0
|
|
%}
|
|
"status":"success",
|
|
"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":{
|
|
"seriesFetched": "{%d qs.SeriesFetched %}"
|
|
}
|
|
{% 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 %}
|