From 89f1e7f003902d696cbd6fc38c03017f0fe29f3d Mon Sep 17 00:00:00 2001 From: djshow832 <873581766@qq.com> Date: Wed, 27 Dec 2023 18:15:49 +0800 Subject: [PATCH] add /debug and /metrics --- pkg/server/api/server.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pkg/server/api/server.go b/pkg/server/api/server.go index daae792f..6e5873b1 100644 --- a/pkg/server/api/server.go +++ b/pkg/server/api/server.go @@ -110,6 +110,9 @@ func NewServer(cfg config.API, lg *zap.Logger, h.registerGrpc(engine, cfg, cfgmgr) h.registerAPI(engine.Group("/api"), cfg, nsmgr, cfgmgr) + // The paths are consistent with other components. + h.registerMetrics(engine.Group("metrics")) + h.registerDebug(engine.Group("debug")) if handler != nil { if err := handler.RegisterHTTP(engine); err != nil { @@ -170,11 +173,12 @@ func (h *Server) attachLogger(c *gin.Context) { fields = append(fields, zap.Errors("errs", errs)) } - if len(c.Errors) > 0 { + switch { + case len(c.Errors) > 0: h.lg.Warn(path, fields...) - } else if strings.HasPrefix(path, "/api/debug") || strings.HasPrefix(path, "/api/metrics") { + case strings.Contains(path, "/debug"), strings.Contains(path, "/metrics"): h.lg.Debug(path, fields...) - } else { + default: h.lg.Info(path, fields...) } }