Skip to content

fix(azure): make ondemand pricing OS-aware for Windows nodes - #3820

Merged
ameijer merged 7 commits into
opencost:developfrom
V-3604:fix/azure-os-aware-pricing
Jun 25, 2026
Merged

ameijer merged 7 commits into
opencost:developfrom
V-3604:fix/azure-os-aware-pricing

Conversation

@V-3604

@V-3604 V-3604 commented May 27, 2026

Copy link
Copy Markdown
Contributor

Fixes #3532

Description

Azure node pricing was OS-blind: azureKey.Features() produced a key of region,instance,ondemand with no OS component, the RateCard parser silently dropped all Windows VM meters, and the retail-price fallback filtered Windows products out entirely. Windows nodes always received Linux pricing.

This change makes all three layers OS-aware:
azureKey.Features() now appends ,windows to the lookup key when the node carries kubernetes.io/os: windows (or deprecated beta.kubernetes.io/os label).
convertMeterToPricings no longer drops Windows subcategory meters; stores them under region,instance,ondemand,windows keys instead.
extractAzureVMRetailAndSpotPrices now returns Linux and Windows retail/spot prices as separate values; getRetailPrice selects correct pair based on a new isWindows bool parameter.
NodePricing detects the OS label, builds OS-qualified lookup keys for spot nodes as well (region,instance,spot,windows), and passes isWindows to getRetailPrice.
Linux nodes and nodes with no OS label are unaffected, key format unchanged.

Related Issues

Fixes #3532

User Impact

Windows nodes on AKS (or any Azure Kubernetes cluster) will now receive Windows VM pricing rather than Linux pricing. No impact on Linux nodes.

Testing

New unit test TestAzureKeyFeaturesOS covers all label combinations (both OS label keys, Linux, no label, case-insensitive). Existing TestConvertMeterToPricings/windows updated to assert a Windows-keyed pricing entry is returned. Test_extractAzureVMRetailAndSpotPrices updated to assert both Linux and Windows prices are captured in the same API response.

=== RUN TestConvertMeterToPricings
=== RUN TestConvertMeterToPricings/windows
=== RUN TestConvertMeterToPricings/storage
{"level":"debug","time":"2026-05-27T14:21:30-05:00","message":"Adding PV.Key: useast,premium_ssd, Cost: 0.085616"}
=== RUN TestConvertMeterToPricings/virtual_machines
--- PASS: TestConvertMeterToPricings (0.00s)
--- PASS: TestConvertMeterToPricings/windows (0.00s)
--- PASS: TestConvertMeterToPricings/storage (0.00s)
--- PASS: TestConvertMeterToPricings/virtual_machines (0.00s)
=== RUN TestAzureKeyFeaturesOS
=== RUN TestAzureKeyFeaturesOS/windows_node_via_kubernetes.io/os
=== RUN TestAzureKeyFeaturesOS/windows_node_via_beta.kubernetes.io/os
=== RUN TestAzureKeyFeaturesOS/linux_node
=== RUN TestAzureKeyFeaturesOS/no_OS_label_defaults_to_linux_key
=== RUN TestAzureKeyFeaturesOS/windows_case-insensitive
--- PASS: TestAzureKeyFeaturesOS (0.00s)
--- PASS: TestAzureKeyFeaturesOS/windows_node_via_kubernetes.io/os (0.00s)
--- PASS: TestAzureKeyFeaturesOS/windows_node_via_beta.kubernetes.io/os (0.00s)
--- PASS: TestAzureKeyFeaturesOS/linux_node (0.00s)
--- PASS: TestAzureKeyFeaturesOS/no_OS_label_defaults_to_linux_key (0.00s)
--- PASS: TestAzureKeyFeaturesOS/windows_case-insensitive (0.00s)
=== RUN Test_extractAzureVMRetailAndSpotPrices
=== RUN Test_extractAzureVMRetailAndSpotPrices/valid_response_with_retail_and_spot_prices
=== RUN Test_extractAzureVMRetailAndSpotPrices/only_retail_price_available
=== RUN Test_extractAzureVMRetailAndSpotPrices/only_spot_price_available
=== RUN Test_extractAzureVMRetailAndSpotPrices/returns_separate_Windows_and_Linux_prices
=== RUN Test_extractAzureVMRetailAndSpotPrices/filters_out_low_priority_instances
=== RUN Test_extractAzureVMRetailAndSpotPrices/empty_items_array
=== RUN Test_extractAzureVMRetailAndSpotPrices/invalid_JSON
--- PASS: Test_extractAzureVMRetailAndSpotPrices (0.00s)
--- PASS: Test_extractAzureVMRetailAndSpotPrices/valid_response_with_retail_and_spot_prices (0.00s)
--- PASS: Test_extractAzureVMRetailAndSpotPrices/only_retail_price_available (0.00s)
--- PASS: Test_extractAzureVMRetailAndSpotPrices/only_spot_price_available (0.00s)
--- PASS: Test_extractAzureVMRetailAndSpotPrices/returns_separate_Windows_and_Linux_prices (0.00s)
--- PASS: Test_extractAzureVMRetailAndSpotPrices/filters_out_low_priority_instances (0.00s)
--- PASS: Test_extractAzureVMRetailAndSpotPrices/empty_items_array (0.00s)
--- PASS: Test_extractAzureVMRetailAndSpotPrices/invalid_JSON (0.00s)
PASS
ok github.com/opencost/opencost/pkg/cloud/azure 0.137s

