Documentation
¶
Overview ¶
Package recommendations provides AWS Cost Explorer recommendations client
Index ¶
- Constants
- Variables
- func AdjustExistingCoverageForExpiringCommitments(recs []common.Recommendation, commitments []common.Commitment, windowDays int) (int, error)
- func AdjustExistingCoverageForExpiringCommitmentsWithCoverage(recs []common.Recommendation, commitments []common.Commitment, windowDays int, ...) (adjusted, missingDemand int, err error)
- func AdjustExistingCoverageForExpiringCommitmentsWithCoverageOptions(recs []common.Recommendation, commitments []common.Commitment, ...) (adjusted, missingDemand int, err error)
- func AggregateRDSFamilyCoverage(coverage PoolCoverageMap) map[string]FamilyCoverage
- func ApplyCoverageMapToRecommendations(recs []common.Recommendation, coverage PoolCoverageMap)
- func ApplyFamilyNUSizingRDSWithExpiry(recs []common.Recommendation, coverage PoolCoverageMap, targetPct float64, ...) (sizedRDS, nonRDS []common.Recommendation, drops FamilyDropCounts, ...)
- func ApplyFamilyNUSizingRDSWithExpiryOptions(recs []common.Recommendation, coverage PoolCoverageMap, targetPct float64, ...) (sizedRDS, nonRDS []common.Recommendation, drops FamilyDropCounts, ...)
- func RDSFamilyFromType(instanceType string) string
- func RDSInstanceNUFromType(instanceType string) float64
- func RederiveFamilyCoverage(recs []common.Recommendation, coverage PoolCoverageMap) []common.Recommendation
- type Client
- func (c *Client) AttachDailyUsageHistory(ctx context.Context, recs []common.Recommendation)
- func (c *Client) GetAllRecommendations(ctx context.Context) ([]common.Recommendation, error)
- func (c *Client) GetDailyUsagePcts(ctx context.Context, serviceFilter, resourceType, region string) ([]float64, error)
- func (c *Client) GetEC2RICoverageMap(ctx context.Context, lookbackDays int, regions []string) (PoolCoverageMap, error)
- func (c *Client) GetOnDemandFamilySeriesForAccount(ctx context.Context, accountID, region string, lookbackDays int) (map[string][]DailyCost, error)
- func (c *Client) GetOnDemandSeries(ctx context.Context, region string, lookbackDays int) ([]DailyCost, error)
- func (c *Client) GetOnDemandSeriesForAccount(ctx context.Context, accountID, region string, lookbackDays int) ([]DailyCost, error)
- func (c *Client) GetRICommitmentRate(ctx context.Context, p RICommitmentRateParams) (float64, error)
- func (c *Client) GetRICoverageMap(ctx context.Context, lookbackDays int, regions []string) (PoolCoverageMap, error)
- func (c *Client) GetRIFeeUtilization(ctx context.Context, accountID, region string, lookbackDays int) ([]RIFeeUtilization, error)
- func (c *Client) GetRIUtilization(ctx context.Context, lookbackDays int, region string) ([]RIUtilization, error)
- func (c *Client) GetRecommendations(ctx context.Context, params *common.RecommendationParams) ([]common.Recommendation, error)
- func (c *Client) GetRecommendationsForService(ctx context.Context, service common.ServiceType) ([]common.Recommendation, error)
- func (c *Client) GetSPCommitmentRate(ctx context.Context, p SPCommitmentRateParams) (float64, error)
- func (c *Client) GetSPCoverageSummary(ctx context.Context, region string, lookbackDays int) (SPCoverageSummary, error)
- func (c *Client) GetSPCoveredSeries(ctx context.Context, region string, lookbackDays int) ([]DailyCost, error)
- func (c *Client) GetSPUtilization(ctx context.Context, planType types.SupportedSavingsPlansType, region string, ...) (SPUtilizationSummary, error)
- func (c *Client) GetSPUtilizationForAccount(ctx context.Context, planType types.SupportedSavingsPlansType, ...) (SPUtilizationSummary, error)
- func (c *Client) SetInstanceTypePagerFactory(f func() InstanceTypePager)
- func (c *Client) SetRecLookbackPeriod(period string)
- type CostExplorerAPI
- type DailyCost
- type DescribeInstanceTypesAPI
- type FamilyCoverage
- type FamilyDropCounts
- type FamilyExpiryOptions
- type FamilyExpiryReport
- type IncompleteRecommendationsError
- type InstanceTypePager
- type PoolCoverage
- type PoolCoverageMap
- type PoolExpiryOptions
- type RICommitmentRateParams
- type RIFeeUtilization
- type RIUtilization
- type RateLimiter
- type SPCommitmentRateParams
- type SPCoverageSummary
- type SPUtilizationSummary
Constants ¶
const DefaultRecLookbackPeriod = "7d"
DefaultRecLookbackPeriod is the LookbackPeriod string forwarded to GetReservationPurchaseRecommendation when --rec-lookback-period is not specified. Kept in the recommendations package so the cmd flag default, the cmd-side fallback, and the client-side fallback all refer to a single source of truth (avoids the magic-value duplication called out by feedback_no_hardcoded_magic_values.md). Valid CE values are 7d/30d/60d (see convertLookbackPeriodE); 7d matches the prior hardcoded behavior from before --rec-lookback-period existed.
Variables ¶
var ErrNoRICommitmentRate = errors.New("ri commitment rate: no usable recommendation detail")
ErrNoRICommitmentRate means Cost Explorer produced no usable Reserved Instance recommendation for the requested scope (no matching detail, a field the formula needs is absent, or no covered on-demand spend). Callers must treat the layer as having no rate (explainable Hold); they must never substitute a 1:1 rate.
var ErrNoSPCommitmentRate = errors.New("sp commitment rate: no usable recommendation detail")
ErrNoSPCommitmentRate means Cost Explorer produced no usable Savings Plan recommendation for the requested scope (no matching detail, a field the formula needs is absent, or no covered on-demand spend). Callers must treat the layer as having no rate (explainable Hold); they must never substitute a 1:1 rate.
var ErrNoSPUtilization = errors.New("sp utilization: no used commitment or on-demand equivalent reported")
ErrNoSPUtilization means CE has no usable utilization for the scope (no plan, a plan too new for CE to report, or 0% used), so the commitment-to-on-demand ratio cannot be derived. Callers must surface an explainable no-op rather than fall back to a 1:1 ratio.
var ErrNotUSD = errors.New("recommendation amounts are not denominated in USD")
ErrNotUSD marks a detail skipped because Cost Explorer priced it in a non-USD currency; common.Recommendation costs are USD by contract. It surfaces through IncompleteRecommendationsError.Causes.
Functions ¶
func AdjustExistingCoverageForExpiringCommitments ¶
func AdjustExistingCoverageForExpiringCommitments( recs []common.Recommendation, commitments []common.Commitment, windowDays int, ) (int, error)
AdjustExistingCoverageForExpiringCommitments returns the number of adjusted recommendations. Demand must be complete disjoint pool shares, or freshly rebalanced by ApplyCoverageMapToRecommendations.
Partial raw slices and duplicated aggregate averages cannot be detected here. Callers with authoritative pool demand should use AdjustExistingCoverageForExpiringCommitmentsWithCoverage. It returns an error, and adjusts nothing, when a commitment or recommendation has an unknown dimension.
func AdjustExistingCoverageForExpiringCommitmentsWithCoverage ¶
func AdjustExistingCoverageForExpiringCommitmentsWithCoverage( recs []common.Recommendation, commitments []common.Commitment, windowDays int, coverage PoolCoverageMap, ) (adjusted, missingDemand int, err error)
AdjustExistingCoverageForExpiringCommitmentsWithCoverage uses authoritative pool demand, never row sums. Eligible rows lacking positive finite demand remain unchanged and are counted in missingDemand. It ignores replacements already bought; see AdjustExistingCoverageForExpiringCommitmentsWithCoverageOptions.
func AdjustExistingCoverageForExpiringCommitmentsWithCoverageOptions ¶
func AdjustExistingCoverageForExpiringCommitmentsWithCoverageOptions( recs []common.Recommendation, commitments []common.Commitment, coverage PoolCoverageMap, opts PoolExpiryOptions, ) (adjusted, missingDemand int, err error)
AdjustExistingCoverageForExpiringCommitmentsWithCoverageOptions deducts RIs expiring inside opts.WindowDays from the existing coverage of each recommendation's pool, net of replacements bought inside opts.CoverageLookbackDays: per pool the deduction is max(0, expiring - replacements). A pool whose expiring RIs are fully replaced is left untouched and is not counted as missingDemand.
Size-flexible EC2 families net in normalized units (see expiryPool), so a replacement of another size in the same family is credited. The rule is conservative: it can under-buy, never over-buy. A growth purchase in the same pool is indistinguishable from a replacement. See PoolExpiryOptions for the lookback contract. It returns an error, and adjusts nothing, when a commitment or recommendation has an unknown service or EC2 size.
func AggregateRDSFamilyCoverage ¶
func AggregateRDSFamilyCoverage(coverage PoolCoverageMap) map[string]FamilyCoverage
AggregateRDSFamilyCoverage walks the per-pool coverage map and returns a family-NU-aggregated view keyed by rdsFamilyKey. Used by family-NU sizing to size buys against the total family demand rather than per-size pool demand — matching how AWS's GetReservationPurchaseRecommendation bundles size-flex demand into a single rec at one size.
Skips non-RDS entries (their keys are 2-part, not 4-part), entries whose instance size isn't in common.RDSInstanceNU, and engines that are not size-flexible (rdsSizeFlexible).
func ApplyCoverageMapToRecommendations ¶
func ApplyCoverageMapToRecommendations(recs []common.Recommendation, coverage PoolCoverageMap)
ApplyCoverageMapToRecommendations sets ExistingCoveragePct on each rec whose pool key appears in the map, and rebalances each rec's AverageInstancesUsedPerHour so that the per-pool sum across recs equals the coverage map's org-wide AvgInstancesPerHour for the pool. Pool key shape depends on service: RDS recs (DatabaseDetails carrying an engine + AZConfig) look up by "region:instance_type:engine:deployment"; other services look up by "region:instance_type". Recs without a match stay at Known=false, which RI --target-coverage sizing drops (target-coverage-unknown) rather than treating them as 0% covered.
Why rebalance instead of just trusting per-rec avgs: AWS's GetReservationPurchaseRecommendation returns one rec per (pool, account) where it sees demand worth recommending. When AWS rec API only returns per-account avgs that sum to less than what CE coverage reports org-wide for the same pool (some linked accounts in the pool aren't surfaced as recs), per-rec sizing under-buys for the pool as a whole. Rebalancing scales each rec's avg by (cov.avg / sum-of-rec-avgs-in-pool) so the sized per-rec purchases sum to what the coverage CSV's gap math implies. When AWS rec API already matches coverage, the scale factor is ~1.0 and behavior is unchanged. When multiple recs have zero avg (no per-account signal at all), the coverage avg is split evenly across them so the total still lines up.
Mutates recs in place to mirror the way the sizing pipeline already hands recs around by value within each loop iteration.
func ApplyFamilyNUSizingRDSWithExpiry ¶
func ApplyFamilyNUSizingRDSWithExpiry( recs []common.Recommendation, coverage PoolCoverageMap, targetPct float64, commitments []common.Commitment, windowDays int, ) (sizedRDS, nonRDS []common.Recommendation, drops FamilyDropCounts, expiry FamilyExpiryReport)
ApplyFamilyNUSizingRDSWithExpiry is ApplyFamilyNUSizingRDS with rebuy-window expiry folded into family coverage first, in normalized units. RDS RIs are size-flexible and Cost Explorer reports coverage under the size actually running, so the deduction is made per family (region, family, engine, deployment), not per size pool. For each family with expiring active RIs:
post-expiry covered NU = max(CoveredNU - expiringNU, min(CoveredNU, activeNU - expiringNU)), floored at 0
activeNU sums count x NU over every active RI in the family the caller supplied. The min() keeps underutilized RIs (more RI units than usage) from overstating the gap. activeNU may be a subset of the org-wide coverage (the CLI inventory is single-account, cli#2131), so the outer max() caps the deduction at expiringNU: missing RIs must never remove more coverage than actually expires. windowDays <= 0 or no commitments leaves coverage unchanged. A family with several size rows or linked-account rows is deducted once.
This form ignores replacement RIs the account already bought for the expiring ones; callers that know the coverage lookback should use ApplyFamilyNUSizingRDSWithExpiryOptions.
func ApplyFamilyNUSizingRDSWithExpiryOptions ¶
func ApplyFamilyNUSizingRDSWithExpiryOptions( recs []common.Recommendation, coverage PoolCoverageMap, targetPct float64, commitments []common.Commitment, opts FamilyExpiryOptions, ) (sizedRDS, nonRDS []common.Recommendation, drops FamilyDropCounts, expiry FamilyExpiryReport)
ApplyFamilyNUSizingRDSWithExpiryOptions is ApplyFamilyNUSizingRDSWithExpiry that also credits replacements already bought. With R = the NU of visible active, non-expiring RIs in the family that started within opts.CoverageLookbackDays, the family's post-expiry covered NU is
max(0, max(min(C, C - E + R), min(C, A - E)))
where C is CoveredNU, E the expiring NU and A the active NU. R only raises the first term, so the result is never below the R = 0 formula (the purchase never grows), never above C, and never more than E below C. Replacement RIs bought inside the lookback are in the lagged C only in part, so crediting them in full can only under-count the gap, never over-count it. With full inventory the min(C, A - E) term already counts them.
func RDSFamilyFromType ¶
RDSFamilyFromType is the exported counterpart of rdsFamilyFromType for callers outside this package that need the family prefix of an RDS instance type (e.g. CSV writers grouping rows by family). Empty string when the type doesn't carry a recognizable size suffix.
func RDSInstanceNUFromType ¶
RDSInstanceNUFromType is the exported counterpart of rdsInstanceNUFromType for callers outside this package that need the NU value for an RDS instance type (e.g. CSV writers displaying per-row family-NU contribution). Returns 0 for unknown sizes — same fallback semantics as the unexported helper.
func RederiveFamilyCoverage ¶
func RederiveFamilyCoverage(recs []common.Recommendation, coverage PoolCoverageMap) []common.Recommendation
RederiveFamilyCoverage recomputes the family-wide ProjectedCoverage that ApplyFamilyNUSizingRDS wrote, for recs whose Count changed after sizing (--max-instances, --count-override, duplicate-RI dedupe). It returns a new slice; recs is not modified.
Only size-flexible RDS RI recs that family-NU sizing annotated (ExistingCoverageKnown) and whose family has demand in coverage are touched. Their ProjectedCoverage becomes existing% (carried on the recs, so any rebuy-window expiry adjustment is preserved) plus the family's current sum(Count x NU) over the recs supplied, relative to the family's total NU from coverage. Recs the caller removed no longer contribute. Everything else (non-RDS, Savings Plans, SQL Server, unknown sizes, families with no coverage signal) is returned unchanged.
Precondition: call it only on the output of ApplyFamilyNUSizingRDS or ApplyFamilyNUSizingRDSWithExpiry[Options], i.e. only on --target-coverage runs, and never after the legacy --coverage path. ApplyCoverageMapToRecommendations also sets ExistingCoverageKnown, with a per-pool ExistingCoveragePct, and nothing on a rec tells the two apart, so on such recs this would mix a per-pool existing% with family NU and overwrite a correct ProjectedCoverage. coverage must be the same PoolCoverageMap that was passed to sizing. ProjectedUtilization is not touched; callers refresh it from the new Count.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps the AWS Cost Explorer client for RI recommendations.
func NewClientWithAPI ¶
func NewClientWithAPI(api CostExplorerAPI, region string) *Client
NewClientWithAPI creates a new recommendations client with a custom Cost Explorer API (for testing).
func (*Client) AttachDailyUsageHistory ¶
func (c *Client) AttachDailyUsageHistory(ctx context.Context, recs []common.Recommendation)
AttachDailyUsageHistory enriches each recommendation in recs with a UsageHistory slice of daily RI-coverage percentages. Recs are batched by (serviceFilter, region) so the number of Cost Explorer requests scales with regions, not with distinct SKUs:
- A bucket with at most usageHistoryLookbackDays distinct resource types issues one DAILY query per type (GetDailyUsagePcts).
- A larger bucket issues one region-wide query per day grouped by INSTANCE_TYPE (getDailyUsagePctsByType) and fans the per-type series out to every rec. CE rejects DAILY granularity combined with GroupBy, so a single grouped request cannot return a daily series; one grouped request per day is the smallest batch CE can express.
Either way a bucket costs at most min(types, usageHistoryLookbackDays) requests (plus extra pages). Errors are logged and skipped so a single CE failure doesn't drop the whole collection; a failed fetch leaves UsageHistory nil rather than reporting zero coverage.
SavingsPlans have no per-instance-type coverage breakdown in CE, so Savings Plan recs (by CommitmentType or Service) are skipped explicitly, as are recs whose Service resolves to the empty coverage-filter string.
func (*Client) GetAllRecommendations ¶
GetAllRecommendations fetches recommendations for all supported services.
All six RI service calls (plus Savings Plans) run concurrently via CollectConcurrently. Each goroutine keeps its own error in its outcome so a single per-service failure does not cancel its siblings (matching the previous loop's `continue`-on-error tolerance). Results are merged in the canonical order EC2 → RDS → ElastiCache → OpenSearch → Redshift → MemoryDB → Savings Plans after all goroutines finish so order-sensitive consumers stay stable.
Partial results retain diagnostics through mergeServiceResults; callers decide whether their workflow can use an incomplete collection.
func (*Client) GetDailyUsagePcts ¶
func (c *Client) GetDailyUsagePcts(ctx context.Context, serviceFilter, resourceType, region string) ([]float64, error)
GetDailyUsagePcts returns a slice of daily RI-coverage percentages (0-100) for the given (service, resourceType, region) over the last usageHistoryLookbackDays days, ordered oldest-to-newest. Each element corresponds to one calendar day. If CE returns no data for a day the slot is filled with 0.0 so the sparkline always has exactly usageHistoryLookbackDays points when data is present.
Returns (nil, nil) on API success when CE has no historical data at all for the tuple; callers store nil so the frontend renders "—" rather than a flat-zero sparkline.
serviceFilter is the canonical CE SERVICE dimension value (e.g. "Amazon Elastic Compute Cloud - Compute"). The resourceType is matched by the INSTANCE_TYPE dimension so we only pick up coverage for the exact SKU the recommendation targets.
func (*Client) GetEC2RICoverageMap ¶
func (c *Client) GetEC2RICoverageMap(ctx context.Context, lookbackDays int, regions []string) (PoolCoverageMap, error)
GetEC2RICoverageMap is GetRICoverageMap restricted to EC2: one CE call per region. Non-EC2 services (ElastiCache, OpenSearch, Redshift, MemoryDB) share the "region:instance_type" key shape, so a caller that must report EC2-only coverage cannot recover it from the all-services map by key.
func (*Client) GetOnDemandFamilySeriesForAccount ¶
func (c *Client) GetOnDemandFamilySeriesForAccount(ctx context.Context, accountID, region string, lookbackDays int) (map[string][]DailyCost, error)
GetOnDemandFamilySeriesForAccount returns the daily on-demand EC2 cost per instance family (USD/hr) for one usage account over the lookback window. It issues one DAILY GetCostAndUsage grouped by INSTANCE_TYPE; the family is the part of the instance type before the first ".". Days a family has no spend are zero-filled, but only for days CE returns at all, so CE reporting lag does not zero every family. An empty result returns an empty map, not an error: the caller falls back to the non-family series.
func (*Client) GetOnDemandSeries ¶
func (c *Client) GetOnDemandSeries(ctx context.Context, region string, lookbackDays int) ([]DailyCost, error)
GetOnDemandSeries fetches daily on-demand EC2 compute cost for the given region over the past lookbackDays days from CE GetCostAndUsage and returns one DailyCost per returned calendar day, ordered oldest-to-newest with strictly increasing unique UTC days (map accumulation dedupes by date; lexicographic sort of "YYYY-MM-DD" keys is chronological). The last element is the most recent day CE has data for, which the ladder baseline's freshness check relies on.
CE query parameters:
- Granularity: DAILY (one entry per calendar day)
- Metric: UnblendedCost (actual on-demand billed rate; see onDemandMetric)
- Filter: SERVICE = EC2 compute AND PURCHASE_TYPE = On Demand Instances AND REGION = region (three-clause AND)
- Time window: [now-lookbackDays, now) exclusive end
Each day's total USD is divided by 24.0 to yield USD/hr. Dividing by 24 is derived from the DAILY granularity contract (one day = 24 hours), not a magic constant.
CE typically lags ~24-48h, so the returned series may be shorter than lookbackDays. The caller (baseline.GetUsageBaseline) enforces minimum length, in-window coverage, and freshness.
Fail-loud conditions (feedback_no_silent_fallbacks):
- Empty result: error.
- A result row missing the requested metric key (or with a nil Amount): error. Missing observations are not treated as measured zero.
- An all-zero series: error. When a filter or metric name is wrong, CE returns a complete, fresh, chronological series of $0 rows that would pass every downstream validation and make the engine size purchases from fabricated data. An account with genuinely zero on-demand EC2 spend for the whole lookback has nothing to ladder, so erroring is correct there too.
func (*Client) GetOnDemandSeriesForAccount ¶
func (c *Client) GetOnDemandSeriesForAccount(ctx context.Context, accountID, region string, lookbackDays int) ([]DailyCost, error)
GetOnDemandSeriesForAccount restricts residual observations to the usage account.
func (*Client) GetRICommitmentRate ¶
func (c *Client) GetRICommitmentRate(ctx context.Context, p RICommitmentRateParams) (float64, error)
GetRICommitmentRate returns r: commitment dollars per on-demand dollar for the USED part of a new Convertible EC2 Reserved Instance, derived from CE purchase recommendations. It costs one billed CE request per result page.
The CE cost fields are monthly USD for the whole recommended quantity and UpfrontCost is the one-time upfront for the term, so per detail:
eff = RecurringStandardMonthlyCost + UpfrontCost/(12*termYears) covered_od = eff + EstimatedMonthlySavingsAmount r = (AverageUtilization/100) * eff / covered_od
summed over the matching details (ratio of sums, so a one-instance detail does not outweigh a hundred-instance one). EstimatedMonthlySavingsPercentage and EstimatedMonthlyOnDemandCost are not used: the first is measured against all on-demand spend and the meaning of the second is not documented. Quantities are CE's reported ones, not the rounded-down counts of the parser; the rate does not depend on quantity, so rounding only reweights details negligibly.
Absent fields are ErrNoRICommitmentRate, never degraded to 0 (which would push r towards the utilization), with one payment-specific exception: UpfrontCost may be absent under no-upfront and the recurring charge under all-upfront. Unparseable, non-finite or negative values are plain errors, as is a non-positive r. r <= 1 holds by construction. Underestimating r only buys less, so every ambiguity resolves towards the lower r.
MANUAL VERIFICATION REQUIRED before relying on it with real money: the semantics of the CE cost fields are verified only against the SDK docs and a constructed CE-shaped fixture, not a live response.
func (*Client) GetRICoverageMap ¶
func (c *Client) GetRICoverageMap(ctx context.Context, lookbackDays int, regions []string) (PoolCoverageMap, error)
GetRICoverageMap fetches existing-RI coverage % and avg-running-instances over the last lookbackDays days, returning a map keyed by org-wide pool (no account dimension — matches the AWS console reservations-coverage report). Operators wiring the result back onto Recommendations should call ApplyCoverageMapToRecommendations rather than walking the map manually.
Non-RDS calls group by INSTANCE_TYPE alone (REGION + SERVICE in the Filter). RDS calls group by INSTANCE_TYPE + DEPLOYMENT_OPTION (REGION + SERVICE + DATABASE_ENGINE in the Filter) so the resulting keys split Single-AZ vs Multi-AZ pools, which have separate RI scopes.
Missing pools (no demand in the pool over the window) are omitted from the map; ApplyCoverageMapToRecommendations leaves rec.ExistingCoverageKnown false for those recs, which RI --target-coverage sizing drops (target-coverage-unknown) rather than treating them as 0% covered.
func (*Client) GetRIFeeUtilization ¶
func (c *Client) GetRIFeeUtilization(ctx context.Context, accountID, region string, lookbackDays int) ([]RIFeeUtilization, error)
GetRIFeeUtilization fetches per-subscription fee and hours for EC2 RIs of one linked account (and region, when non-empty) over the last lookbackDays. A group with all four fields absent is skipped; a partial, unparseable, non-finite or negative set is an error.
MANUAL VERIFICATION REQUIRED (mock-unprovable): the tests prove only the request shape. Whether LINKED_ACCOUNT matches the owner account or the usage account is not provable offline. Before trusting this under payer credentials, run GetReservationUtilization with LINKED_ACCOUNT=<id> under the payer credentials, repeat it under that account's own credentials, and compare.
func (*Client) GetRIUtilization ¶
func (c *Client) GetRIUtilization(ctx context.Context, lookbackDays int, region string) ([]RIUtilization, error)
GetRIUtilization fetches per-RI utilization from Cost Explorer for the last N days, scoped to EC2 RIs in region.
Without a Filter, GetReservationUtilization blends utilization across every reserved-resource type in the account (RDS, ElastiCache, OpenSearch, Redshift, standard EC2 RIs) and every region into one SUBSCRIPTION_ID-grouped number. Callers that read this as "EC2 convertible-RI utilization for this region" (e.g. the ladder ConvertibleRI layer) would then trigger real reshape/exchange decisions off an unrelated RI's utilization (PR #1361). region is optional: an empty string omits the REGION dimension, matching callers that haven't resolved a specific region.
func (*Client) GetRecommendations ¶
func (c *Client) GetRecommendations(ctx context.Context, params *common.RecommendationParams) ([]common.Recommendation, error)
GetRecommendations fetches Reserved Instance recommendations for any service.
func (*Client) GetRecommendationsForService ¶
func (c *Client) GetRecommendationsForService(ctx context.Context, service common.ServiceType) ([]common.Recommendation, error)
GetRecommendationsForService fetches recommendations for a specific service across the full Cartesian product of defaultDiscoveryTerms x defaultDiscoveryPaymentOptions (currently 2 x 3 = 6 Cost Explorer calls per service). Each call returns the recs for that single (term, payment) cell and the parser tags them with params.Term / params.PaymentOption so the resulting slice contains every combo for the user to choose from in the UI.
Failed details or scopes accompany surviving results as a typed diagnostic. If every API call fails, the ordinary error remains fatal.
func (*Client) GetSPCommitmentRate ¶
func (c *Client) GetSPCommitmentRate(ctx context.Context, p SPCommitmentRateParams) (float64, error)
GetSPCommitmentRate returns r: commitment dollars per on-demand dollar for the USED part of a new Savings Plan, derived from CE purchase recommendations.
EstimatedSavingsPercentage is measured against ALL applicable on-demand spend, not just the covered part, so it cannot be used. Per detail:
covered_od = EstimatedSPCost + EstimatedSavingsAmount r = (EstimatedAverageUtilization/100) * EstimatedSPCost / covered_od
summed over the matching details (ratio of sums; every detail shares the lookback so the hours cancel). The raw detail is parsed strictly: an absent field is ErrNoSPCommitmentRate (never degraded to 0, which would give r == utilization ~ 1:1), an unparseable or non-finite one is an error, and a non-positive r (zero utilization) is an error; r <= 1 holds by construction (non-negative savings, utilization <= 100).
MANUAL VERIFICATION REQUIRED before relying on it with real money: the semantics of the CE cost fields are verified only against the SDK docs and a constructed CE-shaped fixture, not a live response.
func (*Client) GetSPCoverageSummary ¶
func (c *Client) GetSPCoverageSummary(ctx context.Context, region string, lookbackDays int) (SPCoverageSummary, error)
GetSPCoverageSummary fetches Savings Plans coverage over the last lookbackDays days and returns a summary the ladder engine can consume.
Unlike GetSPUtilization, coverage is NOT plan-type-scoped, for two reasons:
- CE filter contract: GetSavingsPlansCoverage's Filter supports only the LINKED_ACCOUNT, REGION, SERVICE, and INSTANCE_FAMILY dimensions (see the GetSavingsPlansCoverageInput.Filter SDK doc). SAVINGS_PLANS_TYPE is a utilization-only dimension; passing it here fails with a ValidationException on every real call.
- Semantics: coverage measures the shared pool of SP-eligible on-demand spend that is covered by ANY Savings Plan, so attributing coverage to a single plan type is not meaningful - a dollar of eligible spend covered by a Compute SP is indistinguishable, coverage-wise, from one covered by an EC2 Instance SP.
region == "" means all regions (no Filter at all); a non-empty region adds a REGION dimension filter (a supported coverage dimension).
Coverage carries no pool key (unlike RI coverage's PoolCoverageMap) because SP commitment is dollar-denominated and applies cross-service; the return type is therefore a flat SPCoverageSummary rather than a keyed map.
lookbackDays must be positive. Zero or negative is an error - the caller is responsible for supplying the window (per the no-hardcoded-window rule).
An empty CE response (Days==0) is not an error: it means CE has no coverage data for the requested scope and window. Note that a nonexistent or misspelled region does NOT error either - CE simply matches nothing and the result is Days==0 with all pointer fields nil. Callers must read Days==0 as "no data for this scope", not "no SPs in the account", and check Days before dereferencing the pointer fields.
Concurrent calls are safe: fetchSPCoveragePage derives operation-local retry state from the client's shared retry policy, so callers never mutate the same retry counter.
func (*Client) GetSPCoveredSeries ¶
func (c *Client) GetSPCoveredSeries(ctx context.Context, region string, lookbackDays int) ([]DailyCost, error)
GetSPCoveredSeries returns the daily EC2 usage covered by Savings Plans in region over the past lookbackDays days, ordered oldest-to-newest with strictly increasing unique UTC days.
Units: CE's SpendCoveredBySavingsPlans is ON-DEMAND-EQUIVALENT dollars (the price the covered usage would have cost at on-demand rates), the same unit as the uncovered on-demand residual from GetOnDemandSeries. Each day's total is divided by 24 (DAILY granularity) to give USD/hr. It is NOT the SP commitment consumed; convert commitment to this unit with SPUtilizationSummary.CommitmentToOnDemandRatio.
A row whose Coverage block is nil counts as zero covered (precedent: spCoverageAccumulator.add; CE omits the block for days without activity). An empty response yields an empty series and no error: an account without Savings Plans legitimately has no covered usage, and the caller joins this with the residual series. A non-nil Coverage block without SpendCoveredBySavingsPlans, an undatable row, a duplicate date, or an unparseable amount fails loud.
func (*Client) GetSPUtilization ¶
func (c *Client) GetSPUtilization(ctx context.Context, planType types.SupportedSavingsPlansType, region string, lookbackDays int) (SPUtilizationSummary, error)
GetSPUtilization fetches Savings Plans utilization for one plan type over the last lookbackDays days.
planType scopes the CE call to a single SAVINGS_PLANS_TYPE dimension value (typed SDK enum, validated at the boundary; empty or unknown values are an explicit error). Utilization is per-commitment: the ladder holds two distinct SP layers, and a blended account-wide utilization number would mask under-utilization in one layer being offset by over-utilization in the other. region == "" means all regions (no REGION filter); a non-empty region is ANDed with the plan-type filter. Unlike coverage, utilization's Filter contract DOES support SAVINGS_PLANS_TYPE - see spUtilizationFilter.
GetSavingsPlansUtilization is a single-page API (the response has no NextToken); the Total field already aggregates the full window, so no pagination loop is needed.
lookbackDays must be positive.
Returned money fields (UsedCommitmentUSDPerHour, TotalCommitmentUSDPerHour) are CE's period totals divided by windowHours so callers receive consistent $/hr values. Nil fields mean CE returned no utilization data. As with coverage, a nonexistent or misspelled region (or a plan type with no commitments) does NOT error - CE matches nothing and every pointer field comes back nil. Callers must read all-nil as "no data for this scope", not "no SPs in the account".
MANUAL VERIFICATION REQUIRED (mock-unprovable): the plan-type filter relies on the parameter-enum -> dimension-vocabulary mapping in spPlanTypeDimensionValues ("COMPUTE_SP" -> "ComputeSavingsPlans", ...). A wrong dimension value does not error - CE silently matches nothing - so no unit test can prove the mapping. Before trusting this path in production, verify once against the real API: call GetDimensionValues with Context=SAVINGS_PLANS and Dimension=SAVINGS_PLANS_TYPE (or run one real GetSavingsPlansUtilization per plan type) and confirm the returned dimension values match the map.
Concurrent calls are safe: fetchSPUtilizationPage derives operation-local retry state from the client's shared retry policy, so callers never mutate the same retry counter.
func (*Client) GetSPUtilizationForAccount ¶
func (c *Client) GetSPUtilizationForAccount(ctx context.Context, planType types.SupportedSavingsPlansType, accountID, region string, lookbackDays int) (SPUtilizationSummary, error)
GetSPUtilizationForAccount is GetSPUtilization restricted to one linked account. Under payer credentials the unscoped call blends every account.
MANUAL VERIFICATION REQUIRED (mock-unprovable): the tests prove only the request shape. Whether LINKED_ACCOUNT matches the owner account or the usage account is not provable offline. Before trusting this under payer credentials, run GetSavingsPlansUtilization with LINKED_ACCOUNT=<id> under the payer credentials, repeat it under that account's own credentials, and compare.
func (*Client) SetInstanceTypePagerFactory ¶
func (c *Client) SetInstanceTypePagerFactory(f func() InstanceTypePager)
SetInstanceTypePagerFactory injects a pager factory for the instance-type SKU catalog. Must be called before the first GetRecommendations call. Intended for tests that need to verify the one-fetch-per-lifetime invariant without hitting AWS.
func (*Client) SetRecLookbackPeriod ¶
SetRecLookbackPeriod configures the LookbackPeriodInDays used by GetRecommendationsForService. Valid values: "7d", "30d", "60d". An empty value falls back to "7d" at call time; a non-empty unrecognized value makes the fetch fail.
type CostExplorerAPI ¶
type CostExplorerAPI interface {
GetReservationPurchaseRecommendation(ctx context.Context, params *costexplorer.GetReservationPurchaseRecommendationInput, optFns ...func(*costexplorer.Options)) (*costexplorer.GetReservationPurchaseRecommendationOutput, error)
GetSavingsPlansPurchaseRecommendation(ctx context.Context, params *costexplorer.GetSavingsPlansPurchaseRecommendationInput, optFns ...func(*costexplorer.Options)) (*costexplorer.GetSavingsPlansPurchaseRecommendationOutput, error)
GetReservationUtilization(ctx context.Context, params *costexplorer.GetReservationUtilizationInput, optFns ...func(*costexplorer.Options)) (*costexplorer.GetReservationUtilizationOutput, error)
GetReservationCoverage(ctx context.Context, params *costexplorer.GetReservationCoverageInput, optFns ...func(*costexplorer.Options)) (*costexplorer.GetReservationCoverageOutput, error)
GetSavingsPlansCoverage(ctx context.Context, params *costexplorer.GetSavingsPlansCoverageInput, optFns ...func(*costexplorer.Options)) (*costexplorer.GetSavingsPlansCoverageOutput, error)
GetSavingsPlansUtilization(ctx context.Context, params *costexplorer.GetSavingsPlansUtilizationInput, optFns ...func(*costexplorer.Options)) (*costexplorer.GetSavingsPlansUtilizationOutput, error)
// GetCostAndUsage fetches cost and usage data for arbitrary time periods
// and granularities. Added for the daily on-demand series adapter that
// powers GetUsageBaseline (L2).
GetCostAndUsage(ctx context.Context, params *costexplorer.GetCostAndUsageInput, optFns ...func(*costexplorer.Options)) (*costexplorer.GetCostAndUsageOutput, error)
}
CostExplorerAPI defines the interface for Cost Explorer operations.
type DailyCost ¶
type DailyCost struct {
// Date is the UTC calendar day (midnight UTC) this entry covers.
Date time.Time
// USDPerHour is the on-demand-equivalent spend averaged over the day.
USDPerHour float64
}
DailyCost is one calendar day of on-demand cost from CE GetCostAndUsage. Date is midnight UTC of the calendar day the entry covers; USDPerHour is the day's total unblended cost divided by 24. The ladder package maps this to its own DailyPoint type (identical fields) via a thin adapter; the type is duplicated because recommendations cannot import providers/aws/ladder (ladder already imports recommendations).
type DescribeInstanceTypesAPI ¶
type DescribeInstanceTypesAPI interface {
DescribeInstanceTypes(ctx context.Context, params *awsec2.DescribeInstanceTypesInput, optFns ...func(*awsec2.Options)) (*awsec2.DescribeInstanceTypesOutput, error)
}
DescribeInstanceTypesAPI is the subset of the EC2 client interface needed to build a DescribeInstanceTypes paginator. The production implementation is *ec2.Client; tests inject a stub.
type FamilyCoverage ¶
FamilyCoverage is the family-NU-aggregated view of coverage for an RDS instance family. TotalNU is the sum of (avg × NU(size)) across every size in the family that has CE coverage data; CoveredNU is the sum of (avg × NU(size) × pct/100). Pct can be derived as CoveredNU / TotalNU × 100 (callers do this inline).
type FamilyDropCounts ¶
type FamilyDropCounts struct {
// AlreadyAtTarget is the number of recs from families where the
// existing coverage already meets or exceeds the target (gap <= 0).
AlreadyAtTarget int
// NoNUSignal is the number of recs dropped because the family's
// AWS-recommended counts summed to zero NU (e.g. all recs at
// unknown/unrecognized sizes), so there is no scalable NU to apply
// the family target against. This is distinct from AlreadyAtTarget.
NoNUSignal int
// SizedToZero is the number of recs dropped because the family-wide
// scale factor produced a floor(0) count for that rec's size.
SizedToZero int
}
FamilyDropCounts holds the counts of family-level drops from ApplyFamilyNUSizingRDS, split by the two distinct drop reasons so the caller can record them into a DropSummary without importing cmd.
func ApplyFamilyNUSizingRDS ¶
func ApplyFamilyNUSizingRDS( recs []common.Recommendation, coverage PoolCoverageMap, targetPct float64, ) (sizedRDS, nonRDS []common.Recommendation, drops FamilyDropCounts)
ApplyFamilyNUSizingRDS replaces per-pool RI sizing with family-NU sizing for RDS recommendations. AWS's GetReservationPurchaseRecommendation already bundles size-flex demand within an instance family into a single recommendation at one size; per-pool sizing under-buys because it only sees that size's pool demand. Family-NU sizing rescales each RDS rec's Count so the family-wide NU sum matches the user's target across the whole family.
Algorithm:
- Group RDS recs by (region, family, engine, deployment).
- For each family: a. Compute family existing_pct = covered_NU / total_NU * 100 b. gap = targetPct − existing_pct (drop family if ≤ 0) c. target_NU_need = gap / 100 * total_NU d. current_rec_NU = Σ rec.Count × NU(rec.size) e. scale = target_NU_need / current_rec_NU f. Apply scale to each rec.Count and cost-bearing fields
- Recs scaled to zero are dropped (size flex left no room).
- Non-RDS recs are returned unchanged so callers can continue them through the per-pool sizing path.
Returns (sizedRDS, nonRDS, drops). When targetPct is outside (0,100] all recs are returned as nonRDS unchanged. When the CE coverage for a family has no NU signal (family.TotalNU <= 0), that family's recs are returned sized (as-is) in sizedRDS. When the family's AWS-recommended counts sum to zero NU (currentNU <= 0 — all recs at unrecognized sizes), those recs are dropped and recorded in drops.NoNUSignal; they are NOT passed through to the per-pool path.
type FamilyExpiryOptions ¶
type FamilyExpiryOptions struct {
// WindowDays is the rebuy window: active RIs ending within it are treated
// as expiring. <= 0 disables the expiry adjustment.
WindowDays int
// CoverageLookbackDays is the lookback, in days, of the Cost Explorer
// coverage average the caller passed in (the lookbackDays given to
// GetRICoverageMap). Coverage is an average over that period, so an RI that
// started inside it is not yet fully reflected. Visible active, non-expiring
// RIs that started inside it are credited as already-bought replacements.
// <= 0 credits none, which is exactly ApplyFamilyNUSizingRDSWithExpiry.
CoverageLookbackDays int
}
FamilyExpiryOptions configures ApplyFamilyNUSizingRDSWithExpiryOptions.
type FamilyExpiryReport ¶
type FamilyExpiryReport struct {
// ExpiringNU is the normalized units actually removed from family covered
// NU, summed over families (covered NU before minus after). It is below
// the expiring RIs' own NU when the min() cap, the partial-inventory cap
// or replacement credit absorbs part of it, and 0 when underutilized RIs
// leave covered NU unchanged.
ExpiringNU float64
// ReplacementNU is the normalized units of visible active, non-expiring RDS
// RIs that started inside the coverage lookback and so are not yet in the
// lagged coverage, summed over families that have expiring RIs. It is only
// non-zero when FamilyExpiryOptions.CoverageLookbackDays > 0.
ReplacementNU float64
// Unusable counts active RDS RIs expiring inside the window that could not
// be deducted: an unparsable instance class (NU 0) or a family key with no
// coverage family (e.g. an engine spelled differently from the coverage
// report). Callers must surface this; it never means "no expiry".
// It also counts expiring RIs of non-size-flexible engines (SQL Server):
// those are not lost, their expiry is handled per pool by
// AdjustExistingCoverageForExpiringCommitmentsWithCoverage, so for them it
// is informational, not a failure.
Unusable int
}
FamilyExpiryReport describes how commitment expiry was folded into family coverage by ApplyFamilyNUSizingRDSWithExpiry.
type IncompleteRecommendationsError ¶
IncompleteRecommendationsError accompanies survivors of an incomplete collection. Each cause represents one rejected detail or one failed collection scope.
func (*IncompleteRecommendationsError) Error ¶
func (e *IncompleteRecommendationsError) Error() string
func (*IncompleteRecommendationsError) Unwrap ¶
func (e *IncompleteRecommendationsError) Unwrap() []error
type InstanceTypePager ¶
type InstanceTypePager interface {
HasMorePages() bool
NextPage(ctx context.Context, optFns ...func(*awsec2.Options)) (*awsec2.DescribeInstanceTypesOutput, error)
}
InstanceTypePager defines the iteration contract for DescribeInstanceTypes pages. Production code uses ec2.NewDescribeInstanceTypesPaginator; tests inject a stub.
type PoolCoverage ¶
PoolCoverage captures the two CE coverage signals we use downstream: the share of historical demand already covered by existing reservations (Pct, 0-100) and the average concurrent-instances figure derived from TotalRunningHours over the lookback window (AvgInstancesPerHour).
AvgInstancesPerHour matches the "Total running hours / window hours" figure shown in the AWS console reservations-coverage report; it's what --target-coverage sizing now anchors on (linear in avg × gap%) so a pool's CUDly buy lines up with the same math operators see in the console CSV. Zero means CE returned no running hours for the pool over the window — sizing then falls back to rec.AverageInstancesUsedPerHour from the rec parser (per-account signal from GetReservationPurchaseRecommendation).
type PoolCoverageMap ¶
type PoolCoverageMap map[string]PoolCoverage
PoolCoverageMap maps a pool key to the (pct, avg) pair for that pool. Used by --target-coverage sizing to subtract existing commitments from the under-buy formula and to size linearly off the org-wide demand. Keys are org-wide (no account dimension) to match the AWS console's reservations-coverage report: non-RDS keys are "region:instance_type"; RDS keys are "region:instance_type:engine:deployment" so Single-AZ vs Multi-AZ pools stay distinct (a Single-AZ RI cannot cover a Multi-AZ instance).
type PoolExpiryOptions ¶
PoolExpiryOptions configures the per-pool (EC2 and other non-family) expiry deduction. It mirrors FamilyExpiryOptions, which does the same for RDS.
CoverageLookbackDays must be the lookbackDays given to the coverage fetch (GetRICoverageMap/GetEC2RICoverageMap). Coverage is a lookback average, so an RI bought inside that window is only partly in it. Active, non-expiring RIs in the same pool that started inside the window are credited against the expiring count of that pool. A value <= 0 credits none (the coverage fetch itself defaults a non-positive lookback to 30, so pass 30 here in that case).
The rule is conservative: it can under-buy, never over-buy. The credit is taken in full although lagged coverage already holds part of the new RI. A growth purchase in the same pool is indistinguishable from a replacement.
type RICommitmentRateParams ¶
type RICommitmentRateParams struct {
// AccountID restricts details to this (linked) account.
AccountID string
// Region restricts details to this region. CE reports it only on
// InstanceDetails.EC2InstanceDetails, possibly as a display name.
Region string
// Term is 1yr or 3yr; PaymentOption and LookbackPeriod use the same
// vocabulary as common.RecommendationParams.
Term string
PaymentOption string
LookbackPeriod string
}
RICommitmentRateParams selects the recommendation details a rate is derived from. All fields are required.
type RIFeeUtilization ¶
type RIFeeUtilization struct {
ReservedInstanceID string
TotalAmortizedFee float64
OnDemandCostOfRIHoursUsed float64
PurchasedHours float64
TotalActualHours float64
}
RIFeeUtilization is one subscription's reservation fee and usage, summed over the lookback window.
type RIUtilization ¶
type RIUtilization = common.RIUtilization
RIUtilization is an alias for common.RIUtilization so existing callers that import this package continue to compile without changes. The canonical definition lives in pkg/common so the Azure provider can return the same type without a cross-provider dependency.
type RateLimiter ¶
type RateLimiter struct {
// contains filtered or unexported fields
}
RateLimiter provides rate limiting with exponential backoff.
func NewRateLimiter ¶
func NewRateLimiter() *RateLimiter
NewRateLimiter creates a new rate limiter with default settings.
func NewRateLimiterWithOptions ¶
func NewRateLimiterWithOptions(baseDelay, maxDelay time.Duration, maxRetries int) *RateLimiter
NewRateLimiterWithOptions creates a rate limiter with custom settings.
func (*RateLimiter) GetRetryCount ¶
func (r *RateLimiter) GetRetryCount() int
GetRetryCount returns the current retry count.
func (*RateLimiter) ShouldRetry ¶
func (r *RateLimiter) ShouldRetry(err error) bool
ShouldRetry checks if we should retry based on error type and retry count. Only throttling and transient errors are retried.
type SPCommitmentRateParams ¶
type SPCommitmentRateParams struct {
// PlanType is COMPUTE_SP or EC2_INSTANCE_SP.
PlanType types.SupportedSavingsPlansType
// AccountID restricts details to this (linked) account.
AccountID string
// Region restricts details to this region. CE reports it on
// SavingsPlansDetails only for EC2 Instance SP; Compute SP details carry no
// region, so for COMPUTE_SP the result is the account-wide blend across
// EC2, Lambda and Fargate.
Region string
// Term is 1yr or 3yr; PaymentOption and LookbackPeriod use the same
// vocabulary as common.RecommendationParams.
Term string
PaymentOption string
LookbackPeriod string
}
SPCommitmentRateParams selects the recommendation details a rate is derived from. All fields are required.
type SPCoverageSummary ¶
type SPCoverageSummary struct {
// CoveragePct is covered / (covered + on-demand) * 100 over the window
// (0-100): the share of SP-ELIGIBLE spend actually covered by Savings
// Plans. CE's OnDemandCost is the UNCOVERED remainder, not the eligible
// total, so the denominator must be the sum of both fields - dividing
// by OnDemandCost alone overstates coverage and exceeds 100% as soon as
// real coverage passes 50%. Nil ONLY when the eligible total is zero
// (no SP-eligible activity in the window) or Days==0; a fully covered
// window (OnDemandCost==0, covered>0) yields &100.0, not nil.
CoveragePct *float64
// CoveredUSDPerHour normalizes reported SP-covered spend over the requested
// window, without adjusting for reporting completeness. Nil when Days==0.
CoveredUSDPerHour *float64
// OnDemandUSDPerHour normalizes reported uncovered SP-eligible spend over
// the same requested window. Nil when Days==0.
OnDemandUSDPerHour *float64
// EligibleUSDPerHour is CoveredUSDPerHour + OnDemandUSDPerHour, normalized
// over the requested window including zero-activity days. Nil when Days==0.
EligibleUSDPerHour *float64
// Days counts daily CE data points with a non-nil Coverage block.
// It does not indicate reporting completeness or change the rate divisor.
Days int
}
SPCoverageSummary is the Savings Plans coverage summary (optionally scoped to one region) over a lookback window.
Unlike PoolCoverageMap (keyed by region:instance_type), SP coverage carries no pool key. Savings Plans commitment is dollar-denominated and applies cross-service (and, for Compute SPs, cross-region), so there is no meaningful per-instance-type breakdown at the coverage level. Any region scoping happens via the CE Filter on the request instead, so the summary stays flat. Coverage is also NOT plan-type-scoped - see GetSPCoverageSummary for why (CE filter contract).
All money/percent fields are pointers so "CE returned no data" (nil) is distinguishable from "CE returned 0%" (pointer to 0.0). Days holds the number of daily data points that had a non-nil Coverage block in the CE response; zero means CE returned no coverage data at all for the window (e.g., no Savings Plans have ever been purchased in the account).
type SPUtilizationSummary ¶
type SPUtilizationSummary struct {
// UtilizationPct is the percentage of the SP commitment actually consumed
// over the window (0-100). Nil when CE returned no utilization data.
UtilizationPct *float64
// UsedCommitmentUSDPerHour is the average used SP commitment in $/hr.
// Nil when CE returned no data.
UsedCommitmentUSDPerHour *float64
// TotalCommitmentUSDPerHour is the average total SP commitment in $/hr.
// Nil when CE returned no data.
TotalCommitmentUSDPerHour *float64
// OnDemandCostEquivalentUSDPerHour is the average on-demand price of the
// usage the SP commitment covered, in $/hr (CE Savings.OnDemandCostEquivalent
// divided by windowHours). Nil when CE returned no savings data.
OnDemandCostEquivalentUSDPerHour *float64
}
SPUtilizationSummary is the Savings Plans utilization summary for one plan type (and optionally one region) over a lookback window. All money/percent fields are pointers so "CE returned no data" (nil) is distinguishable from "CE returned 0%".
UsedCommitmentUSDPerHour and TotalCommitmentUSDPerHour are derived by dividing the CE-reported period totals by windowHours so callers receive a consistent $/hr denomination, matching PoolCoverage.AvgInstancesPerHour.
func (SPUtilizationSummary) CommitmentToOnDemandRatio ¶
func (s SPUtilizationSummary) CommitmentToOnDemandRatio() (float64, error)
CommitmentToOnDemandRatio returns k = used commitment / on-demand-equivalent cost, computed from the window totals (not an average of daily ratios): one commitment dollar covers 1/k on-demand dollars of usage. k must satisfy 0 < k <= 1 (a plan cannot cost more than the usage it covers); k > 1 would shrink a commitment converted to on-demand terms (E/k) and over-buy, so it is an error. Missing or zero used/equivalent returns ErrNoSPUtilization.
Source Files
¶
- ce_paginate.go
- client.go
- collection_error.go
- collection_sp.go
- converters.go
- coverage.go
- expiry.go
- family_nu.go
- family_nu_rederive.go
- fetch_retry.go
- ondemand_family_series.go
- ondemand_series.go
- parser_ri.go
- parser_services.go
- parser_sp.go
- ratelimiter.go
- ri_commitment_rate.go
- ri_observed_rate.go
- sku.go
- sp_commitment_rate.go
- sp_coverage.go
- sp_coverage_series.go
- sp_observed_rate.go
- usage_history.go
- utilization.go