[DSET-4071] [DSET-4007] Fix timestamp handling for LogRecord objects without a timestamp #2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This pull request updates the code to make sure addEvents Event object always has a valid timestamp set.
In addition to that, I removed redundant and unnecessary
timestamp
field from the event attributes. This field is already set as part of the mainevent.ts
field and storing it also as part of the event attributes is causing various issues on the server side.Background, Context
While working on a benchmarking task, I noticed that sometimes
LogRecord
objects have timestamp set to the beginning of the unix epoch (January 1970).After digging in, I saw this could happen in various scenarios since it's a default value in case timestamp is not set / available - e.g. if we use
filelog
receiver and timestamp is not explicitly parsed from the log line (if available on the line at all) as part of the filelog parser operator.This is problematic and it means those events won't get ingested / handled correctly on DataSet side since they have timestamp set to a very long time ago.
Proposed Solution / Fix
To solve this problem, I set event timestamp to the
ObservedTimestamp
in case timestamp is not set / available on theLogRecord
object.ObservedTimestamp
holds the timestamp when the collector observed the event (e.g. when the line was read from file or similar). It should always be set, but to be extra safe / as a fallback, I set event timestamp to current time in case neitherLogRecord.Timestamp
norLogRecord.ObservedTimestamp
is available.