Skip logging of health check requests
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Piotr Biernat 2022-12-02 21:53:03 +01:00
parent 32f148ea95
commit 270b07a437
3 changed files with 11 additions and 3 deletions

View File

@ -11,7 +11,7 @@ ARG SVC_NAME
ARG SVC_VER ARG SVC_VER
LABEL dev.egommerce.image.author="Piotr Biernat" 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.service=${SVC_NAME}
LABEL dev.egommerce.image.version=${SVC_VER} LABEL dev.egommerce.image.version=${SVC_VER}

View File

@ -1,17 +1,19 @@
package server package server
import ( import (
"strings"
"git.pbiernat.dev/egommerce/go-api-pkg/fluentd" "git.pbiernat.dev/egommerce/go-api-pkg/fluentd"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
) )
func SetupRoutes(s *Server) { func SetupRoutes(s *Server) {
s.App.Get("/health", s.HealthHandler)
api := s.App.Group("/api") api := s.App.Group("/api")
v1 := api.Group("/v1") v1 := api.Group("/v1")
v1.Post("/product", s.AddProductToBasketHandler) v1.Post("/product", s.AddProductToBasketHandler)
v1.Delete("/product", s.RemoveProductFromBasketHandler) v1.Delete("/product", s.RemoveProductFromBasketHandler)
s.App.Get("/health", s.HealthHandler)
} }
func SetupMiddlewares(s *Server) { func SetupMiddlewares(s *Server) {
@ -21,6 +23,11 @@ func SetupMiddlewares(s *Server) {
// Middlewares // Middlewares
func LoggingMiddleware(log *fluentd.Logger) func(c *fiber.Ctx) error { func LoggingMiddleware(log *fluentd.Logger) func(c *fiber.Ctx) error {
return 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", log.Log("Request: %s, remote: %s, via: %s",
c.Request().URI().String(), c.Request().URI().String(),
c.Context().RemoteIP().String(), c.Context().RemoteIP().String(),

View File

@ -89,6 +89,7 @@ func (s *Server) StartWithGracefulShutdown(forever chan struct{}) {
<-forever <-forever
} }
// GetRequestID Return current requets ID - works only when fiber context are running
func (s *Server) GetRequestID(c *fiber.Ctx) (string, error) { func (s *Server) GetRequestID(c *fiber.Ctx) (string, error) {
var hdr = new(Headers) var hdr = new(Headers)
if err := c.ReqHeaderParser(hdr); err != nil { if err := c.ReqHeaderParser(hdr); err != nil {