fix: make Azure billing usage and forecast windows configurable - #52209
fix: make Azure billing usage and forecast windows configurable#52209stefans-elastic wants to merge 3 commits into
Conversation
🤖 GitHub commentsJust comment with:
|
0b9cdd2 to
5afc628
Compare
|
This pull request does not have a backport label.
To fixup this pull request, you need to add the backport labels for the needed
|
5afc628 to
9e64196
Compare
✅ Elastic Docs Style Checker (Vale)No issues found on modified lines! The Vale linter checks documentation changes against the Elastic Docs style guide. To use Vale locally or report issues, refer to Elastic style guide for Vale. |
|
/test |
There was a problem hiding this comment.
Function func (client *Client) GetMetrics sets following filter:
filter := fmt.Sprintf(
"properties/usageStart eq '%s' and properties/usageEnd eq '%s'",
timeOpts.usageStart.Format(time.RFC3339Nano),
timeOpts.usageEnd.Format(time.RFC3339Nano),
)
result, err := client.BillingService.GetUsageDetails(
scope,
"properties/meterDetails",
filter,
armconsumption.MetrictypeActualCostMetricType,
timeOpts.usageStart.Format("2006-01-02"), // startDate
timeOpts.usageEnd.Format("2006-01-02"), // endDate
)
Will this change work with that or should we use ge and le? We are passing start and end separately but it's worth checking out.
Use range comparisons for the Azure Consumption usage details filter so configurable multi-day lookback windows work for legacy billing scopes as well as the startDate/endDate path. Add a focused unit test that verifies the generated usage details filter and request dates for a multi-day window. Assisted-By: Cursor Co-authored-by: Cursor <cursoragent@cursor.com>
|
@jakubgalecki0 Verified this and changed the usage details |
|
|
||
| If none of the 2 options are entered then the subscription ID will be used as scope. | ||
|
|
||
| `billing_usage_lookback` |
There was a problem hiding this comment.
In which version will these config options become available?
If this will not be backported:
| `billing_usage_lookback` | |
| `billing_usage_lookback` {applies_to}`stack: ga 9.6+` |
If it will be backported, then show the earliest version in which it will become available, e.g:
| `billing_usage_lookback` | |
| `billing_usage_lookback` {applies_to}`stack: ga 9.3+` |
| data is documented to be updated for up to 72 hours after a billing period closes, so increasing | ||
| this to `72h` ensures that late cost corrections from Azure are re-queried and ingested. | ||
|
|
||
| `billing_forecast_window` |
There was a problem hiding this comment.
Same here… If this will not be backported:
| `billing_forecast_window` | |
| `billing_forecast_window` {applies_to}`stack: ga 9.6+` |
If it will be backported, then show the earliest version in which it will become available, e.g:
| `billing_forecast_window` | |
| `billing_forecast_window` {applies_to}`stack: ga 9.3+` |
Proposed commit message
fix: make Azure billing usage and forecast windows configurable
The azure/billing metricset always queried a hardcoded window: exactly the
previous full UTC day for usage, and reference-2d..+30d for forecast. Azure
Cost Management data can change for up to 72 hours after a billing period
closes, but the metricset never re-queried a date it had already collected,
so late cost corrections were never ingested.
Add two duration config options to the shared azure.Config:
usageIntervalFrom and forecastIntervalFrom now take the window as a
parameter; defaults reproduce the previous behaviour exactly, so existing
deployments are unaffected. Operators can set billing_usage_lookback: 72h
to re-ingest Azure's late corrections.
Checklist
stresstest.shscript to run them under stress conditions and race detector to verify their stability../changelog/fragmentsusing the changelog tool.Disruptive User Impact
How to test this PR locally
Ran the
azurebillingmetricset against a live Azure subscription withbilling_usage_lookback: 72h, publishing to a local Elasticsearch, and confirmedthat usage data is now collected for the whole lookback window instead of just the
previous day.
The metricset logs show the widened usage window (start moved back to
-72h, endunchanged at the previous full day):
Verified in Elasticsearch that usage documents span three full days. The
azure.billing.usage_startfilter isolates usage docs (excludes the forward-lookingforecast events), and a daily
date_histogramonazure.billing.usage_datereturnsone bucket per collected day:
Request / Response
Request:
Response:
{ "took": 8, "timed_out": false, "_shards": { "total": 1, "successful": 1, "skipped": 0, "failed": 0 }, "hits": { "total": { "value": 839, "relation": "eq" }, "max_score": null, "hits": [] }, "aggregations": { "days": { "buckets": [ { "key_as_string": "2026-07-19", "key": 1784419200000, "doc_count": 277 }, { "key_as_string": "2026-07-20", "key": 1784505600000, "doc_count": 289 }, { "key_as_string": "2026-07-21", "key": 1784592000000, "doc_count": 273 } ] } } }Three
usage_datebuckets (2026-07-19,2026-07-20,2026-07-21) confirm the72h window re-queried three full days. With the default
24hlookback the samequery returns a single bucket (
2026-07-21), matching the previous behaviour.A reviewer can reproduce this with a minimal config:
Related issues
Use cases
Screenshots
Logs