Skip to content

Fix Azure Monitor API timespan format to use 'Z' for UTC#1005

Merged
pragya811 merged 1 commit into
mainfrom
jenkins_fix6
Jun 18, 2026
Merged

Fix Azure Monitor API timespan format to use 'Z' for UTC#1005
pragya811 merged 1 commit into
mainfrom
jenkins_fix6

Conversation

@pragya811

Copy link
Copy Markdown
Member

Type of change

Note: Fill x in []

  • bug
  • enhancement
  • documentation
  • dependencies

Description

Azure Monitor API requires timespan to use 'Z' suffix for UTC timezone instead of '+00:00' offset. Changed from datetime.isoformat() to strftime('%Y-%m-%dT%H:%M:%SZ') to match Azure's expected ISO 8601 format.

This fixes the BadRequest error: "Detected invalid time interval input" that was occurring in instance_idle and unused_nat_gateway policies.

For security reasons, all pull requests need to be approved first before running any automated CI

Azure Monitor API requires timespan to use 'Z' suffix for UTC timezone
instead of '+00:00' offset. Changed from datetime.isoformat() to
strftime('%Y-%m-%dT%H:%M:%SZ') to match Azure's expected ISO 8601 format.

This fixes the BadRequest error: "Detected invalid time interval input"
that was occurring in instance_idle and unused_nat_gateway policies.

Files modified:
- cloud_governance/common/clouds/azure/monitor/monitor_management_operations.py
- cloud_governance/policy/helpers/azure/azure_policy_operations.py

Co-authored-by: Cursor <cursoragent@cursor.com>
@pragya811 pragya811 self-assigned this Jun 17, 2026
@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Enterprise

Run ID: a29f7e3a-212f-4143-9f98-d43da012e11b

📥 Commits

Reviewing files that changed from the base of the PR and between 0c99ac2 and bfa8658.

📒 Files selected for processing (2)
  • cloud_governance/common/clouds/azure/monitor/monitor_management_operations.py
  • cloud_governance/policy/helpers/azure/azure_policy_operations.py

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Updated Azure Monitor metrics queries to use standardized UTC ISO-8601 formatted timestamps for consistent API compatibility across metric retrieval operations.

Walkthrough

Four single-line changes replace isoformat() with strftime("%Y-%m-%dT%H:%M:%SZ") when constructing the timespan string for Azure Monitor metrics queries, adding an explicit UTC Z suffix in monitor_management_operations.py and three methods of azure_policy_operations.py.

Changes

Azure Monitor UTC timespan formatting

Layer / File(s) Summary
strftime UTC timespan in monitor and policy helpers
cloud_governance/common/clouds/azure/monitor/monitor_management_operations.py, cloud_governance/policy/helpers/azure/azure_policy_operations.py
get_resource_metrics and the three metric helper methods (get_cpu_utilization_percentage_metric, get_network_in_kib_metric, get_network_out_kib_metric) now format start_date/end_date using strftime with a trailing Z instead of isoformat() when building the timespan string.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely summarizes the main change: fixing Azure Monitor API timespan format to use 'Z' for UTC instead of '+00:00' offset.
Description check ✅ Passed The description is directly related to the changeset, explaining the Azure Monitor timespan format fix, the specific method change from isoformat() to strftime(), and the bug it resolves.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Comment @coderabbitai help to get the list of available commands and usage tips.

@ebattat ebattat left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

/approve

@pragya811 pragya811 merged commit 70a5633 into main Jun 18, 2026
19 checks passed
@github-project-automation github-project-automation Bot moved this from In progress to Done in Cloud-Governance project Jun 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

2 participants