Skip to content

Commit

Permalink
fix(logging): only log GET requests at debug level
Browse files Browse the repository at this point in the history
Signed-off-by: James Munson <james.munson@suse.com>
(cherry picked from commit 58ec538)
  • Loading branch information
james-munson authored and derekbit committed Oct 29, 2024
1 parent f746ae2 commit 4b4717f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 13 deletions.
10 changes: 1 addition & 9 deletions app/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,15 +219,7 @@ func startManager(c *cli.Context) error {

server := api.NewServer(m, wsc)
router := http.Handler(api.NewRouter(server))
router = util.FilteredLoggingHandler(map[string]struct{}{
"/v1/apiversions": {},
"/v1/schemas": {},
"/v1/settings": {},
"/v1/volumes": {},
"/v1/nodes": {},
"/v1/engineimages": {},
"/v1/events": {},
}, os.Stdout, router)
router = util.FilteredLoggingHandler(os.Stdout, router)
router = handlers.ProxyHeaders(router)

listen := types.GetAPIServerAddressFromIP(currentIP)
Expand Down
6 changes: 2 additions & 4 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,15 +456,13 @@ func RunAsync(wg *sync.WaitGroup, f func()) {
}

type filteredLoggingHandler struct {
filteredPaths map[string]struct{}
handler http.Handler
loggingHandler http.Handler
}

func FilteredLoggingHandler(filteredPaths map[string]struct{}, writer io.Writer, router http.Handler) http.Handler {
func FilteredLoggingHandler(writer io.Writer, router http.Handler) http.Handler {

return filteredLoggingHandler{
filteredPaths: filteredPaths,
handler: router,
loggingHandler: handlers.CombinedLoggingHandler(writer, router),
}
Expand All @@ -473,7 +471,7 @@ func FilteredLoggingHandler(filteredPaths map[string]struct{}, writer io.Writer,
func (h filteredLoggingHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
switch req.Method {
case "GET":
if _, exists := h.filteredPaths[req.URL.Path]; exists {
if logrus.GetLevel() < logrus.DebugLevel {
h.handler.ServeHTTP(w, req)
return
}
Expand Down

0 comments on commit 4b4717f

Please sign in to comment.