Skip to content

Conversation

@b3nw
Copy link
Contributor

@b3nw b3nw commented Jan 22, 2026

Summary

  • Adds reset_time_iso field to model stats in /v1/quota-stats API response
  • Provides human-readable ISO 8601 UTC timestamp for quota reset time
  • Fixes issue where end users only received Unix timestamp without readable format

Changes

  • src/rotator_library/usage_manager.py
    • Added _format_timestamp_iso() method to format Unix timestamps as ISO 8601 UTC strings
    • Added reset_time_iso field to model stats dict in get_stats_for_endpoint()

Context

Previously, the /v1/quota-stats endpoint returned only quota_reset_ts (Unix timestamp). Now it also returns reset_time_iso (ISO 8601 UTC string) following the established _iso suffix pattern.


Important

Adds reset_time_iso to /v1/quota-stats API response for ISO 8601 UTC timestamp of quota reset time.

  • Behavior:
    • Adds reset_time_iso field to /v1/quota-stats API response, providing ISO 8601 UTC timestamp for quota reset time.
    • Previously, only quota_reset_ts (Unix timestamp) was returned.
  • Functions:
    • Adds _format_timestamp_iso() in usage_manager.py to convert Unix timestamps to ISO 8601 UTC strings.
    • Updates get_stats_for_endpoint() in usage_manager.py to include reset_time_iso in model stats.
  • Context:
    • Follows _iso suffix pattern for human-readable timestamps.

This description was created by Ellipsis for 96d8d01. You can customize this summary. It will automatically update as commits are pushed.

@b3nw b3nw requested a review from Mirrowel as a code owner January 22, 2026 22:40
@mirrobot-agent
Copy link
Contributor

I'm starting my review of the quota stats enhancement. Adding ISO timestamps is a great move for readability. Checking the implementation details now!

Copy link
Contributor

@mirrobot-agent mirrobot-agent bot left a comment

Choose a reason for hiding this comment

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

Overall Assessment

This is a solid improvement to the quota stats API. Adding human-readable timestamps significantly improves the usability of the /v1/quota-stats endpoint for developers and follows the established _iso suffix pattern in the project.

Architectural Feedback

The approach of adding a dedicated helper method _format_timestamp_iso is clean and maintainable. It aligns well with the existing _format_timestamp_local helper and centralizes the formatting logic.

Key Suggestions

  • ISO Formatting: I've suggested a minor tweak to the isoformat() call to ensure it matches the Z suffix mentioned in the docstring and avoids unnecessary microsecond precision.
  • API Consistency: Since the endpoint already returns window_start_ts, adding window_start_iso alongside reset_time_iso would provide a more consistent experience for API consumers.

Nitpicks and Minor Points

  • I noticed that src/rotator_library/client.py contains a similar inline implementation of this ISO formatting. While not urgent, moving this helper to a shared utility module in the future could help reduce duplication.

Questions for the Author

None.

This review was generated by an AI assistant.

Comment on lines +1214 to +1229
def _format_timestamp_iso(self, ts: Optional[float]) -> Optional[str]:
"""
Format Unix timestamp as ISO 8601 UTC string for API responses.
Args:
ts: Unix timestamp or None
Returns:
Formatted string like "2025-12-07T14:30:17Z" or None
"""
if ts is None:
return None
try:
return datetime.fromtimestamp(ts, tz=timezone.utc).isoformat()
except (OSError, ValueError, OverflowError):
return None
Copy link
Contributor

Choose a reason for hiding this comment

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

The current implementation of isoformat() on a timezone-aware datetime will produce a +00:00 offset instead of the Z suffix mentioned in the docstring. Additionally, it may include microseconds if the timestamp has them. For a cleaner API response that matches the docstring, consider:

Suggested change
def _format_timestamp_iso(self, ts: Optional[float]) -> Optional[str]:
"""
Format Unix timestamp as ISO 8601 UTC string for API responses.
Args:
ts: Unix timestamp or None
Returns:
Formatted string like "2025-12-07T14:30:17Z" or None
"""
if ts is None:
return None
try:
return datetime.fromtimestamp(ts, tz=timezone.utc).isoformat()
except (OSError, ValueError, OverflowError):
return None
try:
return datetime.fromtimestamp(ts, tz=timezone.utc).isoformat(timespec="seconds").replace("+00:00", "Z")
except (OSError, ValueError, OverflowError):

Comment on lines 3741 to +3745
"window_start_ts": model_stats.get("window_start_ts"),
"quota_reset_ts": model_stats.get("quota_reset_ts"),
"reset_time_iso": self._format_timestamp_iso(
model_stats.get("quota_reset_ts")
),
Copy link
Contributor

Choose a reason for hiding this comment

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

For consistency with reset_time_iso, consider adding window_start_iso as well. This provides a readable format for both key time metrics in the response.

Suggested change
"window_start_ts": model_stats.get("window_start_ts"),
"quota_reset_ts": model_stats.get("quota_reset_ts"),
"reset_time_iso": self._format_timestamp_iso(
model_stats.get("quota_reset_ts")
),
"window_start_ts": model_stats.get("window_start_ts"),
"window_start_iso": self._format_timestamp_iso(
model_stats.get("window_start_ts")
),
"quota_reset_ts": model_stats.get("quota_reset_ts"),
"reset_time_iso": self._format_timestamp_iso(
model_stats.get("quota_reset_ts")
),

@b3nw b3nw closed this Jan 22, 2026
@Mirrowel
Copy link
Owner

Damn, Opened and closed within 5 minutes.

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