Skip to content

Commit aa555f5

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 d528e1f commit aa555f5

3 files changed

Lines changed: 18 additions & 6 deletions

File tree

‎cmd/main.go‎

Lines changed: 6 additions & 4 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"
@@ -95,9 +96,10 @@ type Config struct {
9596
// without a per-hour signal pass through unfiltered.
9697
MinPoolSize float64
9798
// RecLookbackPeriod controls the LookbackPeriodInDays passed to
98-
// GetReservationPurchaseRecommendation. Valid values: "7d", "30d", "60d".
99-
// A longer window smooths seasonal spikes; a shorter window weights recent
100-
// demand more heavily. Default "7d" matches the CE console default.
99+
// GetReservationPurchaseRecommendation. Valid values: "7d", "30d", "60d"
100+
// (recommendations.DefaultRecLookbackPeriod is the shared default).
101+
// A longer window smooths seasonal spikes; a shorter window weights
102+
// recent demand more heavily.
101103
RecLookbackPeriod string
102104
}
103105

@@ -176,7 +178,7 @@ func init() {
176178
"below this threshold. Useful with --target-coverage to skip tiny pools "+
177179
"that integer arithmetic forces above target (e.g. avg=1 cannot hit 80%%). "+
178180
"Default 0 = no filter.")
179-
rootCmd.Flags().StringVar(&toolCfg.RecLookbackPeriod, "rec-lookback-period", "7d",
181+
rootCmd.Flags().StringVar(&toolCfg.RecLookbackPeriod, "rec-lookback-period", recommendations.DefaultRecLookbackPeriod,
180182
"Historical window for GetReservationPurchaseRecommendation. "+
181183
"Valid values: 7d, 30d, 60d. A longer window smooths seasonal spikes; "+
182184
"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
@@ -423,7 +423,7 @@ func fetchRecommendationsForRegion(
423423

424424
lookback := cfg.RecLookbackPeriod
425425
if lookback == "" {
426-
lookback = "7d"
426+
lookback = recommendations.DefaultRecLookbackPeriod
427427
}
428428
params := common.RecommendationParams{
429429
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)
@@ -248,7 +258,7 @@ func (c *Client) fetchSingleComboRecs(ctx context.Context, service common.Servic
248258
}
249259
lookback := c.recLookbackPeriod
250260
if lookback == "" {
251-
lookback = "7d"
261+
lookback = DefaultRecLookbackPeriod
252262
}
253263
params := common.RecommendationParams{
254264
Service: service,

0 commit comments

Comments
 (0)