@ -68,31 +68,29 @@ type Handler struct {
apiV1 * api_v1 . API
router * route . Router
listenErrCh chan error
quitCh chan struct { }
reloadCh chan chan error
options * Options
configString string
versionInfo * PrometheusVersion
birth time . Time
cwd string
flagsMap map [ string ] string
externalLabels model . LabelSet
mtx sync . RWMutex
now func ( ) model . Time
router * route . Router
listenErrCh chan error
quitCh chan struct { }
reloadCh chan chan error
options * Options
config * config . Config
versionInfo * PrometheusVersion
birth time . Time
cwd string
flagsMap map [ string ] string
mtx sync . RWMutex
now func ( ) model . Time
ready uint32 // ready is uint32 rather than boolean to be able to use atomic functions.
}
// ApplyConfig updates the status state as the new config requires.
// ApplyConfig updates the config field of the Handler struct
func ( h * Handler ) ApplyConfig ( conf * config . Config ) error {
h . mtx . Lock ( )
defer h . mtx . Unlock ( )
h . externalLabels = conf . GlobalConfig . ExternalLabels
h . configString = conf . String ( )
h . config = conf
return nil
}
@ -158,12 +156,23 @@ func New(o *Options) *Handler {
storage : o . Storage ,
notifier : o . Notifier ,
apiV1 : api_v1 . NewAPI ( o . QueryEngine , o . Storage , o . TargetManager , o . Notifier ) ,
now : model . Now ,
now : model . Now ,
ready : 0 ,
}
h . apiV1 = api_v1 . NewAPI (
o . QueryEngine ,
o . Storage ,
o . TargetManager ,
o . Notifier ,
func ( ) config . Config {
h . mtx . RLock ( )
defer h . mtx . RUnlock ( )
return * h . config
} ,
)
if o . RoutePrefix != "/" {
// If the prefix is missing for the root path, prepend it.
router . Get ( "/" , func ( w http . ResponseWriter , r * http . Request ) {
@ -184,7 +193,7 @@ func New(o *Options) *Handler {
router . Get ( "/graph" , readyf ( instrf ( "graph" , h . graph ) ) )
router . Get ( "/status" , readyf ( instrf ( "status" , h . status ) ) )
router . Get ( "/flags" , readyf ( instrf ( "flags" , h . flags ) ) )
router . Get ( "/config" , readyf ( instrf ( "config" , h . c onfig) ) )
router . Get ( "/config" , readyf ( instrf ( "config" , h . serveC onfig) ) )
router . Get ( "/rules" , readyf ( instrf ( "rules" , h . rules ) ) )
router . Get ( "/targets" , readyf ( instrf ( "targets" , h . targets ) ) )
router . Get ( "/version" , readyf ( instrf ( "version" , h . version ) ) )
@ -404,11 +413,11 @@ func (h *Handler) flags(w http.ResponseWriter, r *http.Request) {
h . executeTemplate ( w , "flags.html" , h . flagsMap )
}
func ( h * Handler ) c onfig( w http . ResponseWriter , r * http . Request ) {
func ( h * Handler ) serveC onfig( w http . ResponseWriter , r * http . Request ) {
h . mtx . RLock ( )
defer h . mtx . RUnlock ( )
h . executeTemplate ( w , "config.html" , h . configString )
h . executeTemplate ( w , "config.html" , h . config . String ( ) )
}
func ( h * Handler ) rules ( w http . ResponseWriter , r * http . Request ) {