Skip to content

fix: Update time handling to use TimeUtil for current time retrieval#1199

Merged
alfredyu-cienet merged 1 commit intoGoogleCloudPlatform:masterfrom
CIeNET-International:tpu-obs/release/pr-220
Mar 2, 2026
Merged

fix: Update time handling to use TimeUtil for current time retrieval#1199
alfredyu-cienet merged 1 commit intoGoogleCloudPlatform:masterfrom
CIeNET-International:tpu-obs/release/pr-220

Conversation

@Chrisliao0806
Copy link
Contributor

@Chrisliao0806 Chrisliao0806 commented Mar 2, 2026

Description

This PR standardizes all time-related operations to use the custom TimeUtil utility class and ensures all task sensors use the poke mode for consistency.
Problem: The codebase had inconsistent time handling — some places used Python's built-in datetime.datetime.now() while others used TimeUtil. This made the code harder to maintain and potentially introduced timezone inconsistencies. Additionally, the new uptime validation sensors were using mode="reschedule" instead of the team's standard mode="poke".

Technical Implementation

  1. Extended TimeUtil with now() method:
    • Added TimeUtil.now() class method that returns the current UTC time as a TimeUtil instance
    • This provides a single, consistent way to get the current time across the codebase
  2. Standardized time operations in jobset_util.py:
    • Removed import datetime module, replaced with direct from datetime import timedelta
    • Converted all datetime.datetime.now() calls to TimeUtil.now()
    • Simplified time difference comparison from:
    now.to_datetime() - start_time.to_datetime() >= timedelta(seconds=wait_time_seconds)
    
    to:
    (now.time - start_time.time) >= wait_time_seconds
    
    • Fixed incorrect function call: changed query_time_series to list_time_series (the parameters being passed matched list_time_series signature, not query_time_series
  3. Standardized sensor modes:
    • Changed wait_for_jobset_uptime_data from mode="reschedule" to mode="poke"
    • Changed ensure_no_jobset_uptime_data from mode="reschedule" to mode="poke"
  4. Updated jobset_uptime_validation.py:
    • Simplified get_current_time() task to use TimeUtil.now() directly

Test

Checklist

Before submitting this PR, please make sure (put X in square brackets):

  • I have performed a self-review of my code.
  • I have necessary comments in my code, particularly in hard-to-understand areas.
  • I have run one-shot tests and provided workload links above if applicable.
  • I have made or will make corresponding changes to the doc if needed.

This change standardizes all time-related operations to use the custom `TimeUtil` utility class and ensures all task sensors use the poke mode for consistency.
Problem: The codebase had inconsistent time handling — some places used Python's built-in `datetime.datetime.now()` while others used `TimeUtil`. This made the code harder to maintain and potentially introduced timezone inconsistencies. Additionally, the new uptime validation sensors were using `mode="reschedule"` instead of the team's standard `mode="poke"`.
@alfredyu-cienet alfredyu-cienet merged commit dd90f04 into GoogleCloudPlatform:master Mar 2, 2026
17 checks passed
@alfredyu-cienet alfredyu-cienet deleted the tpu-obs/release/pr-220 branch March 2, 2026 10:17
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