@@ -34,15 +34,20 @@ import (
3434)
3535
3636const (
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.
4246type 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
4853var _ 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
119128func (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