Merge pull request #376 from prometheus/move-api-endpoint

web: Move /api/-/reload endpoint to /-/reload.
This commit is contained in:
Fabian Reinartz 2016-06-12 12:14:16 +02:00 committed by GitHub
commit 6db9089469
3 changed files with 9 additions and 18 deletions

15
api.go
View File

@ -58,7 +58,6 @@ type API struct {
config string
resolveTimeout time.Duration
uptime time.Time
reloadCh chan struct{}
groups func() AlertOverview
@ -75,7 +74,6 @@ func NewAPI(alerts provider.Alerts, silences provider.Silences, gf func() AlertO
silences: silences,
groups: gf,
uptime: time.Now(),
reloadCh: make(chan struct{}),
}
}
@ -84,9 +82,6 @@ func NewAPI(alerts provider.Alerts, silences provider.Silences, gf func() AlertO
func (api *API) Register(r *route.Router) {
ihf := prometheus.InstrumentHandlerFunc
// Register reload API for reload configuration.
r.Post("/-/reload", api.reload)
// Register legacy forwarder for alert pushing.
r.Post("/alerts", ihf("legacy_add_alerts", api.legacyAddAlerts))
@ -114,11 +109,6 @@ func (api *API) Update(config string, resolveTimeout time.Duration) {
api.resolveTimeout = resolveTimeout
}
// Reload returns the receive-only channel that signals configuration reload requests.
func (api *API) Reload() <-chan struct{} {
return api.reloadCh
}
type errorType string
const (
@ -383,11 +373,6 @@ func (api *API) listSilences(w http.ResponseWriter, r *http.Request) {
respond(w, sils)
}
func (api *API) reload(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Reloading configuration file...")
api.reloadCh <- struct{}{}
}
type status string
const (

View File

@ -187,7 +187,8 @@ func main() {
router := route.New()
RegisterWeb(router.WithPrefix(amURL.Path))
webReload := make(chan struct{})
RegisterWeb(router.WithPrefix(amURL.Path), webReload)
api.Register(router.WithPrefix(path.Join(amURL.Path, "/api")))
log.Infoln("Listening on", *listenAddress)
@ -206,7 +207,7 @@ func main() {
for {
select {
case <-hup:
case <-api.Reload():
case <-webReload:
}
reload()
}

7
web.go
View File

@ -47,7 +47,7 @@ func serveAsset(w http.ResponseWriter, req *http.Request, fp string) {
}
// RegisterWeb registers handlers to serve files for the web interface.
func RegisterWeb(r *route.Router) {
func RegisterWeb(r *route.Router, reloadCh chan<- struct{}) {
ihf := prometheus.InstrumentHandlerFunc
r.Get("/app/*filepath", ihf("app_files",
@ -69,6 +69,11 @@ func RegisterWeb(r *route.Router) {
serveAsset(w, req, "ui/app/index.html")
}))
r.Post("/-/reload", func(w http.ResponseWriter, req *http.Request) {
w.Write([]byte("Reloading configuration file..."))
reloadCh <- struct{}{}
})
r.Get("/debug/*subpath", http.DefaultServeMux.ServeHTTP)
r.Post("/debug/*subpath", http.DefaultServeMux.ServeHTTP)
}