mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-26 06:04:05 -08:00
Expose QueryData so that implementations of Codec.CanEncode() can perform a type assertion against Response.Data.
Signed-off-by: Charles Korn <charles.korn@grafana.com>
This commit is contained in:
parent
a0dd1468be
commit
857b23873f
|
@ -384,7 +384,7 @@ func (api *API) Register(r *route.Router) {
|
|||
r.Put("/admin/tsdb/snapshot", wrapAgent(api.snapshot))
|
||||
}
|
||||
|
||||
type queryData struct {
|
||||
type QueryData struct {
|
||||
ResultType parser.ValueType `json:"resultType"`
|
||||
Result parser.Value `json:"result"`
|
||||
Stats stats.QueryStats `json:"stats,omitempty"`
|
||||
|
@ -446,7 +446,7 @@ func (api *API) query(r *http.Request) (result apiFuncResult) {
|
|||
}
|
||||
qs := sr(ctx, qry.Stats(), r.FormValue("stats"))
|
||||
|
||||
return apiFuncResult{&queryData{
|
||||
return apiFuncResult{&QueryData{
|
||||
ResultType: res.Value.Type(),
|
||||
Result: res.Value,
|
||||
Stats: qs,
|
||||
|
@ -537,7 +537,7 @@ func (api *API) queryRange(r *http.Request) (result apiFuncResult) {
|
|||
}
|
||||
qs := sr(ctx, qry.Stats(), r.FormValue("stats"))
|
||||
|
||||
return apiFuncResult{&queryData{
|
||||
return apiFuncResult{&QueryData{
|
||||
ResultType: res.Value.Type(),
|
||||
Result: res.Value,
|
||||
Stats: qs,
|
||||
|
|
|
@ -831,8 +831,8 @@ func TestStats(t *testing.T) {
|
|||
name: "stats is blank",
|
||||
param: "",
|
||||
expected: func(t *testing.T, i interface{}) {
|
||||
require.IsType(t, i, &queryData{})
|
||||
qd := i.(*queryData)
|
||||
require.IsType(t, i, &QueryData{})
|
||||
qd := i.(*QueryData)
|
||||
require.Nil(t, qd.Stats)
|
||||
},
|
||||
},
|
||||
|
@ -840,8 +840,8 @@ func TestStats(t *testing.T) {
|
|||
name: "stats is true",
|
||||
param: "true",
|
||||
expected: func(t *testing.T, i interface{}) {
|
||||
require.IsType(t, i, &queryData{})
|
||||
qd := i.(*queryData)
|
||||
require.IsType(t, i, &QueryData{})
|
||||
qd := i.(*QueryData)
|
||||
require.NotNil(t, qd.Stats)
|
||||
qs := qd.Stats.Builtin()
|
||||
require.NotNil(t, qs.Timings)
|
||||
|
@ -855,8 +855,8 @@ func TestStats(t *testing.T) {
|
|||
name: "stats is all",
|
||||
param: "all",
|
||||
expected: func(t *testing.T, i interface{}) {
|
||||
require.IsType(t, i, &queryData{})
|
||||
qd := i.(*queryData)
|
||||
require.IsType(t, i, &QueryData{})
|
||||
qd := i.(*QueryData)
|
||||
require.NotNil(t, qd.Stats)
|
||||
qs := qd.Stats.Builtin()
|
||||
require.NotNil(t, qs.Timings)
|
||||
|
@ -876,8 +876,8 @@ func TestStats(t *testing.T) {
|
|||
},
|
||||
param: "known",
|
||||
expected: func(t *testing.T, i interface{}) {
|
||||
require.IsType(t, i, &queryData{})
|
||||
qd := i.(*queryData)
|
||||
require.IsType(t, i, &QueryData{})
|
||||
qd := i.(*QueryData)
|
||||
require.NotNil(t, qd.Stats)
|
||||
j, err := json.Marshal(qd.Stats)
|
||||
require.NoError(t, err)
|
||||
|
@ -1037,7 +1037,7 @@ func testEndpoints(t *testing.T, api *API, tr *testTargetRetriever, es storage.E
|
|||
"query": []string{"2"},
|
||||
"time": []string{"123.4"},
|
||||
},
|
||||
response: &queryData{
|
||||
response: &QueryData{
|
||||
ResultType: parser.ValueTypeScalar,
|
||||
Result: promql.Scalar{
|
||||
V: 2,
|
||||
|
@ -1051,7 +1051,7 @@ func testEndpoints(t *testing.T, api *API, tr *testTargetRetriever, es storage.E
|
|||
"query": []string{"0.333"},
|
||||
"time": []string{"1970-01-01T00:02:03Z"},
|
||||
},
|
||||
response: &queryData{
|
||||
response: &QueryData{
|
||||
ResultType: parser.ValueTypeScalar,
|
||||
Result: promql.Scalar{
|
||||
V: 0.333,
|
||||
|
@ -1065,7 +1065,7 @@ func testEndpoints(t *testing.T, api *API, tr *testTargetRetriever, es storage.E
|
|||
"query": []string{"0.333"},
|
||||
"time": []string{"1970-01-01T01:02:03+01:00"},
|
||||
},
|
||||
response: &queryData{
|
||||
response: &QueryData{
|
||||
ResultType: parser.ValueTypeScalar,
|
||||
Result: promql.Scalar{
|
||||
V: 0.333,
|
||||
|
@ -1078,7 +1078,7 @@ func testEndpoints(t *testing.T, api *API, tr *testTargetRetriever, es storage.E
|
|||
query: url.Values{
|
||||
"query": []string{"0.333"},
|
||||
},
|
||||
response: &queryData{
|
||||
response: &QueryData{
|
||||
ResultType: parser.ValueTypeScalar,
|
||||
Result: promql.Scalar{
|
||||
V: 0.333,
|
||||
|
@ -1094,7 +1094,7 @@ func testEndpoints(t *testing.T, api *API, tr *testTargetRetriever, es storage.E
|
|||
"end": []string{"2"},
|
||||
"step": []string{"1"},
|
||||
},
|
||||
response: &queryData{
|
||||
response: &QueryData{
|
||||
ResultType: parser.ValueTypeMatrix,
|
||||
Result: promql.Matrix{
|
||||
promql.Series{
|
||||
|
@ -3180,7 +3180,7 @@ func BenchmarkRespond(b *testing.B) {
|
|||
for i := 0; i < 10000; i++ {
|
||||
points = append(points, promql.Point{V: float64(i * 1000000), T: int64(i)})
|
||||
}
|
||||
response := &queryData{
|
||||
response := &QueryData{
|
||||
ResultType: parser.ValueTypeMatrix,
|
||||
Result: promql.Matrix{
|
||||
promql.Series{
|
||||
|
|
|
@ -30,7 +30,7 @@ func TestJsonCodec_Encode(t *testing.T) {
|
|||
expected string
|
||||
}{
|
||||
{
|
||||
response: &queryData{
|
||||
response: &QueryData{
|
||||
ResultType: parser.ValueTypeMatrix,
|
||||
Result: promql.Matrix{
|
||||
promql.Series{
|
||||
|
@ -42,7 +42,7 @@ func TestJsonCodec_Encode(t *testing.T) {
|
|||
expected: `{"status":"success","data":{"resultType":"matrix","result":[{"metric":{"__name__":"foo"},"values":[[1,"1"]]}]}}`,
|
||||
},
|
||||
{
|
||||
response: &queryData{
|
||||
response: &QueryData{
|
||||
ResultType: parser.ValueTypeMatrix,
|
||||
Result: promql.Matrix{
|
||||
promql.Series{
|
||||
|
|
Loading…
Reference in a new issue