...

Source file src/k8s.io/kubernetes/pkg/scheduler/framework/runtime/instrumented_plugins.go

Documentation: k8s.io/kubernetes/pkg/scheduler/framework/runtime

     1  /*
     2  Copyright 2023 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package runtime
    18  
    19  import (
    20  	"context"
    21  
    22  	v1 "k8s.io/api/core/v1"
    23  	compbasemetrics "k8s.io/component-base/metrics"
    24  	"k8s.io/kubernetes/pkg/scheduler/framework"
    25  )
    26  
    27  type instrumentedFilterPlugin struct {
    28  	framework.FilterPlugin
    29  
    30  	metric compbasemetrics.CounterMetric
    31  }
    32  
    33  var _ framework.FilterPlugin = &instrumentedFilterPlugin{}
    34  
    35  func (p *instrumentedFilterPlugin) Filter(ctx context.Context, state *framework.CycleState, pod *v1.Pod, nodeInfo *framework.NodeInfo) *framework.Status {
    36  	p.metric.Inc()
    37  	return p.FilterPlugin.Filter(ctx, state, pod, nodeInfo)
    38  }
    39  
    40  type instrumentedPreFilterPlugin struct {
    41  	framework.PreFilterPlugin
    42  
    43  	metric compbasemetrics.CounterMetric
    44  }
    45  
    46  var _ framework.PreFilterPlugin = &instrumentedPreFilterPlugin{}
    47  
    48  func (p *instrumentedPreFilterPlugin) PreFilter(ctx context.Context, state *framework.CycleState, pod *v1.Pod) (*framework.PreFilterResult, *framework.Status) {
    49  	result, status := p.PreFilterPlugin.PreFilter(ctx, state, pod)
    50  	if !status.IsSkip() {
    51  		p.metric.Inc()
    52  	}
    53  	return result, status
    54  }
    55  
    56  type instrumentedPreScorePlugin struct {
    57  	framework.PreScorePlugin
    58  
    59  	metric compbasemetrics.CounterMetric
    60  }
    61  
    62  var _ framework.PreScorePlugin = &instrumentedPreScorePlugin{}
    63  
    64  func (p *instrumentedPreScorePlugin) PreScore(ctx context.Context, state *framework.CycleState, pod *v1.Pod, nodes []*framework.NodeInfo) *framework.Status {
    65  	status := p.PreScorePlugin.PreScore(ctx, state, pod, nodes)
    66  	if !status.IsSkip() {
    67  		p.metric.Inc()
    68  	}
    69  	return status
    70  }
    71  
    72  type instrumentedScorePlugin struct {
    73  	framework.ScorePlugin
    74  
    75  	metric compbasemetrics.CounterMetric
    76  }
    77  
    78  var _ framework.ScorePlugin = &instrumentedScorePlugin{}
    79  
    80  func (p *instrumentedScorePlugin) Score(ctx context.Context, state *framework.CycleState, pod *v1.Pod, nodeName string) (int64, *framework.Status) {
    81  	p.metric.Inc()
    82  	return p.ScorePlugin.Score(ctx, state, pod, nodeName)
    83  }
    84  

View as plain text