Skip to content
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

Merged
merged 1 commit into from
Apr 11, 2024
Merged

Conversation

agbpatro
Copy link
Collaborator

@agbpatro agbpatro commented Apr 11, 2024

Description

Please include a summary of the changes and the related issue.

Type of change

Key changes:-

  • Allow a way to suppress the logging messages related to tls handshake error logged here.
  • Remove unused anomaly logger method

Please select all options that apply to this change:

  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Bug fix (non-breaking change which fixes an issue)
  • Documentation update

Checklist:

Confirm you have completed the following steps:

  • My code follows the style of this project.
  • I have performed a self-review of my code.
  • I have made corresponding updates to the documentation.
  • I have added/updated unit tests to cover my changes.
  • I have added/updated integration tests to cover my changes.

@@ -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) {
Copy link
Collaborator Author

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.
Copy link
Collaborator

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, extra E in SUPPRESS)
  • 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
Copy link
Collaborator

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)
Copy link
Collaborator

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)
Copy link
Collaborator

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).

Copy link
Collaborator Author

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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suppressString -> filter, or f

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))
Copy link
Collaborator

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))

})

Context("Tls handshake error", func() {
DescribeTable("supresses",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in suppresses

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))
Copy link
Collaborator

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"),
)
})

Copy link
Collaborator

@vmallet vmallet Apr 11, 2024

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.

@agbpatro agbpatro force-pushed the suppress_tls_handshake_errors branch 5 times, most recently from 31b556d to 49349cc Compare April 11, 2024 20:47
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 {
Copy link
Collaborator

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
@agbpatro agbpatro force-pushed the suppress_tls_handshake_errors branch from 49349cc to 2beea99 Compare April 11, 2024 21:25
@agbpatro agbpatro merged commit 3d53a0a into main Apr 11, 2024
5 checks passed
@agbpatro agbpatro deleted the suppress_tls_handshake_errors branch April 11, 2024 21:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants