Skip to content

fix(chronicle): send UTC timestamps from ingest_log - #230

Open
1AbdullahButt wants to merge 1 commit into
google:mainfrom
1AbdullahButt:fix/ingest-log-utc-timestamps
Open

1AbdullahButt wants to merge 1 commit into
google:mainfrom
1AbdullahButt:fix/ingest-log-utc-timestamps

Conversation

@1AbdullahButt

Copy link
Copy Markdown

Fixes #229.

ingest_log built its default log_entry_time and collection_time from datetime.now(), which is naive local time, then formatted them with a literal Z. On any machine outside UTC every log was sent with the wrong time. Passing a timezone-aware log_entry_time and leaving collection_time at its default also raised TypeError: can't compare offset-naive and offset-aware datetimes.

Change

  • Defaults now come from datetime.now(timezone.utc).
  • A small _to_utc helper normalises both values before the ordering check and formatting: aware values are converted with astimezone(timezone.utc), and naive values are treated as UTC. That is the same rule get_alerts uses, so explicit naive timestamps are sent exactly as before.

Tests (in tests/chronicle/test_log_ingest.py)

  • test_ingest_log_default_timestamps_are_utc patches datetime so the local clock is 8 hours behind UTC, which means it fails on a UTC CI runner too. Before the fix it sends 04:00:00Z for a 12:00 UTC "now".
  • test_ingest_log_aware_timestamp_converted_to_utc passes a +01:00 log_entry_time with no collection_time. Before the fix this raised TypeError; 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

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

No deployments
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.

ingest_log sends local wall-clock time labelled as UTC by default, and raises TypeError for timezone-aware log_entry_time

1 participant