Copilot AI review requested due to automatic review settings May 27, 2026 19:23

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

Note

Copilot was unable to run its full agentic suite in this review.

Adds Windows-aware Azure pricing support by including OS in pricing keys and extracting separate Windows/Linux retail and spot prices from Azure Retail Prices API responses.

Changes:

  • Generate distinct pricing keys for Windows nodes/meters (,windowssuffix) inazureKey.Features()andconvertMeterToPricings()`
  • Extend Azure retail/spot price extraction to return separate Windows and Linux values and update retail price selection accordingly
  • Update and add tests covering Windows key feature generation and Windows pricing extraction behavior

Reviewed changes

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

File Description
pkg/cloud/azure/provider.go Adds OS-aware pricing key construction and separates Windows vs Linux retail/spot price extraction + selection.
pkg/cloud/azure/provider_test.go Updates pricing conversion expectations and adds tests for OS key formatting and Windows/Linux price extraction.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/cloud/azure/provider.go Resolved
Comment thread pkg/cloud/azure/provider_test.go Resolved
Comment thread pkg/cloud/azure/provider.go Resolved
@ameijer

ameijer commented May 27, 2026

Copy link
Copy Markdown
Member

@babbageclunk or @r2k1 would you be willing to review this change for OC?

Copilot AI review requested due to automatic review settings June 14, 2026 21:02
@V-3604
V-3604 force-pushed the fix/azure-os-aware-pricing branch from 72a5ee6 to 73a134b Compare June 14, 2026 21:02

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

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

Comment thread pkg/cloud/azure/provider_test.go Resolved
Comment thread pkg/cloud/azure/provider.go Resolved
Comment thread pkg/cloud/azure/provider.go Resolved
Comment thread pkg/cloud/azure/provider.go Resolved
Copilot AI review requested due to automatic review settings June 16, 2026 09:13

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

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

Comments suppressed due to low confidence (1)

pkg/cloud/azure/provider.go:465

  • Windows detection is implemented twice (in azureKey.Features() and again in NodePricing). This duplication makes it easier for the two paths to drift (e.g., supported label keys, normalization rules). Consider centralizing OS detection (e.g., a helper on azureKey or using the features string as the single source of truth) so there’s only one place to update the OS classification logic.
func (k *azureKey) Features() string {

Comment thread pkg/cloud/azure/provider.go Resolved
Comment thread pkg/cloud/azure/provider.go Resolved
Comment thread pkg/cloud/azure/provider.go Resolved
Comment thread pkg/cloud/azure/provider.go Resolved
Comment thread pkg/cloud/azure/provider.go Resolved
Comment thread pkg/cloud/azure/provider.go Resolved
@sonarqubecloud

Copy link
Copy Markdown

@ameijer ameijer 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.

thanks for the contribution @V-3604 !

@ameijer
ameijer added this pull request to the merge queue Jun 25, 2026
Merged via the queue into opencost:develop with commit 1741baa Jun 25, 2026
24 checks passed
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 onDemand Prices need to be OS aware

3 participants