@@ -42,26 +42,26 @@ const (
42
42
scrapeTickInterval = time .Second / 3
43
43
)
44
44
45
- // Metric is a resource which observes the request load of a Revision and
45
+ // Decider is a resource which observes the request load of a Revision and
46
46
// recommends a number of replicas to run.
47
47
// +k8s:deepcopy-gen=true
48
- type Metric struct {
48
+ type Decider struct {
49
49
metav1.ObjectMeta
50
- Spec MetricSpec
51
- Status MetricStatus
50
+ Spec DeciderSpec
51
+ Status DeciderStatus
52
52
}
53
53
54
- // MetricSpec is the parameters in which the Revision should scaled.
55
- type MetricSpec struct {
54
+ // DeciderSpec is the parameters in which the Revision should scaled.
55
+ type DeciderSpec struct {
56
56
TargetConcurrency float64
57
57
}
58
58
59
- // MetricStatus is the current scale recommendation.
60
- type MetricStatus struct {
59
+ // DeciderStatus is the current scale recommendation.
60
+ type DeciderStatus struct {
61
61
DesiredScale int32
62
62
}
63
63
64
- // UniScaler records statistics for a particular Metric and proposes the scale for the Metric 's target based on those statistics.
64
+ // UniScaler records statistics for a particular Decider and proposes the scale for the Decider 's target based on those statistics.
65
65
type UniScaler interface {
66
66
// Record records the given statistics.
67
67
Record (context.Context , Stat )
@@ -70,15 +70,15 @@ type UniScaler interface {
70
70
// The returned boolean is true if and only if a proposal was returned.
71
71
Scale (context.Context , time.Time ) (int32 , bool )
72
72
73
- // Update reconfigures the UniScaler according to the MetricSpec .
74
- Update (MetricSpec ) error
73
+ // Update reconfigures the UniScaler according to the DeciderSpec .
74
+ Update (DeciderSpec ) error
75
75
}
76
76
77
77
// UniScalerFactory creates a UniScaler for a given PA using the given dynamic configuration.
78
- type UniScalerFactory func (* Metric , * DynamicConfig ) (UniScaler , error )
78
+ type UniScalerFactory func (* Decider , * DynamicConfig ) (UniScaler , error )
79
79
80
80
// StatsScraperFactory creates a StatsScraper for a given PA using the given dynamic configuration.
81
- type StatsScraperFactory func (* Metric ) (StatsScraper , error )
81
+ type StatsScraperFactory func (* Decider ) (StatsScraper , error )
82
82
83
83
// scalerRunner wraps a UniScaler and a channel for implementing shutdown behavior.
84
84
type scalerRunner struct {
@@ -87,21 +87,21 @@ type scalerRunner struct {
87
87
pokeCh chan struct {}
88
88
89
89
// mux guards access to metric
90
- mux sync.RWMutex
91
- metric Metric
90
+ mux sync.RWMutex
91
+ decider Decider
92
92
}
93
93
94
94
func (sr * scalerRunner ) getLatestScale () int32 {
95
95
sr .mux .RLock ()
96
96
defer sr .mux .RUnlock ()
97
- return sr .metric .Status .DesiredScale
97
+ return sr .decider .Status .DesiredScale
98
98
}
99
99
100
100
func (sr * scalerRunner ) updateLatestScale (new int32 ) bool {
101
101
sr .mux .Lock ()
102
102
defer sr .mux .Unlock ()
103
- if sr .metric .Status .DesiredScale != new {
104
- sr .metric .Status .DesiredScale = new
103
+ if sr .decider .Status .DesiredScale != new {
104
+ sr .decider .Status .DesiredScale = new
105
105
return true
106
106
}
107
107
return false
@@ -151,23 +151,23 @@ func NewMultiScaler(
151
151
}
152
152
}
153
153
154
- // Get return the current Metric .
155
- func (m * MultiScaler ) Get (ctx context.Context , namespace , name string ) (* Metric , error ) {
154
+ // Get return the current Decider .
155
+ func (m * MultiScaler ) Get (ctx context.Context , namespace , name string ) (* Decider , error ) {
156
156
key := NewMetricKey (namespace , name )
157
157
m .scalersMutex .RLock ()
158
158
defer m .scalersMutex .RUnlock ()
159
159
scaler , exists := m .scalers [key ]
160
160
if ! exists {
161
161
// This GroupResource is a lie, but unfortunately this interface requires one.
162
- return nil , errors .NewNotFound (kpa .Resource ("Metrics " ), key )
162
+ return nil , errors .NewNotFound (kpa .Resource ("Deciders " ), key )
163
163
}
164
164
scaler .mux .RLock ()
165
165
defer scaler .mux .RUnlock ()
166
- return (& scaler .metric ).DeepCopy (), nil
166
+ return (& scaler .decider ).DeepCopy (), nil
167
167
}
168
168
169
- // Create instantiates the desired Metric .
170
- func (m * MultiScaler ) Create (ctx context.Context , metric * Metric ) (* Metric , error ) {
169
+ // Create instantiates the desired Decider .
170
+ func (m * MultiScaler ) Create (ctx context.Context , metric * Decider ) (* Decider , error ) {
171
171
m .scalersMutex .Lock ()
172
172
defer m .scalersMutex .Unlock ()
173
173
key := NewMetricKey (metric .Namespace , metric .Name )
@@ -182,26 +182,26 @@ func (m *MultiScaler) Create(ctx context.Context, metric *Metric) (*Metric, erro
182
182
}
183
183
scaler .mux .RLock ()
184
184
defer scaler .mux .RUnlock ()
185
- return (& scaler .metric ).DeepCopy (), nil
185
+ return (& scaler .decider ).DeepCopy (), nil
186
186
}
187
187
188
- // Update applied the desired MetricSpec to a currently running Metric .
189
- func (m * MultiScaler ) Update (ctx context.Context , metric * Metric ) (* Metric , error ) {
190
- key := NewMetricKey (metric .Namespace , metric .Name )
188
+ // Update applied the desired DeciderSpec to a currently running Decider .
189
+ func (m * MultiScaler ) Update (ctx context.Context , decider * Decider ) (* Decider , error ) {
190
+ key := NewMetricKey (decider .Namespace , decider .Name )
191
191
m .scalersMutex .Lock ()
192
192
defer m .scalersMutex .Unlock ()
193
193
if scaler , exists := m .scalers [key ]; exists {
194
194
scaler .mux .Lock ()
195
195
defer scaler .mux .Unlock ()
196
- scaler .metric = * metric
197
- scaler .scaler .Update (metric .Spec )
198
- return metric , nil
196
+ scaler .decider = * decider
197
+ scaler .scaler .Update (decider .Spec )
198
+ return decider , nil
199
199
}
200
200
// This GroupResource is a lie, but unfortunately this interface requires one.
201
- return nil , errors .NewNotFound (kpa .Resource ("Metrics " ), key )
201
+ return nil , errors .NewNotFound (kpa .Resource ("Deciders " ), key )
202
202
}
203
203
204
- // Delete stops and removes a Metric .
204
+ // Delete stops and removes a Decider .
205
205
func (m * MultiScaler ) Delete (ctx context.Context , namespace , name string ) error {
206
206
key := NewMetricKey (namespace , name )
207
207
m .scalersMutex .Lock ()
@@ -213,7 +213,7 @@ func (m *MultiScaler) Delete(ctx context.Context, namespace, name string) error
213
213
return nil
214
214
}
215
215
216
- // Watch registers a singleton function to call when MetricStatus is updated.
216
+ // Watch registers a singleton function to call when DeciderStatus is updated.
217
217
func (m * MultiScaler ) Watch (fn func (string )) {
218
218
m .watcherMutex .Lock ()
219
219
defer m .watcherMutex .Unlock ()
@@ -247,21 +247,21 @@ func (m *MultiScaler) setScale(metricKey string, scale int32) bool {
247
247
return true
248
248
}
249
249
250
- func (m * MultiScaler ) createScaler (ctx context.Context , metric * Metric ) (* scalerRunner , error ) {
250
+ func (m * MultiScaler ) createScaler (ctx context.Context , decider * Decider ) (* scalerRunner , error ) {
251
251
252
- scaler , err := m .uniScalerFactory (metric , m .dynConfig )
252
+ scaler , err := m .uniScalerFactory (decider , m .dynConfig )
253
253
if err != nil {
254
254
return nil , err
255
255
}
256
256
257
257
stopCh := make (chan struct {})
258
258
runner := & scalerRunner {
259
- scaler : scaler ,
260
- stopCh : stopCh ,
261
- metric : * metric ,
262
- pokeCh : make (chan struct {}),
259
+ scaler : scaler ,
260
+ stopCh : stopCh ,
261
+ decider : * decider ,
262
+ pokeCh : make (chan struct {}),
263
263
}
264
- runner .metric .Status .DesiredScale = - 1
264
+ runner .decider .Status .DesiredScale = - 1
265
265
266
266
ticker := time .NewTicker (m .dynConfig .Current ().TickInterval )
267
267
@@ -284,9 +284,9 @@ func (m *MultiScaler) createScaler(ctx context.Context, metric *Metric) (*scaler
284
284
}
285
285
}()
286
286
287
- scraper , err := m .statsScraperFactory (metric )
287
+ scraper , err := m .statsScraperFactory (decider )
288
288
if err != nil {
289
- return nil , fmt .Errorf ("failed to create a stats scraper for metric %q: %v" , metric .Name , err )
289
+ return nil , fmt .Errorf ("failed to create a stats scraper for metric %q: %v" , decider .Name , err )
290
290
}
291
291
scraperTicker := time .NewTicker (scrapeTickInterval )
292
292
go func () {
@@ -310,7 +310,7 @@ func (m *MultiScaler) createScaler(ctx context.Context, metric *Metric) (*scaler
310
310
}
311
311
}()
312
312
313
- metricKey := NewMetricKey (metric .Namespace , metric .Name )
313
+ metricKey := NewMetricKey (decider .Namespace , decider .Name )
314
314
go func () {
315
315
for {
316
316
select {
@@ -350,7 +350,7 @@ func (m *MultiScaler) tickScaler(ctx context.Context, scaler UniScaler, scaleCha
350
350
}
351
351
}
352
352
353
- // RecordStat records some statistics for the given Metric .
353
+ // RecordStat records some statistics for the given Decider .
354
354
func (m * MultiScaler ) RecordStat (key string , stat Stat ) {
355
355
m .scalersMutex .RLock ()
356
356
defer m .scalersMutex .RUnlock ()
0 commit comments