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

[DSET-4071] [DSET-4007] Fix timestamp handling for LogRecord objects without a timestamp #2

Merged

Conversation

tomaz-s1
Copy link
Collaborator

@tomaz-s1 tomaz-s1 commented Jun 8, 2023

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 main event.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 the LogRecord 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 neither LogRecord.Timestamp nor LogRecord.ObservedTimestamp is available.

observed timetamp in case LogRecord doesn't contain timestamp.

Even though ObservedTimestamp should always be present, we fall back to
current time in case it's not.

In addition to that, remove duplicate and redundant "timestamp"
attribute from the AddEvents event.
@@ -229,6 +228,65 @@ func TestBuildEventFromLog(t *testing.T) {
assert.Equal(t, expected, was)
}

func TestBuildEventFromLogEventWithoutTimestampWithObservedTimestampUseObservedTimestamp(t *testing.T) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ideally we structure our tests in GIVEN, WHEN and THEN section to increase readability

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm fine with it as long as it's consistent across the board (and also in line with go conventions / best practices) :)

@tomaz-s1
Copy link
Collaborator Author

tomaz-s1 commented Jun 9, 2023

Build failures seem to be related to other exporters and not ours, so I will ignore them.

@tomaz-s1 tomaz-s1 merged commit b9c138f into datasetexporter-latest Jun 9, 2023
@tomaz-s1 tomaz-s1 deleted the event_no_timestamp_fix_use_occurence_time branch June 9, 2023 11:47
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.

2 participants