From 270b07a43786e57ad14622d8ad540daf29e2f3e1 Mon Sep 17 00:00:00 2001 From: Piotr Biernat Date: Fri, 2 Dec 2022 21:53:03 +0100 Subject: [PATCH] Skip logging of health check requests --- Dockerfile.target | 2 +- src/internal/app/server/router.go | 11 +++++++++-- src/internal/app/server/server.go | 1 + 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Dockerfile.target b/Dockerfile.target index b822ac9..665cb28 100644 --- a/Dockerfile.target +++ b/Dockerfile.target @@ -11,7 +11,7 @@ ARG SVC_NAME ARG SVC_VER LABEL dev.egommerce.image.author="Piotr Biernat" -LABEL dev.egommerce.image.service="api-eventubus" +LABEL dev.egommerce.image.vendor="Egommerce" LABEL dev.egommerce.image.service=${SVC_NAME} LABEL dev.egommerce.image.version=${SVC_VER} diff --git a/src/internal/app/server/router.go b/src/internal/app/server/router.go index 28b7ff6..a83fffd 100644 --- a/src/internal/app/server/router.go +++ b/src/internal/app/server/router.go @@ -1,17 +1,19 @@ package server import ( + "strings" + "git.pbiernat.dev/egommerce/go-api-pkg/fluentd" "github.com/gofiber/fiber/v2" ) func SetupRoutes(s *Server) { + s.App.Get("/health", s.HealthHandler) + api := s.App.Group("/api") v1 := api.Group("/v1") v1.Post("/product", s.AddProductToBasketHandler) v1.Delete("/product", s.RemoveProductFromBasketHandler) - - s.App.Get("/health", s.HealthHandler) } func SetupMiddlewares(s *Server) { @@ -21,6 +23,11 @@ func SetupMiddlewares(s *Server) { // Middlewares func LoggingMiddleware(log *fluentd.Logger) func(c *fiber.Ctx) error { return func(c *fiber.Ctx) error { + path := string(c.Request().URI().Path()) + if strings.Contains(path, "/health") { + return c.Next() + } + log.Log("Request: %s, remote: %s, via: %s", c.Request().URI().String(), c.Context().RemoteIP().String(), diff --git a/src/internal/app/server/server.go b/src/internal/app/server/server.go index 3084073..c46640b 100644 --- a/src/internal/app/server/server.go +++ b/src/internal/app/server/server.go @@ -89,6 +89,7 @@ func (s *Server) StartWithGracefulShutdown(forever chan struct{}) { <-forever } +// GetRequestID Return current requets ID - works only when fiber context are running func (s *Server) GetRequestID(c *fiber.Ctx) (string, error) { var hdr = new(Headers) if err := c.ReqHeaderParser(hdr); err != nil {