Skip to content

Commit

Permalink
Merge branch 'master' of github.com:prometheus/prometheus
Browse files Browse the repository at this point in the history
  • Loading branch information
fabxc committed Sep 17, 2015
2 parents 568c2c4 + 704d723 commit fd26b5b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 3 additions & 1 deletion web/api/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/prometheus/prometheus/promql"
"github.com/prometheus/prometheus/storage/local"
"github.com/prometheus/prometheus/storage/metric"
"github.com/prometheus/prometheus/util/httputil"
"github.com/prometheus/prometheus/util/route"
"github.com/prometheus/prometheus/util/strutil"
)
Expand Down Expand Up @@ -79,14 +80,15 @@ func (api *API) Register(r *route.Router) {
}

instr := func(name string, f apiFunc) http.HandlerFunc {
return prometheus.InstrumentHandlerFunc(name, func(w http.ResponseWriter, r *http.Request) {
hf := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
setCORS(w)
if data, err := f(r); err != nil {
respondError(w, err, data)
} else {
respond(w, data)
}
})
return prometheus.InstrumentHandler(name, httputil.CompressionHandler{hf})
}

r.Get("/query", instr("query", api.query))
Expand Down
9 changes: 7 additions & 2 deletions web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
"github.com/prometheus/prometheus/rules"
"github.com/prometheus/prometheus/storage/local"
"github.com/prometheus/prometheus/template"
"github.com/prometheus/prometheus/util/httputil"
"github.com/prometheus/prometheus/util/route"
"github.com/prometheus/prometheus/version"
"github.com/prometheus/prometheus/web/api/legacy"
Expand Down Expand Up @@ -155,8 +156,12 @@ func New(st local.Storage, qe *promql.Engine, rm *rules.Manager, status *Prometh
router = router.WithPrefix(o.ExternalURL.Path)
}

instrf := prometheus.InstrumentHandlerFunc
instrh := prometheus.InstrumentHandler
instrh := func(name string, h http.Handler) http.HandlerFunc {
return prometheus.InstrumentHandler(name, httputil.CompressionHandler{h})
}
instrf := func(name string, f http.HandlerFunc) http.HandlerFunc {
return instrh(name, f)
}

router.Get("/", func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/graph", http.StatusFound)
Expand Down

0 comments on commit fd26b5b

Please sign in to comment.