-
Notifications
You must be signed in to change notification settings - Fork 71
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
Add support to suppress tls logging #157
Conversation
@@ -87,13 +121,22 @@ func (l *Logger) Log(logType LogType, message string, info LogInfo) { | |||
} | |||
} | |||
|
|||
// Write implements the Write method of the io.Writer interface | |||
func (l *Logger) Write(p []byte) (n int, err error) { |
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.
README.md
Outdated
@@ -165,6 +165,10 @@ Configure and use Prometheus or a StatsD-interface supporting data store for met | |||
|
|||
![Basic Dashboard](./doc/grafana-dashboard.png) | |||
|
|||
## Logging | |||
|
|||
To supress [tls handshake error logging](https://cs.opensource.google/go/go/+/master:src/net/http/server.go;l=1933?q=%22TLS%20handshake%20error%20from%20%22&ss=go%2Fgo), set environment variable `SUPPRESSE_TLS_HANDSHAKE_ERROR_LOGGING` to true. See [docker compose](./docker-compose.yml) for example. |
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.
- To
suppress
(typo)... SUPPRESS_TLS_HANDSHAKE_ERROR_LOGGING
(typo, extraE
inSUPPRESS
)- Add backticks around
true
maybe?
logger/logger.go
Outdated
@@ -34,29 +40,45 @@ type LogInfo map[string]interface{} | |||
// Logger a logrus implementer of the JSON logger interface | |||
type Logger struct { | |||
logger *logrus.Entry | |||
|
|||
supressionMessages []string |
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.
- typo in
suppression
- How about:
suppressionFilters
maybe?
logger/logger.go
Outdated
return l | ||
value, ok := os.LookupEnv("SUPPRESSE_TLS_HANDSHAKE_ERROR_LOGGING") | ||
if ok { | ||
ok, err := strconv.ParseBool(value) |
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.
How about b
instead of ok
here for the parsed boolean value? ok
carries a slightly different meaning usually.
logger/logger.go
Outdated
return nil, err | ||
} | ||
if ok { | ||
suppressionMessages = append(suppressionMessages, tlsFilter) |
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.
That looks a bit convoluted for something that right now is going to stay with only one filter. Even though the suppressionFilters
in the type is a slice, maybe when you set it up for now you just hardcoded to a slice of just that one filter, and we extend the code the day we actually need it? (just a thought).
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.
updated
logger/logger.go
Outdated
@@ -69,8 +91,20 @@ func SetLogLevel(name string) { | |||
logrus.SetLevel(level) | |||
} | |||
|
|||
func (l *Logger) shouldSuppress(message string) bool { | |||
for _, suppressString := range l.supressionMessages { |
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.
suppressString
-> filter
, or f
logger/logger_logrus_test.go
Outdated
Expect(len(hook.Entries)).To(Equal(4)) | ||
Expect(hook.LastEntry().Level).To(Equal(githubLogrus.ErrorLevel)) | ||
Expect(hook.LastEntry().Message).To(Equal("sample_anomaly_log_2")) | ||
|
||
logger.Log(ERROR, "http: TLS handshake error from 0.0.0.0:1: EOF", nil) | ||
Expect(len(hook.Entries)).To(Equal(5)) |
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.
Expect(hook.Entries).To(HaveLen(5))
logger/logger_logrus_test.go
Outdated
}) | ||
|
||
Context("Tls handshake error", func() { | ||
DescribeTable("supresses", |
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.
Typo in suppresses
logger/logger_logrus_test.go
Outdated
logger.Log(ERROR, "http: TLS handshake error from 0.0.0.0:1: EOF", nil) | ||
Expect(hook.Entries).To(BeEmpty()) | ||
logger.Log(ERROR, "Random error", nil) | ||
Expect(len(hook.Entries)).To(Equal(1)) |
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.
...len
.. -> HaveLen()
Entry("for env variable 1", "1"), | ||
) | ||
}) | ||
|
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.
Maybe add a case where the env var is set to true
and we see it doesn't suppress other messages?
You're already doing this, sorry.
31b556d
to
49349cc
Compare
logger/logger.go
Outdated
@@ -69,8 +89,18 @@ func SetLogLevel(name string) { | |||
logrus.SetLevel(level) | |||
} | |||
|
|||
func (l *Logger) shouldSuppress(message string) bool { | |||
if len(l.suppressionFilter) == 0 { |
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.
nit: usually go does empty string checks against ""
instead of len
, but that's fine too.
- Allow a way to suppress the logging messages related to tls handshake error logged in https://cs.opensource.google/go/go/+/master:src/net/http/server.go;l=1933?q=%22TLS%20handshake%20error%20from%20%22&ss=go%2Fgo. - Remove unused anomaly logger method
49349cc
to
2beea99
Compare
Description
Please include a summary of the changes and the related issue.
Type of change
Key changes:-
Please select all options that apply to this change:
Checklist:
Confirm you have completed the following steps: