mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-26 21:17:23 +00:00
Merge pull request #87458 from liu-cong/framework-metrics-new
Record overall Filter latency for all nodes in a scheduling cycle.
This commit is contained in:
commit
f409793eb6
@ -490,6 +490,15 @@ func (g *genericScheduler) findNodesThatPassFilters(ctx context.Context, state *
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
beginCheckNode := time.Now()
|
||||||
|
statusCode := framework.Success
|
||||||
|
defer func() {
|
||||||
|
// We record Filter extension point latency here instead of in framework.go because framework.RunFilterPlugins
|
||||||
|
// function is called for each node, whereas we want to have an overall latency for all nodes per scheduling cycle.
|
||||||
|
// Note that this latency also includes latency for `addNominatedPods`, which calls framework.RunPreFilterAddPod.
|
||||||
|
metrics.FrameworkExtensionPointDuration.WithLabelValues(framework.Filter, statusCode.String()).Observe(metrics.SinceInSeconds(beginCheckNode))
|
||||||
|
}()
|
||||||
|
|
||||||
// Stops searching for more nodes once the configured number of feasible nodes
|
// Stops searching for more nodes once the configured number of feasible nodes
|
||||||
// are found.
|
// are found.
|
||||||
workqueue.ParallelizeUntil(ctx, 16, len(allNodes), checkNode)
|
workqueue.ParallelizeUntil(ctx, 16, len(allNodes), checkNode)
|
||||||
@ -498,6 +507,7 @@ func (g *genericScheduler) findNodesThatPassFilters(ctx context.Context, state *
|
|||||||
|
|
||||||
filtered = filtered[:filteredLen]
|
filtered = filtered[:filteredLen]
|
||||||
if err := errCh.ReceiveError(); err != nil {
|
if err := errCh.ReceiveError(); err != nil {
|
||||||
|
statusCode = framework.Error
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return filtered, nil
|
return filtered, nil
|
||||||
|
@ -22,7 +22,7 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
v1 "k8s.io/api/core/v1"
|
"k8s.io/api/core/v1"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
"k8s.io/apimachinery/pkg/util/sets"
|
"k8s.io/apimachinery/pkg/util/sets"
|
||||||
@ -39,12 +39,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
// Filter is the name of the filter extension point.
|
||||||
|
Filter = "Filter"
|
||||||
// Specifies the maximum timeout a permit plugin can return.
|
// Specifies the maximum timeout a permit plugin can return.
|
||||||
maxTimeout time.Duration = 15 * time.Minute
|
maxTimeout time.Duration = 15 * time.Minute
|
||||||
preFilter = "PreFilter"
|
preFilter = "PreFilter"
|
||||||
preFilterExtensionAddPod = "PreFilterExtensionAddPod"
|
preFilterExtensionAddPod = "PreFilterExtensionAddPod"
|
||||||
preFilterExtensionRemovePod = "PreFilterExtensionRemovePod"
|
preFilterExtensionRemovePod = "PreFilterExtensionRemovePod"
|
||||||
filter = "Filter"
|
|
||||||
postFilter = "PostFilter"
|
postFilter = "PostFilter"
|
||||||
score = "Score"
|
score = "Score"
|
||||||
scoreExtensionNormalize = "ScoreExtensionNormalize"
|
scoreExtensionNormalize = "ScoreExtensionNormalize"
|
||||||
@ -353,10 +354,6 @@ func (f *framework) RunPreFilterExtensionAddPod(
|
|||||||
podToAdd *v1.Pod,
|
podToAdd *v1.Pod,
|
||||||
nodeInfo *schedulernodeinfo.NodeInfo,
|
nodeInfo *schedulernodeinfo.NodeInfo,
|
||||||
) (status *Status) {
|
) (status *Status) {
|
||||||
startTime := time.Now()
|
|
||||||
defer func() {
|
|
||||||
metrics.FrameworkExtensionPointDuration.WithLabelValues(preFilterExtensionAddPod, status.Code().String()).Observe(metrics.SinceInSeconds(startTime))
|
|
||||||
}()
|
|
||||||
for _, pl := range f.preFilterPlugins {
|
for _, pl := range f.preFilterPlugins {
|
||||||
if pl.PreFilterExtensions() == nil {
|
if pl.PreFilterExtensions() == nil {
|
||||||
continue
|
continue
|
||||||
@ -393,10 +390,6 @@ func (f *framework) RunPreFilterExtensionRemovePod(
|
|||||||
podToRemove *v1.Pod,
|
podToRemove *v1.Pod,
|
||||||
nodeInfo *schedulernodeinfo.NodeInfo,
|
nodeInfo *schedulernodeinfo.NodeInfo,
|
||||||
) (status *Status) {
|
) (status *Status) {
|
||||||
startTime := time.Now()
|
|
||||||
defer func() {
|
|
||||||
metrics.FrameworkExtensionPointDuration.WithLabelValues(preFilterExtensionRemovePod, status.Code().String()).Observe(metrics.SinceInSeconds(startTime))
|
|
||||||
}()
|
|
||||||
for _, pl := range f.preFilterPlugins {
|
for _, pl := range f.preFilterPlugins {
|
||||||
if pl.PreFilterExtensions() == nil {
|
if pl.PreFilterExtensions() == nil {
|
||||||
continue
|
continue
|
||||||
@ -434,10 +427,6 @@ func (f *framework) RunFilterPlugins(
|
|||||||
nodeInfo *schedulernodeinfo.NodeInfo,
|
nodeInfo *schedulernodeinfo.NodeInfo,
|
||||||
) PluginToStatus {
|
) PluginToStatus {
|
||||||
var firstFailedStatus *Status
|
var firstFailedStatus *Status
|
||||||
startTime := time.Now()
|
|
||||||
defer func() {
|
|
||||||
metrics.FrameworkExtensionPointDuration.WithLabelValues(filter, firstFailedStatus.Code().String()).Observe(metrics.SinceInSeconds(startTime))
|
|
||||||
}()
|
|
||||||
statuses := make(PluginToStatus)
|
statuses := make(PluginToStatus)
|
||||||
for _, pl := range f.filterPlugins {
|
for _, pl := range f.filterPlugins {
|
||||||
pluginStatus := f.runFilterPlugin(ctx, pl, state, pod, nodeInfo)
|
pluginStatus := f.runFilterPlugin(ctx, pl, state, pod, nodeInfo)
|
||||||
@ -468,7 +457,7 @@ func (f *framework) runFilterPlugin(ctx context.Context, pl FilterPlugin, state
|
|||||||
}
|
}
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
status := pl.Filter(ctx, state, pod, nodeInfo)
|
status := pl.Filter(ctx, state, pod, nodeInfo)
|
||||||
f.metricsRecorder.observePluginDurationAsync(filter, pl.Name(), status, metrics.SinceInSeconds(startTime))
|
f.metricsRecorder.observePluginDurationAsync(Filter, pl.Name(), status, metrics.SinceInSeconds(startTime))
|
||||||
return status
|
return status
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -893,30 +893,6 @@ func TestRecordingMetrics(t *testing.T) {
|
|||||||
wantExtensionPoint: "PreFilter",
|
wantExtensionPoint: "PreFilter",
|
||||||
wantStatus: Success,
|
wantStatus: Success,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: "PreFilterAddPod - Success",
|
|
||||||
action: func(f Framework) { f.RunPreFilterExtensionAddPod(context.Background(), state, pod, nil, nil) },
|
|
||||||
wantExtensionPoint: "PreFilterExtensionAddPod",
|
|
||||||
wantStatus: Success,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "PreFilterRemovePod - Success",
|
|
||||||
action: func(f Framework) { f.RunPreFilterExtensionRemovePod(context.Background(), state, pod, nil, nil) },
|
|
||||||
wantExtensionPoint: "PreFilterExtensionRemovePod",
|
|
||||||
wantStatus: Success,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "PreFilterRemovePod - Success",
|
|
||||||
action: func(f Framework) { f.RunPreFilterPlugins(context.Background(), state, pod) },
|
|
||||||
wantExtensionPoint: "PreFilter",
|
|
||||||
wantStatus: Success,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Filter - Success",
|
|
||||||
action: func(f Framework) { f.RunFilterPlugins(context.Background(), state, pod, nil) },
|
|
||||||
wantExtensionPoint: "Filter",
|
|
||||||
wantStatus: Success,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name: "PostFilter - Success",
|
name: "PostFilter - Success",
|
||||||
action: func(f Framework) { f.RunPostFilterPlugins(context.Background(), state, pod, nil, nil) },
|
action: func(f Framework) { f.RunPostFilterPlugins(context.Background(), state, pod, nil, nil) },
|
||||||
@ -973,27 +949,6 @@ func TestRecordingMetrics(t *testing.T) {
|
|||||||
wantExtensionPoint: "PreFilter",
|
wantExtensionPoint: "PreFilter",
|
||||||
wantStatus: Error,
|
wantStatus: Error,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: "PreFilterAddPod - Error",
|
|
||||||
action: func(f Framework) { f.RunPreFilterExtensionAddPod(context.Background(), state, pod, nil, nil) },
|
|
||||||
inject: injectedResult{PreFilterAddPodStatus: int(Error)},
|
|
||||||
wantExtensionPoint: "PreFilterExtensionAddPod",
|
|
||||||
wantStatus: Error,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "PreFilterRemovePod - Error",
|
|
||||||
action: func(f Framework) { f.RunPreFilterExtensionRemovePod(context.Background(), state, pod, nil, nil) },
|
|
||||||
inject: injectedResult{PreFilterRemovePodStatus: int(Error)},
|
|
||||||
wantExtensionPoint: "PreFilterExtensionRemovePod",
|
|
||||||
wantStatus: Error,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Filter - Error",
|
|
||||||
action: func(f Framework) { f.RunFilterPlugins(context.Background(), state, pod, nil) },
|
|
||||||
inject: injectedResult{FilterStatus: int(Error)},
|
|
||||||
wantExtensionPoint: "Filter",
|
|
||||||
wantStatus: Error,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name: "PostFilter - Error",
|
name: "PostFilter - Error",
|
||||||
action: func(f Framework) { f.RunPostFilterPlugins(context.Background(), state, pod, nil, nil) },
|
action: func(f Framework) { f.RunPostFilterPlugins(context.Background(), state, pod, nil, nil) },
|
||||||
|
Loading…
Reference in New Issue
Block a user