Skip to content

Commit

Permalink
Merge pull request #376 from prometheus/move-api-endpoint
Browse files Browse the repository at this point in the history
web: Move /api/-/reload endpoint to /-/reload.
  • Loading branch information
fabxc authored Jun 12, 2016
2 parents 5843dcf + 55eb960 commit 6db9089
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 18 deletions.
15 changes: 0 additions & 15 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ type API struct {
config string
resolveTimeout time.Duration
uptime time.Time
reloadCh chan struct{}

groups func() AlertOverview

Expand All @@ -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{}),
}
}

Expand All @@ -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))

Expand Down Expand Up @@ -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 (
Expand Down Expand Up @@ -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 (
Expand Down
5 changes: 3 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -206,7 +207,7 @@ func main() {
for {
select {
case <-hup:
case <-api.Reload():
case <-webReload:
}
reload()
}
Expand Down
7 changes: 6 additions & 1 deletion web.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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)
}

0 comments on commit 6db9089

Please sign in to comment.