-
Notifications
You must be signed in to change notification settings - Fork 1.6k
En/1672 disable health check log #1686
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: development
Are you sure you want to change the base?
Changes from all commits
ce69d1c
6b6dfd5
c3dbd29
f0a57db
8b89261
3e26b03
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -9,6 +9,8 @@ import ( | |||||||||
"gofr.dev/pkg/gofr/config" | ||||||||||
) | ||||||||||
|
||||||||||
const LogDisableProbeKey = "LOG_DISABLE_PROBES" | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The constant should have a clear comment about its purpose Or simpl prefix it with EnvVar
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this one need to be exported ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If followed this suggestion, then yes There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would have used
Suggested change
Or something like that. Maybe there are other env variables about disabling something |
||||||||||
|
||||||||||
func GetConfigs(c config.Config) map[string]string { | ||||||||||
middlewareConfigs := make(map[string]string) | ||||||||||
|
||||||||||
|
@@ -26,6 +28,10 @@ func GetConfigs(c config.Config) map[string]string { | |||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
if val := strings.TrimSpace(c.Get(LogDisableProbeKey)); val != "" { | ||||||||||
middlewareConfigs[LogDisableProbeKey] = val | ||||||||||
} | ||||||||||
|
||||||||||
return middlewareConfigs | ||||||||||
} | ||||||||||
|
||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ import ( | |
"fmt" | ||
"net/http" | ||
"os" | ||
"strconv" | ||
"time" | ||
|
||
"gofr.dev/pkg/gofr/container" | ||
|
@@ -33,9 +34,15 @@ func newHTTPServer(c *container.Container, port int, middlewareConfigs map[strin | |
r := gofrHTTP.NewRouter() | ||
wsManager := websocket.New() | ||
|
||
r.Use(middleware.Tracer) | ||
|
||
if ok, _ := strconv.ParseBool(middlewareConfigs[middleware.LogDisableProbeKey]); !ok { | ||
r.Use(middleware.Logging(c.Logger)) | ||
} else { | ||
r.Use(middleware.LoggingSkipHealthCheck(c.Logger)) | ||
} | ||
Comment on lines
+39
to
+43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code looks strange to me I mean, why having two middlewares? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True. Same middleware behaviour should be changed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, so changing how that logging middleware works now would mean we'd have to toss in a flag as an argument, and since that Logging function is out there for everyone, that'd be a big ol' breaking change. So, wouldn't it make more sense to just spin up a separate logging middleware and then just kinda decide whether to use it or not when we're setting up the server, based on that flag? |
||
|
||
r.Use( | ||
middleware.Tracer, | ||
middleware.Logging(c.Logger), | ||
middleware.CORS(middlewareConfigs, r.RegisteredRoutes), | ||
middleware.Metrics(c.Metrics()), | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should use the constant you define in the other file