@ -116,9 +116,11 @@ type RulesRetriever interface {
AlertingRules ( ) [ ] * rules . AlertingRule
AlertingRules ( ) [ ] * rules . AlertingRule
}
}
// StatsRenderer converts engine statistics into a format suitable for the API.
type StatsRenderer func ( context . Context , * stats . Statistics , string ) stats . QueryStats
type StatsRenderer func ( context . Context , * stats . Statistics , string ) stats . QueryStats
func defaultStatsRenderer ( _ context . Context , s * stats . Statistics , param string ) stats . QueryStats {
// DefaultStatsRenderer is the default stats renderer for the API.
func DefaultStatsRenderer ( _ context . Context , s * stats . Statistics , param string ) stats . QueryStats {
if param != "" {
if param != "" {
return stats . NewQueryStats ( s )
return stats . NewQueryStats ( s )
}
}
@ -272,7 +274,7 @@ func NewAPI(
buildInfo : buildInfo ,
buildInfo : buildInfo ,
gatherer : gatherer ,
gatherer : gatherer ,
isAgent : isAgent ,
isAgent : isAgent ,
statsRenderer : d efaultStatsRenderer,
statsRenderer : D efaultStatsRenderer,
remoteReadHandler : remote . NewReadHandler ( logger , registerer , q , configFunc , remoteReadSampleLimit , remoteReadConcurrencyLimit , remoteReadMaxBytesInFrame ) ,
remoteReadHandler : remote . NewReadHandler ( logger , registerer , q , configFunc , remoteReadSampleLimit , remoteReadConcurrencyLimit , remoteReadMaxBytesInFrame ) ,
}
}
@ -461,7 +463,7 @@ func (api *API) query(r *http.Request) (result apiFuncResult) {
// Optional stats field in response if parameter "stats" is not empty.
// Optional stats field in response if parameter "stats" is not empty.
sr := api . statsRenderer
sr := api . statsRenderer
if sr == nil {
if sr == nil {
sr = d efaultStatsRenderer
sr = D efaultStatsRenderer
}
}
qs := sr ( ctx , qry . Stats ( ) , r . FormValue ( "stats" ) )
qs := sr ( ctx , qry . Stats ( ) , r . FormValue ( "stats" ) )
@ -563,7 +565,7 @@ func (api *API) queryRange(r *http.Request) (result apiFuncResult) {
// Optional stats field in response if parameter "stats" is not empty.
// Optional stats field in response if parameter "stats" is not empty.
sr := api . statsRenderer
sr := api . statsRenderer
if sr == nil {
if sr == nil {
sr = d efaultStatsRenderer
sr = D efaultStatsRenderer
}
}
qs := sr ( ctx , qry . Stats ( ) , r . FormValue ( "stats" ) )
qs := sr ( ctx , qry . Stats ( ) , r . FormValue ( "stats" ) )