mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-26 14:09:41 -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))
|
r.Put("/admin/tsdb/snapshot", wrapAgent(api.snapshot))
|
||||||
}
|
}
|
||||||
|
|
||||||
type queryData struct {
|
type QueryData struct {
|
||||||
ResultType parser.ValueType `json:"resultType"`
|
ResultType parser.ValueType `json:"resultType"`
|
||||||
Result parser.Value `json:"result"`
|
Result parser.Value `json:"result"`
|
||||||
Stats stats.QueryStats `json:"stats,omitempty"`
|
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"))
|
qs := sr(ctx, qry.Stats(), r.FormValue("stats"))
|
||||||
|
|
||||||
return apiFuncResult{&queryData{
|
return apiFuncResult{&QueryData{
|
||||||
ResultType: res.Value.Type(),
|
ResultType: res.Value.Type(),
|
||||||
Result: res.Value,
|
Result: res.Value,
|
||||||
Stats: qs,
|
Stats: qs,
|
||||||
|
@ -537,7 +537,7 @@ func (api *API) queryRange(r *http.Request) (result apiFuncResult) {
|
||||||
}
|
}
|
||||||
qs := sr(ctx, qry.Stats(), r.FormValue("stats"))
|
qs := sr(ctx, qry.Stats(), r.FormValue("stats"))
|
||||||
|
|
||||||
return apiFuncResult{&queryData{
|
return apiFuncResult{&QueryData{
|
||||||
ResultType: res.Value.Type(),
|
ResultType: res.Value.Type(),
|
||||||
Result: res.Value,
|
Result: res.Value,
|
||||||
Stats: qs,
|
Stats: qs,
|
||||||
|
|
|
@ -831,8 +831,8 @@ func TestStats(t *testing.T) {
|
||||||
name: "stats is blank",
|
name: "stats is blank",
|
||||||
param: "",
|
param: "",
|
||||||
expected: func(t *testing.T, i interface{}) {
|
expected: func(t *testing.T, i interface{}) {
|
||||||
require.IsType(t, i, &queryData{})
|
require.IsType(t, i, &QueryData{})
|
||||||
qd := i.(*queryData)
|
qd := i.(*QueryData)
|
||||||
require.Nil(t, qd.Stats)
|
require.Nil(t, qd.Stats)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -840,8 +840,8 @@ func TestStats(t *testing.T) {
|
||||||
name: "stats is true",
|
name: "stats is true",
|
||||||
param: "true",
|
param: "true",
|
||||||
expected: func(t *testing.T, i interface{}) {
|
expected: func(t *testing.T, i interface{}) {
|
||||||
require.IsType(t, i, &queryData{})
|
require.IsType(t, i, &QueryData{})
|
||||||
qd := i.(*queryData)
|
qd := i.(*QueryData)
|
||||||
require.NotNil(t, qd.Stats)
|
require.NotNil(t, qd.Stats)
|
||||||
qs := qd.Stats.Builtin()
|
qs := qd.Stats.Builtin()
|
||||||
require.NotNil(t, qs.Timings)
|
require.NotNil(t, qs.Timings)
|
||||||
|
@ -855,8 +855,8 @@ func TestStats(t *testing.T) {
|
||||||
name: "stats is all",
|
name: "stats is all",
|
||||||
param: "all",
|
param: "all",
|
||||||
expected: func(t *testing.T, i interface{}) {
|
expected: func(t *testing.T, i interface{}) {
|
||||||
require.IsType(t, i, &queryData{})
|
require.IsType(t, i, &QueryData{})
|
||||||
qd := i.(*queryData)
|
qd := i.(*QueryData)
|
||||||
require.NotNil(t, qd.Stats)
|
require.NotNil(t, qd.Stats)
|
||||||
qs := qd.Stats.Builtin()
|
qs := qd.Stats.Builtin()
|
||||||
require.NotNil(t, qs.Timings)
|
require.NotNil(t, qs.Timings)
|
||||||
|
@ -876,8 +876,8 @@ func TestStats(t *testing.T) {
|
||||||
},
|
},
|
||||||
param: "known",
|
param: "known",
|
||||||
expected: func(t *testing.T, i interface{}) {
|
expected: func(t *testing.T, i interface{}) {
|
||||||
require.IsType(t, i, &queryData{})
|
require.IsType(t, i, &QueryData{})
|
||||||
qd := i.(*queryData)
|
qd := i.(*QueryData)
|
||||||
require.NotNil(t, qd.Stats)
|
require.NotNil(t, qd.Stats)
|
||||||
j, err := json.Marshal(qd.Stats)
|
j, err := json.Marshal(qd.Stats)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -1037,7 +1037,7 @@ func testEndpoints(t *testing.T, api *API, tr *testTargetRetriever, es storage.E
|
||||||
"query": []string{"2"},
|
"query": []string{"2"},
|
||||||
"time": []string{"123.4"},
|
"time": []string{"123.4"},
|
||||||
},
|
},
|
||||||
response: &queryData{
|
response: &QueryData{
|
||||||
ResultType: parser.ValueTypeScalar,
|
ResultType: parser.ValueTypeScalar,
|
||||||
Result: promql.Scalar{
|
Result: promql.Scalar{
|
||||||
V: 2,
|
V: 2,
|
||||||
|
@ -1051,7 +1051,7 @@ func testEndpoints(t *testing.T, api *API, tr *testTargetRetriever, es storage.E
|
||||||
"query": []string{"0.333"},
|
"query": []string{"0.333"},
|
||||||
"time": []string{"1970-01-01T00:02:03Z"},
|
"time": []string{"1970-01-01T00:02:03Z"},
|
||||||
},
|
},
|
||||||
response: &queryData{
|
response: &QueryData{
|
||||||
ResultType: parser.ValueTypeScalar,
|
ResultType: parser.ValueTypeScalar,
|
||||||
Result: promql.Scalar{
|
Result: promql.Scalar{
|
||||||
V: 0.333,
|
V: 0.333,
|
||||||
|
@ -1065,7 +1065,7 @@ func testEndpoints(t *testing.T, api *API, tr *testTargetRetriever, es storage.E
|
||||||
"query": []string{"0.333"},
|
"query": []string{"0.333"},
|
||||||
"time": []string{"1970-01-01T01:02:03+01:00"},
|
"time": []string{"1970-01-01T01:02:03+01:00"},
|
||||||
},
|
},
|
||||||
response: &queryData{
|
response: &QueryData{
|
||||||
ResultType: parser.ValueTypeScalar,
|
ResultType: parser.ValueTypeScalar,
|
||||||
Result: promql.Scalar{
|
Result: promql.Scalar{
|
||||||
V: 0.333,
|
V: 0.333,
|
||||||
|
@ -1078,7 +1078,7 @@ func testEndpoints(t *testing.T, api *API, tr *testTargetRetriever, es storage.E
|
||||||
query: url.Values{
|
query: url.Values{
|
||||||
"query": []string{"0.333"},
|
"query": []string{"0.333"},
|
||||||
},
|
},
|
||||||
response: &queryData{
|
response: &QueryData{
|
||||||
ResultType: parser.ValueTypeScalar,
|
ResultType: parser.ValueTypeScalar,
|
||||||
Result: promql.Scalar{
|
Result: promql.Scalar{
|
||||||
V: 0.333,
|
V: 0.333,
|
||||||
|
@ -1094,7 +1094,7 @@ func testEndpoints(t *testing.T, api *API, tr *testTargetRetriever, es storage.E
|
||||||
"end": []string{"2"},
|
"end": []string{"2"},
|
||||||
"step": []string{"1"},
|
"step": []string{"1"},
|
||||||
},
|
},
|
||||||
response: &queryData{
|
response: &QueryData{
|
||||||
ResultType: parser.ValueTypeMatrix,
|
ResultType: parser.ValueTypeMatrix,
|
||||||
Result: promql.Matrix{
|
Result: promql.Matrix{
|
||||||
promql.Series{
|
promql.Series{
|
||||||
|
@ -3180,7 +3180,7 @@ func BenchmarkRespond(b *testing.B) {
|
||||||
for i := 0; i < 10000; i++ {
|
for i := 0; i < 10000; i++ {
|
||||||
points = append(points, promql.Point{V: float64(i * 1000000), T: int64(i)})
|
points = append(points, promql.Point{V: float64(i * 1000000), T: int64(i)})
|
||||||
}
|
}
|
||||||
response := &queryData{
|
response := &QueryData{
|
||||||
ResultType: parser.ValueTypeMatrix,
|
ResultType: parser.ValueTypeMatrix,
|
||||||
Result: promql.Matrix{
|
Result: promql.Matrix{
|
||||||
promql.Series{
|
promql.Series{
|
||||||
|
|
|
@ -30,7 +30,7 @@ func TestJsonCodec_Encode(t *testing.T) {
|
||||||
expected string
|
expected string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
response: &queryData{
|
response: &QueryData{
|
||||||
ResultType: parser.ValueTypeMatrix,
|
ResultType: parser.ValueTypeMatrix,
|
||||||
Result: promql.Matrix{
|
Result: promql.Matrix{
|
||||||
promql.Series{
|
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"]]}]}}`,
|
expected: `{"status":"success","data":{"resultType":"matrix","result":[{"metric":{"__name__":"foo"},"values":[[1,"1"]]}]}}`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
response: &queryData{
|
response: &QueryData{
|
||||||
ResultType: parser.ValueTypeMatrix,
|
ResultType: parser.ValueTypeMatrix,
|
||||||
Result: promql.Matrix{
|
Result: promql.Matrix{
|
||||||
promql.Series{
|
promql.Series{
|
||||||
|
|
Loading…
Reference in a new issue