Skip to content

fix: set interval (granularity) in Azure Monitor API request#7526

Open
nicknikolakakis wants to merge 2 commits into
kedacore:mainfrom
nicknikolakakis:fix/7524-azure-monitor-interval
Open

fix: set interval (granularity) in Azure Monitor API request#7526
nicknikolakakis wants to merge 2 commits into
kedacore:mainfrom
nicknikolakakis:fix/7524-azure-monitor-interval

Conversation

@nicknikolakakis
Copy link
Copy Markdown

Fixes #7524

Summary

The azure-monitor scaler was not setting the Interval (granularity) parameter when querying the Azure Monitor metrics API. Without it, Azure defaults to PT1M granularity, returning multiple data points within the timespan. Since verifyAggregationTypeIsSupported only reads data[len(data)-1] (the last data point), the Total aggregation over a 15-minute window would only return the last 1-minute bucket's value instead of the sum over the full window.

Changes

  • formatTimeSpan now also returns an ISO 8601 duration string (e.g., PT15M) matching the timespan, and requestMetric passes it as opts.Interval
  • When no metricAggregationInterval is configured, both timespan and interval default to 5 minutes (PT5M)
  • Added unit tests for toISO8601Duration and formatTimeSpan
  • Updated CHANGELOG.md

How it works

Before After
Interval: nil → Azure returns multiple 1-min buckets Interval: "PT15M" → Azure returns a single data point
Only last bucket's value is used Single aggregated value covers the full window

@nicknikolakakis nicknikolakakis requested a review from a team as a code owner March 8, 2026 05:35
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 8, 2026

Thank you for your contribution! 🙏

Please understand that we will do our best to review your PR and give you feedback as soon as possible, but please bear with us if it takes a little longer as expected.

While you are waiting, make sure to:

  • Add an entry in our changelog in alphabetical order and link related issue
  • Update the documentation, if needed
  • Add unit & e2e tests for your changes
  • GitHub checks are passing
  • Is the DCO check failing? Here is how you can fix DCO issues

Once the initial tests are successful, a KEDA member will ensure that the e2e tests are run. Once the e2e tests have been successfully completed, the PR may be merged at a later date. Please be patient.

Learn more about our contribution guide.

@keda-automation keda-automation requested a review from a team March 8, 2026 05:35
@snyk-io
Copy link
Copy Markdown

snyk-io Bot commented Mar 8, 2026

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 9, 2026

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

@github-actions github-actions Bot added the stale All issues that are marked as stale due to inactivity label May 9, 2026
@rickbrouwer rickbrouwer added merge-conflict This PR has a merge conflict and removed stale All issues that are marked as stale due to inactivity labels May 9, 2026
The azure-monitor scaler was not setting the Interval parameter when
querying Azure Monitor metrics. Without it, Azure defaults to PT1M
granularity, returning multiple data points within the timespan. Since
verifyAggregationTypeIsSupported only reads the last data point, the
Total aggregation over a 15-minute window would only return the last
1-minute bucket instead of the sum over the full window.

Set Interval equal to the timespan duration so Azure returns a single
aggregated data point covering the entire window.

Fixes kedacore#7524

Signed-off-by: Nick Nikolakakis <nonicked@protonmail.com>
- Extract "PT5M" into defaultAggregationInterval constant
- Sort changelog entry alphabetically (Azure before Cron)

Signed-off-by: Nick Nikolakakis <nonicked@protonmail.com>
@nicknikolakakis nicknikolakakis force-pushed the fix/7524-azure-monitor-interval branch from c268bdb to 27ef61c Compare May 9, 2026 05:22
@rickbrouwer rickbrouwer removed the merge-conflict This PR has a merge conflict label May 9, 2026
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.

azure-monitor scaler seems to ignore metricAggregationInterval

2 participants