forked from TrueCloudLab/frostfs-s3-gw
Move metrics, pprof and healthy routes to /system subrouter
This commit is contained in:
parent
151c3c672a
commit
48d8138474
6 changed files with 59 additions and 30 deletions
|
@ -17,12 +17,16 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
func attachHealthy(r *mux.Router, h Healthy) {
|
func attachHealthy(r *mux.Router, h Healthy) {
|
||||||
r.HandleFunc("/-/ready", func(w http.ResponseWriter, r *http.Request) {
|
healthy := r.PathPrefix(systemPath + "/-").
|
||||||
|
Subrouter().
|
||||||
|
StrictSlash(true)
|
||||||
|
|
||||||
|
healthy.HandleFunc("/ready", func(w http.ResponseWriter, r *http.Request) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
_, _ = fmt.Fprintln(w, healthyState+"ready")
|
_, _ = fmt.Fprintln(w, healthyState+"ready")
|
||||||
})
|
})
|
||||||
|
|
||||||
r.HandleFunc("/-/healthy", func(w http.ResponseWriter, r *http.Request) {
|
healthy.HandleFunc("/healthy", func(w http.ResponseWriter, r *http.Request) {
|
||||||
code := http.StatusOK
|
code := http.StatusOK
|
||||||
msg := "healthy"
|
msg := "healthy"
|
||||||
|
|
||||||
|
|
|
@ -7,11 +7,14 @@ import (
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
func attachMetrics(v *viper.Viper, l *zap.Logger, r *mux.Router) {
|
func attachMetrics(r *mux.Router, v *viper.Viper, l *zap.Logger) {
|
||||||
if !v.GetBool(cfgEnableMetrics) {
|
if !v.GetBool(cfgEnableMetrics) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l.Info("enable metrics")
|
l.Info("enable metrics")
|
||||||
r.Handle("/metrics", promhttp.Handler())
|
r.PathPrefix(systemPath+"/metrics").
|
||||||
|
Subrouter().
|
||||||
|
StrictSlash(true).
|
||||||
|
Handle("", promhttp.Handler())
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,16 +8,25 @@ import (
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
func attachProfiler(v *viper.Viper, l *zap.Logger, r *mux.Router) {
|
func attachProfiler(r *mux.Router, v *viper.Viper, l *zap.Logger) {
|
||||||
if !v.GetBool(cfgEnableProfiler) {
|
if !v.GetBool(cfgEnableProfiler) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l.Info("enable profiler")
|
l.Info("enable profiler")
|
||||||
|
|
||||||
r.HandleFunc("/debug/pprof/", pprof.Index)
|
profiler := r.PathPrefix(systemPath + "/debug/pprof").
|
||||||
r.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
|
Subrouter().
|
||||||
r.HandleFunc("/debug/pprof/profile", pprof.Profile)
|
StrictSlash(true)
|
||||||
r.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
|
|
||||||
r.HandleFunc("/debug/pprof/trace", pprof.Trace)
|
profiler.HandleFunc("/", pprof.Index)
|
||||||
|
profiler.HandleFunc("/cmdline", pprof.Cmdline)
|
||||||
|
profiler.HandleFunc("/profile", pprof.Profile)
|
||||||
|
profiler.HandleFunc("/symbol", pprof.Symbol)
|
||||||
|
profiler.HandleFunc("/trace", pprof.Trace)
|
||||||
|
|
||||||
|
// Manually add support for paths linked to by index page at /debug/pprof/
|
||||||
|
for _, item := range []string{"allocs", "block", "heap", "goroutine", "mutex", "threadcreate"} {
|
||||||
|
profiler.Handle("/"+item, pprof.Handler(item))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
|
||||||
minio "github.com/minio/minio/legacy"
|
minio "github.com/minio/minio/legacy"
|
||||||
"github.com/minio/minio/neofs/layer"
|
"github.com/minio/minio/neofs/layer"
|
||||||
"github.com/minio/minio/neofs/pool"
|
"github.com/minio/minio/neofs/pool"
|
||||||
|
@ -22,7 +21,6 @@ type (
|
||||||
App struct {
|
App struct {
|
||||||
cli pool.Pool
|
cli pool.Pool
|
||||||
log *zap.Logger
|
log *zap.Logger
|
||||||
web *mux.Router
|
|
||||||
cfg *viper.Viper
|
cfg *viper.Viper
|
||||||
obj minio.ObjectLayer
|
obj minio.ObjectLayer
|
||||||
|
|
||||||
|
@ -108,19 +106,21 @@ func newApp(l *zap.Logger, v *viper.Viper) *App {
|
||||||
zap.Error(err))
|
zap.Error(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
l.Info("credentials",
|
||||||
|
zap.String("AccessKey", uid.String()),
|
||||||
|
zap.String("SecretKey", wif))
|
||||||
|
|
||||||
if obj, err = layer.NewLayer(cli, auth.Credentials{AccessKey: uid.String(), SecretKey: wif}); err != nil {
|
if obj, err = layer.NewLayer(cli, auth.Credentials{AccessKey: uid.String(), SecretKey: wif}); err != nil {
|
||||||
l.Fatal("could not prepare ObjectLayer",
|
l.Fatal("could not prepare ObjectLayer",
|
||||||
zap.Error(err))
|
zap.Error(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = obj
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return &App{
|
return &App{
|
||||||
cli: cli,
|
cli: cli,
|
||||||
log: l,
|
log: l,
|
||||||
cfg: v,
|
cfg: v,
|
||||||
web: minio.NewRouter(obj),
|
obj: obj,
|
||||||
|
|
||||||
webDone: make(chan struct{}, 1),
|
webDone: make(chan struct{}, 1),
|
||||||
wrkDone: make(chan struct{}, 1),
|
wrkDone: make(chan struct{}, 1),
|
||||||
|
@ -150,7 +150,7 @@ func (a *App) Server(ctx context.Context) {
|
||||||
err error
|
err error
|
||||||
lis net.Listener
|
lis net.Listener
|
||||||
lic net.ListenConfig
|
lic net.ListenConfig
|
||||||
srv = http.Server{Handler: a.web}
|
srv = new(http.Server)
|
||||||
addr = a.cfg.GetString(cfgListenAddress)
|
addr = a.cfg.GetString(cfgListenAddress)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -159,10 +159,18 @@ func (a *App) Server(ctx context.Context) {
|
||||||
zap.Error(err))
|
zap.Error(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
router := newS3Router()
|
||||||
|
|
||||||
// Attach app-specific routes:
|
// Attach app-specific routes:
|
||||||
attachHealthy(a.web, a.cli)
|
attachHealthy(router, a.cli)
|
||||||
attachMetrics(a.cfg, a.log, a.web)
|
attachMetrics(router, a.cfg, a.log)
|
||||||
attachProfiler(a.cfg, a.log, a.web)
|
attachProfiler(router, a.cfg, a.log)
|
||||||
|
|
||||||
|
// Attach S3 API:
|
||||||
|
minio.AttachS3API(router, a.obj)
|
||||||
|
|
||||||
|
// Use mux.Router as http.Handler
|
||||||
|
srv.Handler = router
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
a.log.Info("starting server",
|
a.log.Info("starting server",
|
||||||
|
|
12
cmd/gate/app_router.go
Normal file
12
cmd/gate/app_router.go
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import "github.com/gorilla/mux"
|
||||||
|
|
||||||
|
const systemPath = "/system"
|
||||||
|
|
||||||
|
func newS3Router() *mux.Router {
|
||||||
|
// Initialize router. `SkipClean(true)` stops gorilla/mux from
|
||||||
|
// normalizing URL path minio/minio#3256
|
||||||
|
// avoid URL path encoding minio/minio#8950
|
||||||
|
return mux.NewRouter().SkipClean(true).UseEncodedPath()
|
||||||
|
}
|
|
@ -4,20 +4,15 @@ import (
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewRouter(obj ObjectLayer) *mux.Router {
|
func AttachS3API(r *mux.Router, obj ObjectLayer) {
|
||||||
// Initialize router. `SkipClean(true)` stops gorilla/mux from
|
|
||||||
// normalizing URL path minio/minio#3256
|
|
||||||
// avoid URL path encoding minio/minio#8950
|
|
||||||
router := mux.NewRouter().SkipClean(true).UseEncodedPath()
|
|
||||||
|
|
||||||
// Add healthcheck router
|
// Add healthcheck router
|
||||||
registerHealthCheckRouter(router)
|
registerHealthCheckRouter(r)
|
||||||
|
|
||||||
// Add server metrics router
|
// Add server metrics router
|
||||||
registerMetricsRouter(router)
|
registerMetricsRouter(r)
|
||||||
|
|
||||||
// Add API router.
|
// Add API router.
|
||||||
registerAPIRouter(router, true, true)
|
registerAPIRouter(r, true, true)
|
||||||
|
|
||||||
layer := NewGatewayLayerWithLocker(obj)
|
layer := NewGatewayLayerWithLocker(obj)
|
||||||
|
|
||||||
|
@ -39,6 +34,4 @@ func NewRouter(obj ObjectLayer) *mux.Router {
|
||||||
globalObjLayerMutex.Lock()
|
globalObjLayerMutex.Lock()
|
||||||
globalSafeMode = false
|
globalSafeMode = false
|
||||||
globalObjLayerMutex.Unlock()
|
globalObjLayerMutex.Unlock()
|
||||||
|
|
||||||
return router
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue