-
Notifications
You must be signed in to change notification settings - Fork 214
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
Trims timestamp from log message if customer enables on logs plugin #1568
Conversation
@@ -130,15 +130,34 @@ func TestTimestampParser(t *testing.T) { | |||
expectedTimestamp := time.Unix(1497882318, 0) | |||
timestampString := "19 Jun 2017 14:25:18" | |||
logEntry := fmt.Sprintf("%s [INFO] This is a test message.", timestampString) | |||
timestamp := fileConfig.timestampFromLogLine(logEntry) | |||
timestamp, modifiedLogEntry := fileConfig.timestampFromLogLine(logEntry) |
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: logEntry
is a better name since we don't actually modify the content here
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.
It depends on the TrimTimestamp flag right. so I just kept it generic
return timestamp | ||
if config.TrimTimestamp { | ||
// Trim the entire timestamp portion (from start to end of the match) | ||
return timestamp, logValue[:index[0]] + logValue[index[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.
Can you explain the value of index[0]
[index[1]
? What are they corresponding to?
Reading the if cases above, it seems like the length can vary depending on the regex so want to make sure we are fine with always calling index 0 and 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.
Regex will always write down the index array with index[0] is the start position of the timestamp match
index[1] is the end position of the timestamp match
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.
Should we also trim any leading whitespace after the timestamp trim?
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.
For a point against doing this by default, the OTEL filelog receiver has preserve_(leading|trailing)_whitespace
options in their config.
type TrimTimestamp struct { | ||
} | ||
|
||
func (r *TrimTimestamp) ApplyRule(input interface{}) (returnKey string, returnVal interface{}) { |
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.
Please address lint issues.
return timestamp | ||
if config.TrimTimestamp { | ||
// Trim the entire timestamp portion (from start to end of the match) | ||
return timestamp, logValue[:index[0]] + logValue[index[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.
Should we also trim any leading whitespace after the timestamp trim?
Description of the issue
Describe the problem or feature in addition to a link to the issues.
CWA should be configurable to trim timestamp from the log message before publishing
Description of changes
How does this change address the problem?
Adds a configuration option to the agent to optionally trim the timestamp from the log message before publishing to CWL.
License
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Tests
Describe what tests you have done.
Unit Tests
Manual Test
Config.json
Toml
CloudWatch logs for log group
trim_log_group
and log streamtrim_log_stream
Requirements
Before commit the code, please do the following steps.
make fmt
andmake fmt-sh
make lint