Skip to content

[amg] Fix year duration calculation for service-account token create (#10181) - #10195

Open
Nithin (nithin42) wants to merge 3 commits into
Azure:mainfrom
nithin42:fix/amg-token-ttl-year-calculation
Open

[amg] Fix year duration calculation for service-account token create (#10181)#10195
Nithin (nithin42) wants to merge 3 commits into
Azure:mainfrom
nithin42:fix/amg-token-ttl-year-calculation

Conversation

@nithin42

Copy link
Copy Markdown

Description

Fixes #10181.

This PR fixes a duration calculation bug in the Azure Managed Grafana (amg) extension when creating service account tokens with the year unit (e.g., --time-to-live 10y).

Problem & Cause

In src/amg/azext_amg/custom.py, the unit_to_seconds dictionary mapped "y" to 3600 * 24 * 30 * 365. Because of the duplicate 30 multiplier, 1 year was calculated as 30 years (315,360,000 seconds). Passing 10y evaluated to 300 years, causing Grafana's nanosecond timestamp calculation to overflow into the past (year 1741), producing an already-expired token.

Fix Details

  1. Duration Formula: Corrected "y" in unit_to_seconds from 3600 * 24 * 30 * 365 to 3600 * 24 * 365 (31,536,000 seconds/year).
  2. Help Text: Fixed minor typo in _params.py ("fr" -> "for").
  3. Unit Tests: Added test_duration_conversion unit test covering all duration units (s, m, h, d, w, M, y).
  4. Version Bump: Bumped amg extension version to 3.0.1 in setup.py and updated HISTORY.rst.

Testing

Ran unit test suite validating duration conversion logic for all supported units (s, m, h, d, w, M, y).

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@microsoft-github-policy-service microsoft-github-policy-service Bot added customer-reported Issues that are reported by GitHub users external to the Azure organization. Auto-Assign Auto assign by bot extension/grafana az grafana labels Aug 9, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the amg (Azure Managed Grafana) CLI extension to correct year-based TTL parsing for service-account token creation, preventing invalid/overflowed expirations when users pass values like --time-to-live 10y.

Changes:

  • Fixes the "y" duration unit conversion from an incorrect 30× multiplier to a correct 365-day year in _convert_duration_to_seconds.
  • Adds a regression test covering duration conversions for all supported units.
  • Bumps the extension version to 3.0.1 and adds a changelog entry; fixes a small help-text typo.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/amg/azext_amg/custom.py Corrects year-to-seconds conversion used for secondsToLive when creating service-account tokens.
src/amg/azext_amg/tests/latest/test_amg_scenario.py Adds coverage for duration parsing across all supported units, including y.
src/amg/azext_amg/_params.py Fixes a typo in the --time-to-live help text.
src/amg/setup.py Bumps the amg extension version to 3.0.1.
src/amg/HISTORY.rst Adds a 3.0.1 changelog entry describing the fix.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/amg/azext_amg/custom.py
Comment thread src/amg/HISTORY.rst Outdated
@yonzhan

Copy link
Copy Markdown
Collaborator

amg

@nithin42

Copy link
Copy Markdown
Author

Ethan Yang (@necusjz) any updates ?

Comment thread src/amg/azext_amg/tests/latest/test_amg_scenario.py
@necusjz

Copy link
Copy Markdown
Member

lgtm. and im honored to have the review from Alan Zhang (@ABZhang0) who is the owner from service team.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Auto-Assign Auto assign by bot customer-reported Issues that are reported by GitHub users external to the Azure organization. extension/grafana az grafana

Projects

None yet

Development

Successfully merging this pull request may close these issues.

az grafana service-account token create --time-to-live bugs: 10y yields corrupted expiry (year 1741); omitting the flag gives 1 day

4 participants