Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mybee
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
mybee
Commits
36b3c5f3
Unverified
Commit
36b3c5f3
authored
May 29, 2020
by
Janoš Guljaš
Committed by
GitHub
May 29, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
suppress log messages for debug api metrics, health and readiness (#239)
parent
a1443489
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
7 deletions
+37
-7
router.go
pkg/debugapi/router.go
+14
-5
http_access.go
pkg/logging/http_access.go
+23
-2
No files found.
pkg/debugapi/router.go
View file @
36b3c5f3
...
...
@@ -21,9 +21,12 @@ import (
func
(
s
*
server
)
setupRouting
()
{
baseRouter
:=
http
.
NewServeMux
()
baseRouter
.
Handle
(
"/metrics"
,
promhttp
.
InstrumentMetricHandler
(
s
.
metricsRegistry
,
promhttp
.
HandlerFor
(
s
.
metricsRegistry
,
promhttp
.
HandlerOpts
{}),
baseRouter
.
Handle
(
"/metrics"
,
web
.
ChainHandlers
(
logging
.
SetAccessLogLevelHandler
(
0
),
// suppress access log messages
web
.
FinalHandler
(
promhttp
.
InstrumentMetricHandler
(
s
.
metricsRegistry
,
promhttp
.
HandlerFor
(
s
.
metricsRegistry
,
promhttp
.
HandlerOpts
{}),
)),
))
router
:=
mux
.
NewRouter
()
...
...
@@ -38,8 +41,14 @@ func (s *server) setupRouting() {
router
.
Handle
(
"/debug/vars"
,
expvar
.
Handler
())
router
.
HandleFunc
(
"/health"
,
s
.
statusHandler
)
router
.
HandleFunc
(
"/readiness"
,
s
.
statusHandler
)
router
.
Handle
(
"/health"
,
web
.
ChainHandlers
(
logging
.
SetAccessLogLevelHandler
(
0
),
// suppress access log messages
web
.
FinalHandlerFunc
(
s
.
statusHandler
),
))
router
.
Handle
(
"/readiness"
,
web
.
ChainHandlers
(
logging
.
SetAccessLogLevelHandler
(
0
),
// suppress access log messages
web
.
FinalHandlerFunc
(
s
.
statusHandler
),
))
router
.
Handle
(
"/addresses"
,
jsonhttp
.
MethodHandler
{
"GET"
:
http
.
HandlerFunc
(
s
.
addressesHandler
),
...
...
pkg/logging/http_access.go
View file @
36b3c5f3
...
...
@@ -12,14 +12,20 @@ import (
"github.com/sirupsen/logrus"
)
// NewHTTPAccessLogHandler creates a handler that will log a message after a
// request has been served.
func
NewHTTPAccessLogHandler
(
logger
Logger
,
level
logrus
.
Level
,
message
string
)
func
(
h
http
.
Handler
)
http
.
Handler
{
return
func
(
h
http
.
Handler
)
http
.
Handler
{
return
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
startTime
:=
time
.
Now
()
rl
:=
&
responseLogger
{
w
,
0
,
0
}
rl
:=
&
responseLogger
{
w
,
0
,
0
,
level
}
h
.
ServeHTTP
(
rl
,
r
)
if
rl
.
level
==
0
{
return
}
status
:=
rl
.
status
if
status
==
0
{
status
=
http
.
StatusOK
...
...
@@ -49,7 +55,21 @@ func NewHTTPAccessLogHandler(logger Logger, level logrus.Level, message string)
if
v
:=
r
.
Header
.
Get
(
"X-Real-Ip"
);
v
!=
""
{
fields
[
"x-real-ip"
]
=
v
}
logger
.
WithFields
(
fields
)
.
Log
(
level
,
message
)
logger
.
WithFields
(
fields
)
.
Log
(
rl
.
level
,
message
)
})
}
}
// SetAccessLogLevelHandler overrides the log level set in
// NewHTTPAccessLogHandler for a specific endpoint. Use log level 0 to suppress
// log messages.
func
SetAccessLogLevelHandler
(
level
logrus
.
Level
)
func
(
h
http
.
Handler
)
http
.
Handler
{
return
func
(
h
http
.
Handler
)
http
.
Handler
{
return
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
if
rl
,
ok
:=
w
.
(
*
responseLogger
);
ok
{
rl
.
level
=
level
}
h
.
ServeHTTP
(
w
,
r
)
})
}
}
...
...
@@ -58,6 +78,7 @@ type responseLogger struct {
w
http
.
ResponseWriter
status
int
size
int
level
logrus
.
Level
}
func
(
l
*
responseLogger
)
Header
()
http
.
Header
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment