Repository navigation
fix(chronicle): send UTC timestamps from ingest_log - #230
Open
1AbdullahButt wants to merge 1 commit into
Open
1AbdullahButt wants to merge 1 commit into
1AbdullahButt wants to merge 1 commit into
Conversation
ingest_log built its default log_entry_time and collection_time from datetime.now(), a naive local time, and then formatted it with a literal Z suffix. On machines outside UTC every ingested log was shifted by the local offset. Passing an aware log_entry_time with the default collection_time also raised TypeError when the two were compared. Default to datetime.now(timezone.utc) and normalise both values to UTC before the ordering check and formatting. Naive inputs are still treated as UTC, so explicit naive timestamps are sent unchanged. Fixes google#229
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #229.
ingest_logbuilt its defaultlog_entry_timeandcollection_timefromdatetime.now(), which is naive local time, then formatted them with a literalZ. On any machine outside UTC every log was sent with the wrong time. Passing a timezone-awarelog_entry_timeand leavingcollection_timeat its default also raisedTypeError: can't compare offset-naive and offset-aware datetimes.Change
datetime.now(timezone.utc)._to_utchelper normalises both values before the ordering check and formatting: aware values are converted withastimezone(timezone.utc), and naive values are treated as UTC. That is the same ruleget_alertsuses, so explicit naive timestamps are sent exactly as before.Tests (in
tests/chronicle/test_log_ingest.py)test_ingest_log_default_timestamps_are_utcpatchesdatetimeso the local clock is 8 hours behind UTC, which means it fails on a UTC CI runner too. Before the fix it sends04:00:00Zfor a 12:00 UTC "now".test_ingest_log_aware_timestamp_converted_to_utcpasses a+01:00log_entry_timewith nocollection_time. Before the fix this raisedTypeError; now it sends the UTC value.pytest tests -k "not integration": 690 passed. Black (line length 80) is clean on the changed lines.I left the other modules the issue mentions (
search_udm,get_stats) out of this PR to keep it focused on the default path. I'm happy to send a follow-up if you want them handled the same way.I used Claude Code to help write this fix and the tests, then checked and ran them myself.
🤖 Generated with Claude Code