Skip to content

Commit bee2aa5

Browse files
committed
refactor(coverage): hoist 7d default into shared DefaultRecLookbackPeriod constant
The "7d" default was hardcoded in three places after PR #992 added --rec-lookback-period (cmd flag default, cmd-side fallback in fetchRecommendationsForRegion, client-side fallback in fetchSingleComboRecs). Per feedback_no_hardcoded_magic_values.md, centralise it into recommendations.DefaultRecLookbackPeriod so the cmd flag default, the cmd-side fallback, and the client-side fallback all reference one source of truth, and a future change to the default only needs to flip one value. No behavioural change: same "7d" value, same call sites. refs #360
1 parent 77790f5 commit bee2aa5

3 files changed

Lines changed: 17 additions & 5 deletions

File tree

‎cmd/main.go‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/LeanerCloud/CUDly/pkg/common"
1212
"github.com/LeanerCloud/CUDly/pkg/provider"
1313
_ "github.com/LeanerCloud/CUDly/providers/aws"
14+
"github.com/LeanerCloud/CUDly/providers/aws/recommendations"
1415
"github.com/LeanerCloud/CUDly/providers/aws/services/ec2"
1516
"github.com/LeanerCloud/CUDly/providers/aws/services/elasticache"
1617
"github.com/LeanerCloud/CUDly/providers/aws/services/memorydb"
@@ -70,9 +71,10 @@ type Config struct {
7071
DryRun bool
7172
SkipConfirmation bool
7273
// RecLookbackPeriod controls the LookbackPeriodInDays passed to
73-
// GetReservationPurchaseRecommendation. Valid values: "7d", "30d", "60d".
74+
// GetReservationPurchaseRecommendation. Valid values: "7d", "30d", "60d"
75+
// (recommendations.DefaultRecLookbackPeriod is the shared default).
7476
// A longer window smooths seasonal spikes; a shorter window weights
75-
// recent demand more heavily. Default "7d" matches the CE console default.
77+
// recent demand more heavily.
7678
RecLookbackPeriod string
7779
}
7880

@@ -151,7 +153,7 @@ func init() {
151153
"below this threshold. Useful with --target-coverage to skip tiny pools "+
152154
"that integer arithmetic forces above target (e.g. avg=1 cannot hit 80%%). "+
153155
"Default 0 = no filter.")
154-
rootCmd.Flags().StringVar(&toolCfg.RecLookbackPeriod, "rec-lookback-period", "7d",
156+
rootCmd.Flags().StringVar(&toolCfg.RecLookbackPeriod, "rec-lookback-period", recommendations.DefaultRecLookbackPeriod,
155157
"Historical window for GetReservationPurchaseRecommendation. "+
156158
"Valid values: 7d, 30d, 60d. A longer window smooths seasonal spikes; "+
157159
"a shorter window weights recent demand more heavily. Default 7d.")

‎cmd/multi_service_helpers.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ func fetchRecommendationsForRegion(
425425

426426
lookback := cfg.RecLookbackPeriod
427427
if lookback == "" {
428-
lookback = "7d"
428+
lookback = recommendations.DefaultRecLookbackPeriod
429429
}
430430
params := common.RecommendationParams{
431431
Service: service,

‎providers/aws/recommendations/client.go‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ import (
2222
// payer org we have seen. Exceeding the cap returns a diagnostic error (issue #692).
2323
const maxRecommendationPages = 20
2424

25+
// DefaultRecLookbackPeriod is the LookbackPeriod string forwarded to
26+
// GetReservationPurchaseRecommendation when --rec-lookback-period is not
27+
// specified. Kept in the recommendations package so the cmd flag default,
28+
// the cmd-side fallback, and the client-side fallback all refer to a single
29+
// source of truth (avoids the magic-value duplication called out by
30+
// feedback_no_hardcoded_magic_values.md). Valid CE values are 7d/30d/60d
31+
// (see convertLookbackPeriodE); 7d matches the prior hardcoded behaviour
32+
// from before --rec-lookback-period existed.
33+
const DefaultRecLookbackPeriod = "7d"
34+
2535
// CostExplorerAPI defines the interface for Cost Explorer operations
2636
type CostExplorerAPI interface {
2737
GetReservationPurchaseRecommendation(ctx context.Context, params *costexplorer.GetReservationPurchaseRecommendationInput, optFns ...func(*costexplorer.Options)) (*costexplorer.GetReservationPurchaseRecommendationOutput, error)
@@ -254,7 +264,7 @@ func (c *Client) fetchSingleComboRecs(ctx context.Context, service common.Servic
254264
}
255265
lookback := c.recLookbackPeriod
256266
if lookback == "" {
257-
lookback = "7d"
267+
lookback = DefaultRecLookbackPeriod
258268
}
259269
params := common.RecommendationParams{
260270
Service: service,

0 commit comments

Comments
 (0)