Skip to content

Commit 8f1b070

Browse files
committed
Add EstimateComponentsPlugins support to framework and related tests
Signed-off-by: seanlaii <qazwsx0939059006@gmail.com>
1 parent ce66819 commit 8f1b070

File tree

3 files changed

+294
-17
lines changed

3 files changed

+294
-17
lines changed

pkg/estimator/server/framework/interface.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ type Framework interface {
3838
// The Result contains code, reasons and error
3939
// it is merged from all plugins returned result codes
4040
RunEstimateReplicasPlugins(ctx context.Context, snapshot *schedcache.Snapshot, replicaRequirements *pb.ReplicaRequirements) (int32, *Result)
41+
// RunEstimateComponentsPlugins runs the set of configured EstimateComponentsPlugins
42+
// for estimating the maximum number of complete component sets based on the given components.
43+
// It returns an integer and a Result.
44+
// The integer represents the minimum calculated value of estimated component sets from each EstimateComponentsPlugin.
45+
// The Result contains code, reasons and error
46+
// it is merged from all plugins returned result codes
47+
RunEstimateComponentsPlugins(ctx context.Context, snapshot *schedcache.Snapshot, components []pb.Component) (int32, *Result)
4148
// TODO(wengyao04): we can add filter and score plugin extension points if needed in the future
4249
}
4350

@@ -58,6 +65,19 @@ type EstimateReplicasPlugin interface {
5865
Estimate(ctx context.Context, snapshot *schedcache.Snapshot, replicaRequirements *pb.ReplicaRequirements) (int32, *Result)
5966
}
6067

68+
// EstimateComponentsPlugin is an interface for component set estimation plugins.
69+
// These estimators are used to estimate the maximum number of complete component sets
70+
// for a given set of components with different replica requirements.
71+
type EstimateComponentsPlugin interface {
72+
Plugin
73+
// EstimateComponents is called for each MaxAvailableComponentSets request.
74+
// It returns an integer and a Result.
75+
// The integer represents the estimated number of complete component sets that can be scheduled.
76+
// The Result contains code, reasons and error
77+
// it is merged from all plugins returned result codes
78+
EstimateComponents(ctx context.Context, snapshot *schedcache.Snapshot, components []pb.Component) (int32, *Result)
79+
}
80+
6181
// Handle provides data and some tools that plugins can use. It is
6282
// passed to the plugin factories at the time of plugin initialization. Plugins
6383
// must store and use this handle to call framework functions.

pkg/estimator/server/framework/runtime/framework.go

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,20 @@ import (
3434
)
3535

3636
const (
37-
estimator = "Estimator"
37+
// estimator is the legacy label for replica estimation metrics.
38+
// Deprecated: Use estimateReplicasExtension instead. This will be removed in a future release.
39+
estimator = "Estimator"
40+
estimateReplicasExtension = "EstimateReplicas"
41+
estimateComponentsExtension = "EstimateComponents"
3842
)
3943

4044
// frameworkImpl implements the Framework interface and is responsible for initializing and running scheduler
4145
// plugins.
4246
type frameworkImpl struct {
43-
estimateReplicasPlugins []framework.EstimateReplicasPlugin
44-
clientSet clientset.Interface
45-
informerFactory informers.SharedInformerFactory
47+
estimateReplicasPlugins []framework.EstimateReplicasPlugin
48+
estimateComponentsPlugins []framework.EstimateComponentsPlugin
49+
clientSet clientset.Interface
50+
informerFactory informers.SharedInformerFactory
4651
}
4752

