Skip to content

Commit 8adcd79

Browse files
authored
Merge pull request kubernetes#92268 from alculquicondor/ext-point-profile
Add profile label to framework_extension_point_duration_seconds
2 parents c6d2b22 + 698eda3 commit 8adcd79

File tree

6 files changed

+39
-24
lines changed

6 files changed

+39
-24
lines changed

pkg/scheduler/core/generic_scheduler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ func (g *genericScheduler) findNodesThatPassFilters(ctx context.Context, prof *p
500500
// We record Filter extension point latency here instead of in framework.go because framework.RunFilterPlugins
501501
// function is called for each node, whereas we want to have an overall latency for all nodes per scheduling cycle.
502502
// Note that this latency also includes latency for `addNominatedPods`, which calls framework.RunPreFilterAddPod.
503-
metrics.FrameworkExtensionPointDuration.WithLabelValues(runtime.Filter, statusCode.String()).Observe(metrics.SinceInSeconds(beginCheckNode))
503+
metrics.FrameworkExtensionPointDuration.WithLabelValues(runtime.Filter, statusCode.String(), prof.Name).Observe(metrics.SinceInSeconds(beginCheckNode))
504504
}()
505505

506506
// Stops searching for more nodes once the configured number of feasible nodes

pkg/scheduler/core/generic_scheduler_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,9 @@ func TestGenericScheduler(t *testing.T) {
710710
if err != nil {
711711
t.Fatal(err)
712712
}
713-
prof := &profile.Profile{Framework: fwk}
713+
prof := &profile.Profile{
714+
Framework: fwk,
715+
}
714716

715717
var pvcs []v1.PersistentVolumeClaim
716718
pvcs = append(pvcs, test.pvcs...)

pkg/scheduler/framework/runtime/framework.go

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ type frameworkImpl struct {
8585
informerFactory informers.SharedInformerFactory
8686

8787
metricsRecorder *metricsRecorder
88+
profileName string
8889

8990
preemptHandle framework.PreemptHandle
9091

@@ -127,6 +128,7 @@ type frameworkOptions struct {
127128
informerFactory informers.SharedInformerFactory
128129
snapshotSharedLister framework.SharedLister
129130
metricsRecorder *metricsRecorder
131+
profileName string
130132
podNominator framework.PodNominator
131133
extenders []framework.Extender
132134
runAllFilters bool
@@ -171,6 +173,13 @@ func WithRunAllFilters(runAllFilters bool) Option {
171173
}
172174
}
173175

176+
// WithProfileName sets the profile name.
177+
func WithProfileName(name string) Option {
178+
return func(o *frameworkOptions) {
179+
o.profileName = name
180+
}
181+
}
182+
174183
// withMetricsRecorder is only used in tests.
175184
func withMetricsRecorder(recorder *metricsRecorder) Option {
176185
return func(o *frameworkOptions) {
@@ -228,6 +237,7 @@ func NewFramework(r Registry, plugins *config.Plugins, args []config.PluginConfi
228237
eventRecorder: options.eventRecorder,
229238
informerFactory: options.informerFactory,
230239
metricsRecorder: options.metricsRecorder,
240+
profileName: options.profileName,
231241
runAllFilters: options.runAllFilters,
232242
}
233243
f.preemptHandle = &preemptHandle{
@@ -381,7 +391,7 @@ func (f *frameworkImpl) QueueSortFunc() framework.LessFunc {
381391
func (f *frameworkImpl) RunPreFilterPlugins(ctx context.Context, state *framework.CycleState, pod *v1.Pod) (status *framework.Status) {
382392
startTime := time.Now()
383393
defer func() {
384-
metrics.FrameworkExtensionPointDuration.WithLabelValues(preFilter, status.Code().String()).Observe(metrics.SinceInSeconds(startTime))
394+
metrics.FrameworkExtensionPointDuration.WithLabelValues(preFilter, status.Code().String(), f.profileName).Observe(metrics.SinceInSeconds(startTime))
385395
}()
386396
for _, pl := range f.preFilterPlugins {
387397
status = f.runPreFilterPlugin(ctx, pl, state, pod)
@@ -528,7 +538,7 @@ func (f *frameworkImpl) runFilterPlugin(ctx context.Context, pl framework.Filter
528538
func (f *frameworkImpl) RunPostFilterPlugins(ctx context.Context, state *framework.CycleState, pod *v1.Pod, filteredNodeStatusMap framework.NodeToStatusMap) (_ *framework.PostFilterResult, status *framework.Status) {
529539
startTime := time.Now()
530540
defer func() {
531-
metrics.FrameworkExtensionPointDuration.WithLabelValues(postFilter, status.Code().String()).Observe(metrics.SinceInSeconds(startTime))
541+
metrics.FrameworkExtensionPointDuration.WithLabelValues(postFilter, status.Code().String(), f.profileName).Observe(metrics.SinceInSeconds(startTime))
532542
}()
533543

534544
statuses := make(framework.PluginToStatus)
@@ -566,7 +576,7 @@ func (f *frameworkImpl) RunPreScorePlugins(
566576
) (status *framework.Status) {
567577
startTime := time.Now()
568578
defer func() {
569-
metrics.FrameworkExtensionPointDuration.WithLabelValues(preScore, status.Code().String()).Observe(metrics.SinceInSeconds(startTime))
579+
metrics.FrameworkExtensionPointDuration.WithLabelValues(preScore, status.Code().String(), f.profileName).Observe(metrics.SinceInSeconds(startTime))
570580
}()
571581
for _, pl := range f.preScorePlugins {
572582
status = f.runPreScorePlugin(ctx, pl, state, pod, nodes)
@@ -597,7 +607,7 @@ func (f *frameworkImpl) runPreScorePlugin(ctx context.Context, pl framework.PreS
597607
func (f *frameworkImpl) RunScorePlugins(ctx context.Context, state *framework.CycleState, pod *v1.Pod, nodes []*v1.Node) (ps framework.PluginToNodeScores, status *framework.Status) {
598608
startTime := time.Now()
599609
defer func() {
600-
metrics.FrameworkExtensionPointDuration.WithLabelValues(score, status.Code().String()).Observe(metrics.SinceInSeconds(startTime))
610+
metrics.FrameworkExtensionPointDuration.WithLabelValues(score, status.Code().String(), f.profileName).Observe(metrics.SinceInSeconds(startTime))
601611
}()
602612
pluginToNodeScores := make(framework.PluginToNodeScores, len(f.scorePlugins))
603613
for _, pl := range f.scorePlugins {
@@ -699,7 +709,7 @@ func (f *frameworkImpl) runScoreExtension(ctx context.Context, pl framework.Scor
699709
func (f *frameworkImpl) RunPreBindPlugins(ctx context.Context, state *framework.CycleState, pod *v1.Pod, nodeName string) (status *framework.Status) {
700710
startTime := time.Now()
701711
defer func() {
702-
metrics.FrameworkExtensionPointDuration.WithLabelValues(preBind, status.Code().String()).Observe(metrics.SinceInSeconds(startTime))
712+
metrics.FrameworkExtensionPointDuration.WithLabelValues(preBind, status.Code().String(), f.profileName).Observe(metrics.SinceInSeconds(startTime))
703713
}()
704714
for _, pl := range f.preBindPlugins {
705715
status = f.runPreBindPlugin(ctx, pl, state, pod, nodeName)
@@ -726,7 +736,7 @@ func (f *frameworkImpl) runPreBindPlugin(ctx context.Context, pl framework.PreBi
726736
func (f *frameworkImpl) RunBindPlugins(ctx context.Context, state *framework.CycleState, pod *v1.Pod, nodeName string) (status *framework.Status) {
727737
startTime := time.Now()
728738
defer func() {
729-
metrics.FrameworkExtensionPointDuration.WithLabelValues(bind, status.Code().String()).Observe(metrics.SinceInSeconds(startTime))
739+
metrics.FrameworkExtensionPointDuration.WithLabelValues(bind, status.Code().String(), f.profileName).Observe(metrics.SinceInSeconds(startTime))
730740
}()
731741
if len(f.bindPlugins) == 0 {
732742
return framework.NewStatus(framework.Skip, "")
@@ -760,7 +770,7 @@ func (f *frameworkImpl) runBindPlugin(ctx context.Context, bp framework.BindPlug
760770
func (f *frameworkImpl) RunPostBindPlugins(ctx context.Context, state *framework.CycleState, pod *v1.Pod, nodeName string) {
761771
startTime := time.Now()
762772
defer func() {
763-
metrics.FrameworkExtensionPointDuration.WithLabelValues(postBind, framework.Success.String()).Observe(metrics.SinceInSeconds(startTime))
773+
metrics.FrameworkExtensionPointDuration.WithLabelValues(postBind, framework.Success.String(), f.profileName).Observe(metrics.SinceInSeconds(startTime))
764774
}()
765775
for _, pl := range f.postBindPlugins {
766776
f.runPostBindPlugin(ctx, pl, state, pod, nodeName)
@@ -783,7 +793,7 @@ func (f *frameworkImpl) runPostBindPlugin(ctx context.Context, pl framework.Post
783793
func (f *frameworkImpl) RunReservePlugins(ctx context.Context, state *framework.CycleState, pod *v1.Pod, nodeName string) (status *framework.Status) {
784794
startTime := time.Now()
785795
defer func() {
786-
metrics.FrameworkExtensionPointDuration.WithLabelValues(reserve, status.Code().String()).Observe(metrics.SinceInSeconds(startTime))
796+
metrics.FrameworkExtensionPointDuration.WithLabelValues(reserve, status.Code().String(), f.profileName).Observe(metrics.SinceInSeconds(startTime))
787797
}()
788798
for _, pl := range f.reservePlugins {
789799
status = f.runReservePlugin(ctx, pl, state, pod, nodeName)
@@ -810,7 +820,7 @@ func (f *frameworkImpl) runReservePlugin(ctx context.Context, pl framework.Reser
810820
func (f *frameworkImpl) RunUnreservePlugins(ctx context.Context, state *framework.CycleState, pod *v1.Pod, nodeName string) {
811821
startTime := time.Now()
812822
defer func() {
813-
metrics.FrameworkExtensionPointDuration.WithLabelValues(unreserve, framework.Success.String()).Observe(metrics.SinceInSeconds(startTime))
823+
metrics.FrameworkExtensionPointDuration.WithLabelValues(unreserve, framework.Success.String(), f.profileName).Observe(metrics.SinceInSeconds(startTime))
814824
}()
815825
for _, pl := range f.unreservePlugins {
816826
f.runUnreservePlugin(ctx, pl, state, pod, nodeName)
@@ -836,7 +846,7 @@ func (f *frameworkImpl) runUnreservePlugin(ctx context.Context, pl framework.Unr
836846
func (f *frameworkImpl) RunPermitPlugins(ctx context.Context, state *framework.CycleState, pod *v1.Pod, nodeName string) (status *framework.Status) {
837847
startTime := time.Now()
838848
defer func() {
839-
metrics.FrameworkExtensionPointDuration.WithLabelValues(permit, status.Code().String()).Observe(metrics.SinceInSeconds(startTime))
849+
metrics.FrameworkExtensionPointDuration.WithLabelValues(permit, status.Code().String(), f.profileName).Observe(metrics.SinceInSeconds(startTime))
840850
}()
841851
pluginsWaitTime := make(map[string]time.Duration)
842852
statusCode := framework.Success

pkg/scheduler/framework/runtime/framework_test.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ const (
4848
testPlugin = "test-plugin"
4949
permitPlugin = "permit-plugin"
5050
bindPlugin = "bind-plugin"
51+
52+
testProfileName = "test-profile"
5153
)
5254

5355
// TestScoreWithNormalizePlugin implements ScoreWithNormalizePlugin interface.
@@ -1719,7 +1721,7 @@ func TestRecordingMetrics(t *testing.T) {
17191721
Unreserve: pluginSet,
17201722
}
17211723
recorder := newMetricsRecorder(100, time.Nanosecond)
1722-
f, err := newFrameworkWithQueueSortAndBind(r, plugins, emptyArgs, withMetricsRecorder(recorder))
1724+
f, err := newFrameworkWithQueueSortAndBind(r, plugins, emptyArgs, withMetricsRecorder(recorder), WithProfileName(testProfileName))
17231725
if err != nil {
17241726
t.Fatalf("Failed to create framework for testing: %v", err)
17251727
}
@@ -1824,7 +1826,7 @@ func TestRunBindPlugins(t *testing.T) {
18241826
}
18251827
plugins := &config.Plugins{Bind: pluginSet}
18261828
recorder := newMetricsRecorder(100, time.Nanosecond)
1827-
fwk, err := newFrameworkWithQueueSortAndBind(r, plugins, emptyArgs, withMetricsRecorder(recorder))
1829+
fwk, err := newFrameworkWithQueueSortAndBind(r, plugins, emptyArgs, withMetricsRecorder(recorder), WithProfileName(testProfileName))
18281830
if err != nil {
18291831
t.Fatal(err)
18301832
}
@@ -2073,16 +2075,17 @@ func collectAndCompareFrameworkMetrics(t *testing.T, wantExtensionPoint string,
20732075
t.Helper()
20742076
m := collectHistogramMetric(metrics.FrameworkExtensionPointDuration)
20752077

2076-
if len(m.Label) != 2 {
2077-
t.Fatalf("Unexpected number of label pairs, got: %v, want: 2", len(m.Label))
2078+
gotLabels := make(map[string]string, len(m.Label))
2079+
for _, p := range m.Label {
2080+
gotLabels[p.GetName()] = p.GetValue()
20782081
}
2079-
2080-
if *m.Label[0].Value != wantExtensionPoint {
2081-
t.Errorf("Unexpected extension point label, got: %q, want %q", *m.Label[0].Value, wantExtensionPoint)
2082+
wantLabels := map[string]string{
2083+
"extension_point": wantExtensionPoint,
2084+
"status": wantStatus.String(),
2085+
"profile": testProfileName,
20822086
}
2083-
2084-
if *m.Label[1].Value != wantStatus.String() {
2085-
t.Errorf("Unexpected status code label, got: %q, want %q", *m.Label[1].Value, wantStatus)
2087+
if diff := cmp.Diff(wantLabels, gotLabels); diff != "" {
2088+
t.Errorf("unexpected labels (-want,+got):\n%s", diff)
20862089
}
20872090

20882091
if *m.Histogram.SampleCount != 1 {

pkg/scheduler/metrics/metrics.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ var (
182182
Buckets: metrics.ExponentialBuckets(0.0001, 2, 12),
183183
StabilityLevel: metrics.ALPHA,
184184
},
185-
[]string{"extension_point", "status"})
185+
[]string{"extension_point", "status", "profile"})
186186

187187
PluginExecutionDuration = metrics.NewHistogramVec(
188188
&metrics.HistogramOpts{

pkg/scheduler/profile/profile.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ type Profile struct {
4747
func NewProfile(cfg config.KubeSchedulerProfile, frameworkFact FrameworkFactory, recorderFact RecorderFactory,
4848
opts ...frameworkruntime.Option) (*Profile, error) {
4949
recorder := recorderFact(cfg.SchedulerName)
50-
opts = append(opts, frameworkruntime.WithEventRecorder(recorder))
50+
opts = append(opts, frameworkruntime.WithEventRecorder(recorder), frameworkruntime.WithProfileName(cfg.SchedulerName))
5151
fwk, err := frameworkFact(cfg, opts...)
5252
if err != nil {
5353
return nil, err

0 commit comments

Comments
 (0)