-
Notifications
You must be signed in to change notification settings - Fork 32
Add log type include filter #714
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: main
Are you sure you want to change the base?
Conversation
43b0941 to
9fcc372
Compare
9fcc372 to
bccd92c
Compare
chombium
left a comment
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.
@jorbaum Thanks for the changes.
Generally it looks good, but I have some smaller objections which should be addressed.
| DrainData DrainData `json:"type,omitempty"` | ||
| OmitMetadata bool | ||
| InternalTls bool | ||
| LogFilter *LogTypeSet |
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.
I don't think that this has to be a pointer.
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.
I tried that at first, but in manager.go line 45 Binding is used as a map key:
sourceDrainMap map[string]map[syslog.Binding]drainHolder
My understanding is that maps in Go are not comparable, so adding LogTypeSet (which is a map[LogType]struct{}) to the Binding struct makes it non-comparable.
AFAICS the alternative to using a pointer would be to implement a custom comparable key for the map, but using a pointer seemed simpler to me.
| default: | ||
| // Unknown log type, skip it | ||
| // TODO add unit test for unknown log type | ||
| d.log.Printf("Unknown log type '%s' in log type filter, ignoring", logType) |
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.
If there is a log message here and an app owner wrongly configures the drain, than for every app instance and every app log, a log ,message will be written.
The filter settings should be validated upfront and we should not end up in this situation. At this point we should only have valid drain configuration.
I guess we have to bring in #633 first and than this change.
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.
My understanding is that this code does not run for every log message, but only parsing the syslog drain config. I intentionally left logging out of filtering_drain_writer.go to avoid creating a log for each app log.
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.
After discussing with @chombium we concluded that yhis log gets created for each wrongly configured value in the log types of each syslog drain. This is emitted every few seconds on each VM within cloud foundry. While this is better than for each log line, we would still keep log load at a minimum.
To address this I now made sure to log at most one log line in this method.
| set := make(syslog.LogTypeSet, len(logTypes)) | ||
|
|
||
| for _, logType := range logTypes { | ||
| logType = strings.ToLower(strings.TrimSpace(logType)) |
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.
The query string in the URL is case sensitive. We should only accept lowercase and not convert eVerY POssibLE string to lower case.
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.
Did so.
Still, I wonder if we should be strict here about this. Not caring about casing might bring us some benefits as this might be something that users accidentally misconfigure. It should not hurt much to support both I think.
|
@chombium I left a bunch of replies for points that are not yet clear to me. All the rest look good. Thanks for the thorough review! You found a bunch of nice things. |
jorbaum
left a comment
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.
Worked in some comments.
| set := make(syslog.LogTypeSet, len(logTypes)) | ||
|
|
||
| for _, logType := range logTypes { | ||
| logType = strings.ToLower(strings.TrimSpace(logType)) |
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.
Did so.
Still, I wonder if we should be strict here about this. Not caring about casing might bring us some benefits as this might be something that users accidentally misconfigure. It should not hurt much to support both I think.
jorbaum
left a comment
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.
Worked in most comments. Still 2 left to clarify.
| default: | ||
| // Unknown log type, skip it | ||
| // TODO add unit test for unknown log type | ||
| d.log.Printf("Unknown log type '%s' in log type filter, ignoring", logType) |
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.
After discussing with @chombium we concluded that yhis log gets created for each wrongly configured value in the log types of each syslog drain. This is emitted every few seconds on each VM within cloud foundry. While this is better than for each log line, we would still keep log load at a minimum.
To address this I now made sure to log at most one log line in this method.
|
Feel free to take another look at it. |
Description
Addresses #711 :
?include-log-types=and?exclude-log-typesI still need to verify this, but I think a feature flag is not necessary as I tried to make string parsing more efficient by:
strings.IndexBytemight take some time, but it is used only with a single char/andstrings.IndexByte()should be more efficient thanstrings.Index()logTypePrefixesrather than in each log line, which should be more efficientUse both include and exclude log filter
Type of change
Testing performed?
Checklist:
mainbranch, or relevant version branch