4853
var _ framework.Framework = &frameworkImpl{}
@@ -85,12 +90,16 @@ func NewFramework(r Registry, opts ...Option) (framework.Framework, error) {
8590
estimateReplicasPluginsList := reflect.ValueOf(&f.estimateReplicasPlugins).Elem()
8691
estimateReplicasType := estimateReplicasPluginsList.Type().Elem()
8792

93+
estimateComponentsPluginsList := reflect.ValueOf(&f.estimateComponentsPlugins).Elem()
94+
estimateComponentsType := estimateComponentsPluginsList.Type().Elem()
95+
8896
for name, factory := range r {
8997
p, err := factory(f)
9098
if err != nil {
9199
return nil, fmt.Errorf("failed to initialize plugin %q: %w", name, err)
92100
}
93101
addPluginToList(p, estimateReplicasType, &estimateReplicasPluginsList)
102+
addPluginToList(p, estimateComponentsType, &estimateComponentsPluginsList)
94103
}
95104
return f, nil
96105
}
@@ -119,7 +128,10 @@ func (frw *frameworkImpl) SharedInformerFactory() informers.SharedInformerFactor
119128
func (frw *frameworkImpl) RunEstimateReplicasPlugins(ctx context.Context, snapshot *schedcache.Snapshot, replicaRequirements *pb.ReplicaRequirements) (int32, *framework.Result) {
120129
startTime := time.Now()
121130
defer func() {
131+
// Emit metrics with both old and new labels for backward compatibility
132+
// TODO: Remove estimator label in a future release (deprecated)
122133
metrics.FrameworkExtensionPointDuration.WithLabelValues(estimator).Observe(utilmetrics.DurationInSeconds(startTime))
134+
metrics.FrameworkExtensionPointDuration.WithLabelValues(estimateReplicasExtension).Observe(utilmetrics.DurationInSeconds(startTime))
123135
}()
124136
var replica int32 = math.MaxInt32
125137
results := make(framework.PluginToResult)
@@ -141,6 +153,42 @@ func (frw *frameworkImpl) runEstimateReplicasPlugins(
141153
) (int32, *framework.Result) {
142154
startTime := time.Now()
143155
replica, ret := pl.Estimate(ctx, snapshot, replicaRequirements)
156+
// Emit metrics with both old and new labels for backward compatibility
157+
// TODO: Remove estimator label in a future release (deprecated)
144158
metrics.PluginExecutionDuration.WithLabelValues(pl.Name(), estimator).Observe(utilmetrics.DurationInSeconds(startTime))
159+
metrics.PluginExecutionDuration.WithLabelValues(pl.Name(), estimateReplicasExtension).Observe(utilmetrics.DurationInSeconds(startTime))
145160
return replica, ret
146161
}
162+
163+
// RunEstimateComponentsPlugins runs the set of configured EstimateComponentsPlugins
164+
// for estimating the maximum number of complete component sets based on the given components.
165+
// It returns an integer and a Result.
166+
// The integer represents the minimum calculated value of estimated component sets from each EstimateComponentsPlugin.
167+
func (frw *frameworkImpl) RunEstimateComponentsPlugins(ctx context.Context, snapshot *schedcache.Snapshot, components []pb.Component) (int32, *framework.Result) {
168+
startTime := time.Now()
169+
defer func() {
170+
metrics.FrameworkExtensionPointDuration.WithLabelValues(estimateComponentsExtension).Observe(utilmetrics.DurationInSeconds(startTime))
171+
}()
172+
var sets int32 = math.MaxInt32
173+
results := make(framework.PluginToResult)
174+
for _, pl := range frw.estimateComponentsPlugins {
175+
plSets, ret := frw.runEstimateComponentsPlugins(ctx, pl, snapshot, components)
176+
if (ret.IsSuccess() || ret.IsUnschedulable()) && plSets < sets {
177+
sets = plSets
178+
}
179+
results[pl.Name()] = ret
180+
}
181+
return sets, results.Merge()
182+
}
183+
184+
func (frw *frameworkImpl) runEstimateComponentsPlugins(
185+
ctx context.Context,
186+
pl framework.EstimateComponentsPlugin,
187+
snapshot *schedcache.Snapshot,
188+
components []pb.Component,
189+
) (int32, *framework.Result) {
190+
startTime := time.Now()
191+
sets, ret := pl.EstimateComponents(ctx, snapshot, components)
192+
metrics.PluginExecutionDuration.WithLabelValues(pl.Name(), estimateComponentsExtension).Observe(utilmetrics.DurationInSeconds(startTime))
193+
return sets, ret
194+
}

0 commit comments

Comments
 (0)