[amg] Fix year duration calculation for service-account token create (#10181) - #10195
Open
Nithin (nithin42) wants to merge 3 commits into
Open
[amg] Fix year duration calculation for service-account token create (#10181)#10195Nithin (nithin42) wants to merge 3 commits into
Nithin (nithin42) wants to merge 3 commits into
Conversation
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
microsoft-github-policy-service
Bot
requested review from
Yu Chen (jsntcy),
ZelinWang (wangzelin007) and
Yong Zhang (yonzhan)
August 9, 2026 03:03
Contributor
There was a problem hiding this comment.
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.1and 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.
Collaborator
|
amg |
Author
|
Ethan Yang (@necusjz) any updates ? |
…ttest.TestCase) class
Member
|
lgtm. and im honored to have the review from Alan Zhang (@ABZhang0) who is the owner from service team. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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, theunit_to_secondsdictionary mapped"y"to3600 * 24 * 30 * 365. Because of the duplicate30multiplier, 1 year was calculated as 30 years (315,360,000seconds). Passing10yevaluated to 300 years, causing Grafana's nanosecond timestamp calculation to overflow into the past (year 1741), producing an already-expired token.Fix Details
"y"inunit_to_secondsfrom3600 * 24 * 30 * 365to3600 * 24 * 365(31,536,000seconds/year)._params.py("fr"->"for").test_duration_conversionunit test covering all duration units (s,m,h,d,w,M,y).amgextension version to3.0.1insetup.pyand updatedHISTORY.rst.Testing
Ran unit test suite validating duration conversion logic for all supported units (
s,m,h,d,w,M,y).