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

fix: avoid truncating sessionaction logs #86

Merged
merged 1 commit into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/deadline_worker_agent/log_sync/cloudwatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,8 +635,13 @@ def emit(self, record: LogRecord) -> None:
message = " "
# record.created is expressed in seconds (floating-point) since
# January 1, 1970, 00:00:00 (UTC) but CloudWatch expects an integer value expressed in
# microseconds. Convert to microseconds and round to nearest integer.
timestamp = int(round(record.created * 1000))
# microseconds since utc-epoch.
# Our service uses a SessionAction's startedAt/endedAt times to determine which part of a
# log belongs to that particular SessionAction. So, we need to take some care to ensure that
# the time that we report to CloudWatch is rounded in the same way that the service will round
# the startedAt/endedAt time that it receives. Our service truncates, rather than rounds, times
# to microseconds so we do the same here.
timestamp = int(record.created * 1000)
self._log_event_queue.append(
FormattedLogEntry(
timestamp=timestamp,
Expand Down
4 changes: 2 additions & 2 deletions test/unit/log_sync/test_cloudwatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -1345,7 +1345,7 @@ def test_emit(
# THEN
log_queue_append_mock.assert_called_once_with(
FormattedLogEntry(
timestamp=int(round(record.created * 1000)),
timestamp=int(record.created * 1000),
message=record.message,
)
)
Expand Down Expand Up @@ -1386,7 +1386,7 @@ def test_emit_exception(
# THEN
log_queue_append_mock.assert_called_once_with(
FormattedLogEntry(
timestamp=int(round(record.created * 1000)),
timestamp=int(record.created * 1000),
message=record.message,
)
)
Expand Down