Documentation
¶
Overview ¶
Package planstep resolves a purchase plan's current step into the recommendations it would buy. It reads only; nothing here attaches or executes, and no production caller exists yet (platform#631).
Index ¶
- Variables
- func CheckBoundBinding(plan *config.PurchasePlan) error
- func MatchesPlan(rec *config.RecommendationRecord, term int, wantPayment string, ...) (bool, error)
- func Precheck(plan *config.PurchasePlan) error
- func SizeSavingsPlan(out, stored *config.RecommendationRecord, share *big.Rat) (float64, error)
- type Resolver
- type Result
- type Source
- type Store
Constants ¶
This section is empty.
Variables ¶
var ErrBoundPlanMissingBinding = fmt.Errorf("%w: bound plan entry has no bound recommendations", ErrUnsupportedPlan)
ErrBoundPlanMissingBinding marks a bound plan entry with no bound recommendations, for example one stripped by an older binary's write (issue #1746). It wraps ErrUnsupportedPlan so attach records a failed step instead of buying by filter or retrying silently.
var ErrNoMatch = errors.New("no current recommendation matches the plan")
ErrNoMatch means no stored recommendation matches the plan right now. It is not a failure of the plan: the cache may be cold or mid-collect, so callers retry on a later tick and fail only after the grace window.
var ErrTargetMet = errors.New("the plan's cumulative target is already met")
ErrTargetMet means every matched recommendation already has this plan's cumulative target committed, so the step has nothing left to buy. It is distinct from ErrNoMatch (nothing matched, retry later).
var ErrUnsupportedPlan = errors.New("plan settings are not supported by recommendation resolution")
ErrUnsupportedPlan marks a plan whose settings Resolve cannot honor. Every such plan is refused before any recommendation is read, rather than resolved with the setting silently ignored.
Functions ¶
func CheckBoundBinding ¶
func CheckBoundBinding(plan *config.PurchasePlan) error
CheckBoundBinding refuses a plan where an enabled entry is bound (a "#" key, or any entry of a plan with the bound_groups marker) but has no bound identities. Precheck runs it, and so do plan writes that arm or widen auto-purchase; de-escalating writes skip it so a stripped plan can still be stopped.
func MatchesPlan ¶
func MatchesPlan(rec *config.RecommendationRecord, term int, wantPayment string, allowed map[string]struct{}) (bool, error)
MatchesPlan reports whether rec has the plan service's term, payment and a target account. An unrecognized payment is an error, never a loosened match.
func Precheck ¶
func Precheck(plan *config.PurchasePlan) error
Precheck refuses, with a plan-specific error, the plan settings Resolve does not apply: any Include*/Exclude*/MinCount filter on a service config (the plan-step request never sets them, so honoring them would buy something other than what the plan says), an armed multi-step plan with a Savings Plans service (platform#631 Q7), and an immediate ramp whose PercentPerStep is not 100 (an immediate ramp ignores that field when validated but Resolve sizes with it). An enabled service at target_coverage 0 is a plan that buys nothing: it is refused here, with its reason, instead of sizing to a quantity of 0 or failing every tick on an invalid-input error (#523).
func SizeSavingsPlan ¶
SizeSavingsPlan sizes a Savings Plans recommendation to share (an exact fraction of the stored hourly commitment) the way a plan step does: the hourly commitment is floored to whole cents, never rounded up. It rewrites out.Details (every other key untouched) and out.Count, and returns the ratio sized/stored; 0 means the share is below the one-cent minimum and out is left unchanged. The caller owns scaling the cost fields by the ratio.
Types ¶
type Resolver ¶
type Resolver interface {
Resolve(ctx context.Context, plan *config.PurchasePlan, accountIDs []string, step int,
baseline config.PlanRampBaseline, committed map[string]config.PlanRampQuantity) (Result, error)
}
Resolver resolves one step; the scheduler and the plan preview each supply their own read path behind it.
type Result ¶
type Result struct {
// Baseline is set only when step is 1: every matched count-based identity
// mapped to its base (the existing baseline entry, else step-1 shown),
// including recs that sized to 0. The caller freezes it; nil at step > 1.
Baseline config.PlanRampBaseline
// Recs are the recommendations the step would buy.
Recs []config.RecommendationRecord
// Skipped lists identities with no baseline at step > 1 (new recs, newly
// added accounts). They are never frozen at first sight: under-buy.
Skipped []string
// MissingBound lists bound identities (issue #1746) the strict read did
// not show, through churn or suppression. They are not bought this step.
MissingBound []string
// MismatchedBound lists bound identities the strict read showed but whose
// group rejected them (term, payment or account differs from the group's).
// They are not bought this step; an operator fixes the plan.
MismatchedBound []string
// Target and Committed total the judged identities' cumulative target and
// what the plan already holds. Set only with ErrTargetMet, for the no-op
// row's note.
Target int
Committed int
}
Result is what Resolve decided for one step.
func Resolve ¶
func Resolve(ctx context.Context, src Source, store Store, plan *config.PurchasePlan, accountIDs []string, step int, baseline config.PlanRampBaseline, committed map[string]config.PlanRampQuantity) (Result, error)
Resolve returns the recommendations the plan's step would buy: for each enabled plan service, the recs Opportunities shows (strict read, enabled providers) restricted to the plan's term, payment and target accounts, sized to the CUMULATIVE target and priced from the unsuppressed stored row. For a count rec: target = floor(base * Coverage * CumulativePercent(step) / 10000) and buy = clamp(target - committed, 0, shown). base is the frozen baseline entry, or at step 1 the shown count (post-suppression, never above demand); at step > 1 an identity without a baseline is skipped. baseline and committed are caller-supplied (this function does no extra store reads). accountIDs are the plan's target accounts; recs without an account are excluded. Every failure is returned; there is no unsized or over-show fallback. An empty result is ErrTargetMet only when a non-empty baseline exists and every baselined identity has its target committed (decided without `shown`); anything else, including a hidden identity with a gap or an empty step-1 read (no baseline returned), is ErrNoMatch. Savings Plans keep their per-step sizing (platform#631 Q7).
func ResolveStep ¶
func ResolveStep(ctx context.Context, r Resolver, plan *config.PurchasePlan, accountIDs []string, step int, baseline config.PlanRampBaseline, committed map[string]config.PlanRampQuantity, freeze func(config.PlanRampBaseline) (bool, error)) (Result, error)
ResolveStep is the one step-1 rule. At step 1 with no frozen baseline it freezes the baseline the step saw, including when nothing sized to a purchase: a base whose target floors to 0 still has to be frozen or step 2 would find no baseline and strand. A step that matched nothing is then judged again against the frozen baseline, so "target met" and "hidden" are told apart exactly as at any later step. freeze reports whether it stored the baseline; false means the ramp ledger cannot be trusted.
type Source ¶
type Source interface {
ListRecommendationsStrict(ctx context.Context, filter config.RecommendationFilter) ([]config.RecommendationRecord, error)
}
Source is the strict recommendation read (suppressions and account overrides applied; their read errors returned). *scheduler.Scheduler.
type Store ¶
type Store interface {
ListStoredRecommendations(ctx context.Context, filter config.RecommendationFilter) ([]config.RecommendationRecord, error)
GetGlobalConfig(ctx context.Context) (*config.GlobalConfig, error)
}
Store supplies the unsuppressed stored rows used for pricing and the enabled-providers setting. config.StoreInterface satisfies it.