mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-03 19:58:17 +00:00 
			
		
		
		
	Merge pull request #118025 from AxeZhan/score-metrics
feature(scheduler): plugin_evaluation_total metric support preScore/score
This commit is contained in:
		@@ -355,6 +355,12 @@ func NewFramework(ctx context.Context, r Registry, profile *config.KubeScheduler
 | 
				
			|||||||
		options.captureProfile(outputProfile)
 | 
							options.captureProfile(outputProfile)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						f.setInstrumentedPlugins()
 | 
				
			||||||
 | 
						return f, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// setInstrumentedPlugins initializes instrumented plugins from current plugins that frameworkImpl has.
 | 
				
			||||||
 | 
					func (f *frameworkImpl) setInstrumentedPlugins() {
 | 
				
			||||||
	// Cache metric streams for prefilter and filter plugins.
 | 
						// Cache metric streams for prefilter and filter plugins.
 | 
				
			||||||
	for i, pl := range f.preFilterPlugins {
 | 
						for i, pl := range f.preFilterPlugins {
 | 
				
			||||||
		f.preFilterPlugins[i] = &instrumentedPreFilterPlugin{
 | 
							f.preFilterPlugins[i] = &instrumentedPreFilterPlugin{
 | 
				
			||||||
@@ -369,7 +375,19 @@ func NewFramework(ctx context.Context, r Registry, profile *config.KubeScheduler
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return f, nil
 | 
						// Cache metric streams for prescore and score plugins.
 | 
				
			||||||
 | 
						for i, pl := range f.preScorePlugins {
 | 
				
			||||||
 | 
							f.preScorePlugins[i] = &instrumentedPreScorePlugin{
 | 
				
			||||||
 | 
								PreScorePlugin: f.preScorePlugins[i],
 | 
				
			||||||
 | 
								metric:         metrics.PluginEvaluationTotal.WithLabelValues(pl.Name(), metrics.PreScore, f.profileName),
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						for i, pl := range f.scorePlugins {
 | 
				
			||||||
 | 
							f.scorePlugins[i] = &instrumentedScorePlugin{
 | 
				
			||||||
 | 
								ScorePlugin: f.scorePlugins[i],
 | 
				
			||||||
 | 
								metric:      metrics.PluginEvaluationTotal.WithLabelValues(pl.Name(), metrics.Score, f.profileName),
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (f *frameworkImpl) SetPodNominator(n framework.PodNominator) {
 | 
					func (f *frameworkImpl) SetPodNominator(n framework.PodNominator) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -52,3 +52,32 @@ func (p *instrumentedPreFilterPlugin) PreFilter(ctx context.Context, state *fram
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	return result, status
 | 
						return result, status
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type instrumentedPreScorePlugin struct {
 | 
				
			||||||
 | 
						framework.PreScorePlugin
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						metric compbasemetrics.CounterMetric
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var _ framework.PreScorePlugin = &instrumentedPreScorePlugin{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (p *instrumentedPreScorePlugin) PreScore(ctx context.Context, state *framework.CycleState, pod *v1.Pod, nodes []*v1.Node) *framework.Status {
 | 
				
			||||||
 | 
						status := p.PreScorePlugin.PreScore(ctx, state, pod, nodes)
 | 
				
			||||||
 | 
						if !status.IsSkip() {
 | 
				
			||||||
 | 
							p.metric.Inc()
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return status
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type instrumentedScorePlugin struct {
 | 
				
			||||||
 | 
						framework.ScorePlugin
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						metric compbasemetrics.CounterMetric
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var _ framework.ScorePlugin = &instrumentedScorePlugin{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (p *instrumentedScorePlugin) Score(ctx context.Context, state *framework.CycleState, pod *v1.Pod, nodeName string) (int64, *framework.Status) {
 | 
				
			||||||
 | 
						p.metric.Inc()
 | 
				
			||||||
 | 
						return p.ScorePlugin.Score(ctx, state, pod, nodeName)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user