mirror of
https://github.com/grafana/grafana.git
synced 2025-08-01 13:22:21 +08:00
healthchecks should work regardless domain (#27981)
This commit is contained in:
@ -436,9 +436,5 @@ func (hs *HTTPServer) registerRoutes() {
|
|||||||
r.Get("/api/snapshots-delete/:deleteKey", reqSnapshotPublicModeOrSignedIn, Wrap(DeleteDashboardSnapshotByDeleteKey))
|
r.Get("/api/snapshots-delete/:deleteKey", reqSnapshotPublicModeOrSignedIn, Wrap(DeleteDashboardSnapshotByDeleteKey))
|
||||||
r.Delete("/api/snapshots/:key", reqEditorRole, Wrap(DeleteDashboardSnapshot))
|
r.Delete("/api/snapshots/:key", reqEditorRole, Wrap(DeleteDashboardSnapshot))
|
||||||
|
|
||||||
// Health check
|
|
||||||
r.Get("/api/health", hs.apiHealthHandler)
|
|
||||||
r.Get("/healthz", hs.healthzHandler)
|
|
||||||
|
|
||||||
r.Get("/*", reqSignedIn, hs.Index)
|
r.Get("/*", reqSignedIn, hs.Index)
|
||||||
}
|
}
|
||||||
|
@ -332,7 +332,12 @@ func (hs *HTTPServer) addMiddlewaresAndStaticRoutes() {
|
|||||||
Delims: macaron.Delims{Left: "[[", Right: "]]"},
|
Delims: macaron.Delims{Left: "[[", Right: "]]"},
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
// These endpoints are used for monitoring the Grafana instance
|
||||||
|
// and should not be redirect or rejected.
|
||||||
|
m.Use(hs.healthzHandler)
|
||||||
|
m.Use(hs.apiHealthHandler)
|
||||||
m.Use(hs.metricsEndpoint)
|
m.Use(hs.metricsEndpoint)
|
||||||
|
|
||||||
m.Use(middleware.GetContextHandler(
|
m.Use(middleware.GetContextHandler(
|
||||||
hs.AuthTokenService,
|
hs.AuthTokenService,
|
||||||
hs.RemoteCacheService,
|
hs.RemoteCacheService,
|
||||||
@ -373,6 +378,11 @@ func (hs *HTTPServer) metricsEndpoint(ctx *macaron.Context) {
|
|||||||
|
|
||||||
// healthzHandler always return 200 - Ok if Grafana's web server is running
|
// healthzHandler always return 200 - Ok if Grafana's web server is running
|
||||||
func (hs *HTTPServer) healthzHandler(ctx *macaron.Context) {
|
func (hs *HTTPServer) healthzHandler(ctx *macaron.Context) {
|
||||||
|
notHeadOrGet := ctx.Req.Method != http.MethodGet && ctx.Req.Method != http.MethodHead
|
||||||
|
if notHeadOrGet || ctx.Req.URL.Path != "/healthz" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
ctx.WriteHeader(200)
|
ctx.WriteHeader(200)
|
||||||
_, err := ctx.Resp.Write([]byte("Ok"))
|
_, err := ctx.Resp.Write([]byte("Ok"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -384,6 +394,11 @@ func (hs *HTTPServer) healthzHandler(ctx *macaron.Context) {
|
|||||||
// can access the database. If the database cannot be access it will return
|
// can access the database. If the database cannot be access it will return
|
||||||
// http status code 503.
|
// http status code 503.
|
||||||
func (hs *HTTPServer) apiHealthHandler(ctx *macaron.Context) {
|
func (hs *HTTPServer) apiHealthHandler(ctx *macaron.Context) {
|
||||||
|
notHeadOrGet := ctx.Req.Method != http.MethodGet && ctx.Req.Method != http.MethodHead
|
||||||
|
if notHeadOrGet || ctx.Req.URL.Path != "/api/health" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
data := simplejson.New()
|
data := simplejson.New()
|
||||||
data.Set("database", "ok")
|
data.Set("database", "ok")
|
||||||
if !hs.Cfg.AnonymousHideVersion {
|
if !hs.Cfg.AnonymousHideVersion {
|
||||||
|
Reference in New Issue
Block a user