// Code generated by qtc from "query_response.qtpl". DO NOT EDIT.
// See https://github.com/valyala/quicktemplate for details.

//line app/vmselect/prometheus/query_response.qtpl:1
package prometheus

//line app/vmselect/prometheus/query_response.qtpl:1
import (
	"github.com/VictoriaMetrics/VictoriaMetrics/app/vmselect/netstorage"
	"github.com/VictoriaMetrics/VictoriaMetrics/app/vmselect/promql"
	"github.com/VictoriaMetrics/VictoriaMetrics/lib/querytracer"
)

// QueryResponse generates response for /api/v1/query.See https://prometheus.io/docs/prometheus/latest/querying/api/#instant-queries

//line app/vmselect/prometheus/query_response.qtpl:10
import (
	qtio422016 "io"

	qt422016 "github.com/valyala/quicktemplate"
)

//line app/vmselect/prometheus/query_response.qtpl:10
var (
	_ = qtio422016.Copy
	_ = qt422016.AcquireByteBuffer
)

//line app/vmselect/prometheus/query_response.qtpl:10
func StreamQueryResponse(qw422016 *qt422016.Writer, rs []netstorage.Result, qt *querytracer.Tracer, qtDone func(), qs *promql.QueryStats) {
//line app/vmselect/prometheus/query_response.qtpl:10
	qw422016.N().S(`{`)
//line app/vmselect/prometheus/query_response.qtpl:12
	seriesCount := len(rs)

//line app/vmselect/prometheus/query_response.qtpl:12
	qw422016.N().S(`"status":"success","data":{"resultType":"vector","result":[`)
//line app/vmselect/prometheus/query_response.qtpl:17
	if len(rs) > 0 {
//line app/vmselect/prometheus/query_response.qtpl:17
		qw422016.N().S(`{"metric":`)
//line app/vmselect/prometheus/query_response.qtpl:19
		streammetricNameObject(qw422016, &rs[0].MetricName)
//line app/vmselect/prometheus/query_response.qtpl:19
		qw422016.N().S(`,"value":`)
//line app/vmselect/prometheus/query_response.qtpl:20
		streammetricRow(qw422016, rs[0].Timestamps[0], rs[0].Values[0])
//line app/vmselect/prometheus/query_response.qtpl:20
		qw422016.N().S(`}`)
//line app/vmselect/prometheus/query_response.qtpl:22
		rs = rs[1:]

//line app/vmselect/prometheus/query_response.qtpl:23
		for i := range rs {
//line app/vmselect/prometheus/query_response.qtpl:24
			r := &rs[i]

//line app/vmselect/prometheus/query_response.qtpl:24
			qw422016.N().S(`,{"metric":`)
//line app/vmselect/prometheus/query_response.qtpl:26
			streammetricNameObject(qw422016, &r.MetricName)
//line app/vmselect/prometheus/query_response.qtpl:26
			qw422016.N().S(`,"value":`)
//line app/vmselect/prometheus/query_response.qtpl:27
			streammetricRow(qw422016, r.Timestamps[0], r.Values[0])
//line app/vmselect/prometheus/query_response.qtpl:27
			qw422016.N().S(`}`)
//line app/vmselect/prometheus/query_response.qtpl:29
		}
//line app/vmselect/prometheus/query_response.qtpl:30
	}
//line app/vmselect/prometheus/query_response.qtpl:30
	qw422016.N().S(`]},"stats":{`)
//line app/vmselect/prometheus/query_response.qtpl:35
	// seriesFetched is string instead of int because of historical reasons.
	// It cannot be converted to int without breaking backwards compatibility at vmalert :(
	executionDuration := int64(0)
	if ed := qs.ExecutionDuration.Load(); ed != nil {
		executionDuration = ed.Milliseconds()
	}

//line app/vmselect/prometheus/query_response.qtpl:41
	qw422016.N().S(`"seriesFetched": "`)
//line app/vmselect/prometheus/query_response.qtpl:42
	qw422016.N().DL(qs.SeriesFetched.Load())
//line app/vmselect/prometheus/query_response.qtpl:42
	qw422016.N().S(`","executionTimeMsec":`)
//line app/vmselect/prometheus/query_response.qtpl:43
	qw422016.N().DL(executionDuration)
//line app/vmselect/prometheus/query_response.qtpl:43
	qw422016.N().S(`}`)
//line app/vmselect/prometheus/query_response.qtpl:46
	qt.Printf("generate /api/v1/query response for series=%d", seriesCount)
	qtDone()

//line app/vmselect/prometheus/query_response.qtpl:49
	streamdumpQueryTrace(qw422016, qt)
//line app/vmselect/prometheus/query_response.qtpl:49
	qw422016.N().S(`}`)
//line app/vmselect/prometheus/query_response.qtpl:51
}

//line app/vmselect/prometheus/query_response.qtpl:51
func WriteQueryResponse(qq422016 qtio422016.Writer, rs []netstorage.Result, qt *querytracer.Tracer, qtDone func(), qs *promql.QueryStats) {
//line app/vmselect/prometheus/query_response.qtpl:51
	qw422016 := qt422016.AcquireWriter(qq422016)
//line app/vmselect/prometheus/query_response.qtpl:51
	StreamQueryResponse(qw422016, rs, qt, qtDone, qs)
//line app/vmselect/prometheus/query_response.qtpl:51
	qt422016.ReleaseWriter(qw422016)
//line app/vmselect/prometheus/query_response.qtpl:51
}

//line app/vmselect/prometheus/query_response.qtpl:51
func QueryResponse(rs []netstorage.Result, qt *querytracer.Tracer, qtDone func(), qs *promql.QueryStats) string {
//line app/vmselect/prometheus/query_response.qtpl:51
	qb422016 := qt422016.AcquireByteBuffer()
//line app/vmselect/prometheus/query_response.qtpl:51
	WriteQueryResponse(qb422016, rs, qt, qtDone, qs)
//line app/vmselect/prometheus/query_response.qtpl:51
	qs422016 := string(qb422016.B)
//line app/vmselect/prometheus/query_response.qtpl:51
	qt422016.ReleaseByteBuffer(qb422016)
//line app/vmselect/prometheus/query_response.qtpl:51
	return qs422016
//line app/vmselect/prometheus/query_response.qtpl:51
}
