@@ -61,8 +61,8 @@ type limiter interface {
61
61
}
62
62
63
63
type checker interface {
64
- RunCheckAndCapCount (ctx context.Context , currentCount int64 ) (sdk.ScalingAction , error )
65
- Group () string
64
+ runCheckAndCapCount (ctx context.Context , currentCount int64 ) (sdk.ScalingAction , error )
65
+ group () string
66
66
}
67
67
68
68
// Handler monitors a policy for changes and controls when them are sent for
@@ -107,39 +107,40 @@ type Handler struct {
107
107
}
108
108
109
109
type HandlerConfig struct {
110
- UpdatesChan chan * sdk.ScalingPolicy
111
- ErrChan chan <- error
112
- Policy * sdk.ScalingPolicy
113
- Log hclog.Logger
114
- TargetController targetpkg.Controller
115
- Limiter * Limiter
116
- DependencyGetter dependencyGetter
110
+ UpdatesChan chan * sdk.ScalingPolicy
111
+ ErrChan chan <- error
112
+ Policy * sdk.ScalingPolicy
113
+ Log hclog.Logger
114
+ TargetController targetpkg.Controller
115
+ Limiter * Limiter
116
+ DependencyGetter dependencyGetter
117
+
118
+ // Ent only field
117
119
HistoricalAPMGetter HistoricalAPMGetter
118
120
EvaluateAfter time.Duration
119
121
}
120
122
121
123
func NewPolicyHandler (config HandlerConfig ) (* Handler , error ) {
122
-
123
124
h := & Handler {
124
125
log : config .Log ,
125
126
mutators : []Mutator {
126
127
NomadAPMMutator {},
127
128
},
128
129
pm : config .DependencyGetter ,
129
- historicalAPMGetter : config .HistoricalAPMGetter ,
130
- evaluateAfter : config .EvaluateAfter ,
131
130
targetController : config .TargetController ,
132
131
updatesCh : config .UpdatesChan ,
133
132
policy : config .Policy ,
134
133
errChn : config .ErrChan ,
135
134
limiter : config .Limiter ,
136
135
stateLock : sync.RWMutex {},
137
136
state : StateIdle ,
137
+ historicalAPMGetter : config .HistoricalAPMGetter ,
138
+ evaluateAfter : config .EvaluateAfter ,
138
139
}
139
140
140
141
err := h .loadCheckRunners ()
141
142
if err != nil {
142
- return nil , fmt .Errorf ("unable to load the checks for the handler : %w" , err )
143
+ return nil , fmt .Errorf ("failed to load check handlers : %w" , err )
143
144
}
144
145
145
146
currentStatus , err := h .runTargetStatus ()
@@ -174,7 +175,8 @@ func NewPolicyHandler(config HandlerConfig) (*Handler, error) {
174
175
return h , nil
175
176
}
176
177
177
- // Convert the last event string.
178
+ // checkForOutOfBandEvents tries to determine if there has been any recent
179
+ // scaling events in case of the autoscaler going offline.
178
180
func checkForOutOfBandEvents (status * sdk.TargetStatus ) (int64 , error ) {
179
181
// If the target status includes a last event meta key, check for cooldown
180
182
// due to out-of-band events. This is also useful if the Autoscaler has
@@ -208,7 +210,7 @@ func (h *Handler) loadCheckRunners() error {
208
210
return fmt .Errorf ("failed to get APM for strategy %s: %w" , check .Strategy .Name , err )
209
211
}
210
212
211
- runner := NewCheckRunner (& CheckRunnerConfig {
213
+ runner := newCheckRunner (& CheckRunnerConfig {
212
214
Log : h .log .Named ("check_handler" ).With ("check" , check .Name ,
213
215
"source" , check .Source , "strategy" , check .Strategy .Name ),
214
216
StrategyRunner : s ,
@@ -437,13 +439,13 @@ func (h *Handler) calculateNewCount(ctx context.Context, currentCount int64) (sd
437
439
checkGroups := make (map [string ][]checkResult )
438
440
439
441
for _ , ch := range h .checkRunners {
440
- action , err := ch .RunCheckAndCapCount (ctx , currentCount )
442
+ action , err := ch .runCheckAndCapCount (ctx , currentCount )
441
443
if err != nil {
442
444
return sdk.ScalingAction {}, fmt .Errorf ("failed get count from metrics: %v" , err )
443
445
444
446
}
445
447
446
- g := ch .Group ()
448
+ g := ch .group ()
447
449
checkGroups [g ] = append (checkGroups [g ], checkResult {
448
450
action : & action ,
449
451
handler : ch ,
0 commit comments