Repository navigation
fix(providers): mark reported costs as known and stop inventing Azure inventory region and state #713
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(providers): mark reported costs as known and stop inventing Azure inventory region and state #713
Changes from all commits
4ad7c9e
c3505c3
0d85428
cdc2d13
67bba81
8e62d60
f37ef20
19f230e
89919c2
93a29ee
f2ac40f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -74,6 +74,9 @@ func (a *AWSLadder) listRICommitments(ctx context.Context) ([]common.Commitment, | |
| // FixedPrice) are per-instance, so the per-instance hourly rate is multiplied | ||
| // by InstanceCount. See riHourlyCost for the formula and semantics (matches the | ||
| // repo's canonical monthlyCostFromConvertibleRI in internal/api/handler_ri_exchange.go). | ||
| // | ||
| // CostKnown requires a Duration: riHourlyCost skips upfront amortization without | ||
| // one, so the total would be incomplete. | ||
| func riToCommitment(ri *ec2svc.ConvertibleRI, accountID, region string) common.Commitment { | ||
| totalHourlyCost := riHourlyCost(ri) | ||
|
|
||
|
|
@@ -90,6 +93,7 @@ func riToCommitment(ri *ec2svc.ConvertibleRI, accountID, region string) common.C | |
| StartDate: ri.Start, | ||
| EndDate: ri.End, | ||
| Cost: totalHourlyCost, | ||
| CostKnown: ri.Duration > 0, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
| } | ||
|
|
||
|
|
@@ -140,5 +144,6 @@ func spToCommitment(sp *ActiveSP, accountID string) common.Commitment { | |
| StartDate: sp.StartDate, | ||
| EndDate: sp.EndDate, | ||
| Cost: sp.HourlyCommitmentUSD, | ||
| CostKnown: true, | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| package ladder | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
|
|
||
| ec2svc "github.com/LeanerCloud/cloud-commitments-go/providers/aws/services/ec2" | ||
| ) | ||
|
|
||
| func TestRIToCommitment_FullyUpfrontWithDurationIsKnown(t *testing.T) { | ||
| t.Parallel() | ||
| ri := &ec2svc.ConvertibleRI{ | ||
| ReservedInstanceID: "ri-1", | ||
| InstanceCount: 2, | ||
| FixedPrice: 8760, | ||
| Duration: 31536000, // one year in seconds | ||
| } | ||
|
|
||
| got := riToCommitment(ri, "123456789012", "us-east-1") | ||
|
|
||
| assert.True(t, got.CostKnown) | ||
| assert.Greater(t, got.Cost, 0.0) | ||
| } | ||
|
|
||
| func TestRIToCommitment_NoDurationIsUnknown(t *testing.T) { | ||
| t.Parallel() | ||
| // Without a duration the upfront part cannot be amortized, so the | ||
| // computed cost is incomplete and must not be claimed as known. | ||
| ri := &ec2svc.ConvertibleRI{ReservedInstanceID: "ri-1", InstanceCount: 2, FixedPrice: 8760} | ||
|
|
||
| got := riToCommitment(ri, "123456789012", "us-east-1") | ||
|
|
||
| assert.False(t, got.CostKnown) | ||
| } | ||
|
|
||
| func TestSPToCommitment_ZeroHourlyCommitmentIsKnown(t *testing.T) { | ||
| t.Parallel() | ||
| sp := &ActiveSP{PlanID: "sp-1", PlanType: spPlanTypeCompute, HourlyCommitmentUSD: 0} | ||
|
|
||
| got := spToCommitment(sp, "123456789012") | ||
|
|
||
| assert.True(t, got.CostKnown) | ||
| assert.Zero(t, got.Cost) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package reservationstest | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
|
|
||
| "github.com/LeanerCloud/cloud-commitments-go/pkg/common" | ||
| ) | ||
|
|
||
| // AssertUnknownInventory asserts that c carries only what the consumption | ||
| // ReservationDetail API reports: no region, state, price, quantity or start | ||
| // date. Producers built on that API must not invent these from the client. | ||
| func AssertUnknownInventory(t *testing.T, c common.Commitment) { | ||
| t.Helper() | ||
| assert.Empty(t, c.Region, "region is not in ReservationDetail") | ||
| assert.Empty(t, c.State, "state is not in ReservationDetail") | ||
| assert.False(t, c.CostKnown) | ||
| assert.Zero(t, c.Cost) | ||
| assert.Zero(t, c.Count) | ||
| assert.True(t, c.StartDate.IsZero()) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Script executed:
Repository: LeanerCloud/cloud-commitments-go
Length of output: 40946
Script executed:
Repository: LeanerCloud/cloud-commitments-go
Length of output: 20139
Web query:
AWS SDK Go v2 aws ToFloat32 nil zero v1.47.5 ec2 v1.343.0 ReservedInstances FixedPrice UsagePrice optional recurringCharges API responseResult:
Web query:
site:docs.aws.amazon.com/AWSEC2/latest/APIReference/API_ReservedInstances.html fixedPrice usagePrice recurringCharges required NoResult:
Script executed:
Repository: LeanerCloud/cloud-commitments-go
Length of output: 1558
Preserve RI price presence before marking cost known.
If EC2 omits all price fields but returns a positive duration,
ListCommitmentsreports a known zero cost. Preserve price-field presence inConvertibleRIand leaveCostKnownfalse when no price was reported.