Skip to content

Commit

Permalink
add health check
Browse files Browse the repository at this point in the history
  • Loading branch information
mylxsw committed Jul 16, 2020
1 parent 6582c51 commit 7784b04
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 10 deletions.
6 changes: 6 additions & 0 deletions agent/api/provider.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package api

import (
"github.com/gorilla/mux"
"github.com/mylxsw/asteria/log"
"github.com/mylxsw/container"
"github.com/mylxsw/glacier"
"github.com/mylxsw/glacier/web"
"github.com/prometheus/client_golang/prometheus/promhttp"
)

type ServiceProvider struct{}
Expand All @@ -13,6 +15,10 @@ func (s ServiceProvider) Register(app container.Container) {}

func (s ServiceProvider) Boot(app glacier.Glacier) {
app.WebAppRouter(routers(app.Container()))
app.WebAppMuxRouter(func(router *mux.Router) {
// prometheus metrics
router.PathPrefix("/metrics").Handler(promhttp.Handler())
})
}

func routers(cc container.Container) func(router *web.Router, mw web.RequestMiddleware) {
Expand Down
13 changes: 13 additions & 0 deletions api/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
_ "github.com/mylxsw/adanos-alert/docs"
"github.com/mylxsw/container"
"github.com/mylxsw/glacier"
"github.com/prometheus/client_golang/prometheus/promhttp"
httpSwagger "github.com/swaggo/http-swagger"
)

Expand All @@ -34,8 +35,20 @@ func (s ServiceProvider) Boot(app glacier.Glacier) {
app.WebAppMuxRouter(func(router *mux.Router) {
// Swagger doc
router.PathPrefix("/swagger/").Handler(httpSwagger.WrapHandler).Name("swagger")
// prometheus metrics
router.PathPrefix("/metrics").Handler(promhttp.Handler())
// health check
router.PathPrefix("/health").Handler(HealthCheck{})
// Dashboard
router.PathPrefix("/").Handler(http.StripPrefix("/", http.FileServer(FS(conf.UseLocalDashboard)))).Name("assets")
})
})
}

type HealthCheck struct{}

func (h HealthCheck) ServeHTTP(writer http.ResponseWriter, request *http.Request) {
writer.Header().Add("Content-Type", "application/json")
writer.WriteHeader(http.StatusOK)
_, _ = writer.Write([]byte(`{"status": "UP"}`))
}
16 changes: 8 additions & 8 deletions api/static.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/buger/jsonparser v1.0.0
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
github.com/go-chi/chi v3.3.2+incompatible // indirect
github.com/golang/protobuf v1.4.0
github.com/golang/protobuf v1.4.2
github.com/golang/snappy v0.0.1 // indirect
github.com/gorilla/mux v1.7.4
github.com/gorilla/websocket v1.4.2 // indirect
Expand All @@ -23,6 +23,7 @@ require (
github.com/mylxsw/go-toolkit v0.0.0-20191208081907-50a06279f988
github.com/mylxsw/graceful v0.0.0-20200605063420-3c53968cf134
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.7.1
github.com/robfig/cron/v3 v3.0.1 // indirect
github.com/satori/go.uuid v1.2.0
github.com/siddontang/go v0.0.0-20170517070808-cb568a3e5cc0
Expand All @@ -41,6 +42,6 @@ require (
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e // indirect
golang.org/x/tools v0.0.0-20191007185444-6536af71d98a // indirect
google.golang.org/grpc v1.28.1
google.golang.org/protobuf v1.21.0
google.golang.org/protobuf v1.23.0
gopkg.in/yaml.v2 v2.3.0 // indirect
)
Loading

0 comments on commit 7784b04

Please sign in to comment.