mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
Review feedback
* renamed MakeQueryStats * added stats to query() as well * gofmt
This commit is contained in:
parent
c93e54d240
commit
af75ce02c1
|
@ -61,9 +61,9 @@ type QueryStats struct {
|
||||||
ExecTotalTime float64 `json:"execTotalTime"`
|
ExecTotalTime float64 `json:"execTotalTime"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// MakeQueryStats makes a QueryStats struct with all QueryTimings found in the
|
// NewQueryStats makes a QueryStats struct with all QueryTimings found in the
|
||||||
// given TimerGroup.
|
// given TimerGroup.
|
||||||
func MakeQueryStats(tg *TimerGroup) *QueryStats {
|
func NewQueryStats(tg *TimerGroup) *QueryStats {
|
||||||
var qs QueryStats
|
var qs QueryStats
|
||||||
|
|
||||||
for s, timer := range tg.timers {
|
for s, timer := range tg.timers {
|
||||||
|
|
|
@ -171,8 +171,8 @@ func (api *API) Register(r *route.Router) {
|
||||||
}
|
}
|
||||||
|
|
||||||
type queryData struct {
|
type queryData struct {
|
||||||
ResultType promql.ValueType `json:"resultType"`
|
ResultType promql.ValueType `json:"resultType"`
|
||||||
Result promql.Value `json:"result"`
|
Result promql.Value `json:"result"`
|
||||||
Stats *stats.QueryStats `json:"stats,omitempty"`
|
Stats *stats.QueryStats `json:"stats,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -221,9 +221,17 @@ func (api *API) query(r *http.Request) (interface{}, *apiError) {
|
||||||
}
|
}
|
||||||
return nil, &apiError{errorExec, res.Err}
|
return nil, &apiError{errorExec, res.Err}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Optional stats field in response if parameter "stats" is not empty.
|
||||||
|
var qs *stats.QueryStats
|
||||||
|
if r.FormValue("stats") != "" {
|
||||||
|
qs = stats.NewQueryStats(qry.Stats())
|
||||||
|
}
|
||||||
|
|
||||||
return &queryData{
|
return &queryData{
|
||||||
ResultType: res.Value.Type(),
|
ResultType: res.Value.Type(),
|
||||||
Result: res.Value,
|
Result: res.Value,
|
||||||
|
Stats: qs,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -289,7 +297,7 @@ func (api *API) queryRange(r *http.Request) (interface{}, *apiError) {
|
||||||
// Optional stats field in response if parameter "stats" is not empty.
|
// Optional stats field in response if parameter "stats" is not empty.
|
||||||
var qs *stats.QueryStats
|
var qs *stats.QueryStats
|
||||||
if r.FormValue("stats") != "" {
|
if r.FormValue("stats") != "" {
|
||||||
qs = stats.MakeQueryStats(qry.Stats())
|
qs = stats.NewQueryStats(qry.Stats())
|
||||||
}
|
}
|
||||||
|
|
||||||
return &queryData{
|
return &queryData{
|
||||||
|
|
Loading…
Reference in a new issue