[#318] Log unmatched requests

Signed-off-by: Denis Kirillov <d.kirillov@yadro.com>
This commit is contained in:
Denis Kirillov 2024-02-21 17:32:58 +03:00
parent 529ec7e0b9
commit 7b86bac6ee
2 changed files with 5 additions and 4 deletions

View file

@ -293,7 +293,7 @@ func determineBucketOperation(r *http.Request) string {
} }
} }
return "" return "UnmatchedBucketOperation"
} }
func determineObjectOperation(r *http.Request) string { func determineObjectOperation(r *http.Request) string {
@ -357,12 +357,12 @@ func determineObjectOperation(r *http.Request) string {
} }
} }
return "" return "UnmatchedObjectOperation"
} }
func determineGeneralOperation(r *http.Request) string { func determineGeneralOperation(r *http.Request) string {
if r.Method == http.MethodGet { if r.Method == http.MethodGet {
return ListBucketsOperation return ListBucketsOperation
} }
return "" return "UnmatchedOperation"
} }

View file

@ -148,6 +148,7 @@ func NewRouter(cfg Config) *chi.Mux {
defaultRouter := chi.NewRouter() defaultRouter := chi.NewRouter()
defaultRouter.Mount(fmt.Sprintf("/{%s}", s3middleware.BucketURLPrm), bucketRouter(cfg.Handler, cfg.Log)) defaultRouter.Mount(fmt.Sprintf("/{%s}", s3middleware.BucketURLPrm), bucketRouter(cfg.Handler, cfg.Log))
defaultRouter.Get("/", named("ListBuckets", cfg.Handler.ListBucketsHandler)) defaultRouter.Get("/", named("ListBuckets", cfg.Handler.ListBucketsHandler))
attachErrorHandler(defaultRouter)
hr := NewHostBucketRouter("bucket") hr := NewHostBucketRouter("bucket")
hr.Default(defaultRouter) hr.Default(defaultRouter)
@ -182,7 +183,7 @@ func errorResponseHandler(w http.ResponseWriter, r *http.Request) {
}) })
if log := s3middleware.GetReqLog(ctx); log != nil { if log := s3middleware.GetReqLog(ctx); log != nil {
log.Error(logs.RequestUnmatched, zap.String("method", reqInfo.API)) log.Error(logs.RequestUnmatched, zap.String("method", reqInfo.API), zap.String("http method", r.Method), zap.String("url", r.RequestURI))
} }
} }