Azure Monitor API rejecting timespan format#1003
Conversation
📝 WalkthroughWalkthroughThe PR updates Azure metrics timespan construction in ChangesMetrics Timespan Serialization
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@cloud_governance/common/clouds/azure/monitor/monitor_management_operations.py`:
- Line 84: The timespan strings in
cloud_governance/policy/helpers/azure/azure_policy_operations.py are built using
f'{start_date}/{end_date}' where start_date/end_date are datetime objects from
Utils.get_start_and_end_datetime(); change these to use ISO 8601 formatting like
f'{start_date.isoformat()}/{end_date.isoformat()}' in every call site (the three
places around the reported locations) so they match
monitor_management_operations.py and meet Azure Monitor's
startDateTime_ISO/endDateTime_ISO requirement.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Enterprise
Run ID: 85a13054-02b5-40cb-af63-ed76d868c163
📒 Files selected for processing (1)
cloud_governance/common/clouds/azure/monitor/monitor_management_operations.py
There was a problem hiding this comment.
🧹 Nitpick comments (1)
cloud_governance/policy/helpers/azure/azure_policy_operations.py (1)
201-202: ⚡ Quick winConsider extracting timespan construction into a helper method.
The identical timespan formatting pattern is repeated across three methods. Extracting it would improve maintainability and ensure consistency if the formatting logic needs adjustment.
♻️ Example refactor
def _build_timespan(self, days: int) -> str: """Build ISO-8601 formatted timespan string for Azure Monitor queries.""" start_date, end_date = Utils.get_start_and_end_datetime(days=days) return f'{start_date.isoformat()}/{end_date.isoformat()}'Then use in each method:
timespan = self._build_timespan(days=days)Also applies to: 220-221, 240-241
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@cloud_governance/policy/helpers/azure/azure_policy_operations.py` around lines 201 - 202, The repeated construction of the Azure Monitor timespan string using Utils.get_start_and_end_datetime(days=days) and f'{start_date.isoformat()}/{end_date.isoformat()}' appears in multiple methods; extract this into a private helper method (e.g., _build_timespan(self, days: int) -> str) that calls Utils.get_start_and_end_datetime and returns the formatted ISO-8601 timespan, then replace the three inline occurrences (where timespan is constructed around Utils.get_start_and_end_datetime) with calls to self._build_timespan(days=days) to centralize formatting and ensure consistency.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@cloud_governance/policy/helpers/azure/azure_policy_operations.py`:
- Around line 201-202: The repeated construction of the Azure Monitor timespan
string using Utils.get_start_and_end_datetime(days=days) and
f'{start_date.isoformat()}/{end_date.isoformat()}' appears in multiple methods;
extract this into a private helper method (e.g., _build_timespan(self, days:
int) -> str) that calls Utils.get_start_and_end_datetime and returns the
formatted ISO-8601 timespan, then replace the three inline occurrences (where
timespan is constructed around Utils.get_start_and_end_datetime) with calls to
self._build_timespan(days=days) to centralize formatting and ensure consistency.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Enterprise
Run ID: 91c6dfe6-090b-49de-bc4d-7ea14669e021
📒 Files selected for processing (1)
cloud_governance/policy/helpers/azure/azure_policy_operations.py
Type of change
Note: Fill x in []
Description
Problem: Azure Monitor API was rejecting timespan format due to non-ISO 8601 datetime formatting. Found from azure daily policies run Jenkins job.
For security reasons, all pull requests need to be approved first before running any automated CI
Assisted-by: Cursor