return /metrics before session middleware

This commit is contained in:
bergquist
2017-09-06 22:24:10 +02:00
committed by Carl Bergquist
parent 6b1ae1a8a8
commit 6d22a67a30
6 changed files with 223 additions and 10 deletions

View File

@@ -6,7 +6,6 @@ import (
"github.com/grafana/grafana/pkg/api/dtos"
"github.com/grafana/grafana/pkg/middleware"
m "github.com/grafana/grafana/pkg/models"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
// Register adds http routes
@@ -98,8 +97,6 @@ func (hs *HttpServer) registerRoutes() {
// api renew session based on remember cookie
r.Get("/api/login/ping", quota("session"), LoginApiPing)
r.Get("/metrics", promhttp.Handler())
// authed api
r.Group("/api", func() {
@@ -266,9 +263,6 @@ func (hs *HttpServer) registerRoutes() {
r.Get("/tsdb/testdata/gensql", reqGrafanaAdmin, wrap(GenerateSqlTestData))
r.Get("/tsdb/testdata/random-walk", wrap(GetTestDataRandomWalk))
// metrics
//r.Get("/metrics", wrap(GetInternalMetrics))
r.Group("/alerts", func() {
r.Post("/test", bind(dtos.AlertTestCommand{}), wrap(AlertTest))
r.Post("/:alertId/pause", bind(dtos.PauseAlertCommand{}), wrap(PauseAlert), reqEditorRole)

View File

@@ -11,6 +11,8 @@ import (
"path"
"time"
"github.com/prometheus/client_golang/prometheus/promhttp"
gocache "github.com/patrickmn/go-cache"
macaron "gopkg.in/macaron.v1"
@@ -165,6 +167,7 @@ func (hs *HttpServer) newMacaron() *macaron.Macaron {
}))
m.Use(hs.healthHandler)
m.Use(hs.metricsEndpoint)
m.Use(middleware.GetContextHandler())
m.Use(middleware.Sessioner(&setting.SessionOptions))
m.Use(middleware.RequestMetrics())
@@ -180,6 +183,14 @@ func (hs *HttpServer) newMacaron() *macaron.Macaron {
return m
}
func (hs *HttpServer) metricsEndpoint(ctx *macaron.Context) {
if ctx.Req.Method != "GET" || ctx.Req.URL.Path != "/metrics" {
return
}
promhttp.Handler().ServeHTTP(ctx.Resp, ctx.Req.Request)
}
func (hs *HttpServer) healthHandler(ctx *macaron.Context) {
if ctx.Req.Method != "GET" || ctx.Req.URL.Path != "/api/health" {
return