Skip to content

Commit

Permalink
Add scheduler plugin execution duration metric.
Browse files Browse the repository at this point in the history
Address comments

Sample metrics

Use rand.Intn and some cleanup
  • Loading branch information
liu-cong committed Nov 12, 2019
1 parent bcb171b commit af6a816
Show file tree
Hide file tree
Showing 8 changed files with 527 additions and 97 deletions.
2 changes: 2 additions & 0 deletions pkg/scheduler/framework/v1alpha1/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ go_library(
"cycle_state.go",
"framework.go",
"interface.go",
"metrics_recorder.go",
"registry.go",
"waiting_pods_map.go",
],
Expand All @@ -25,6 +26,7 @@ go_library(
"//staging/src/k8s.io/client-go/informers:go_default_library",
"//staging/src/k8s.io/client-go/kubernetes:go_default_library",
"//staging/src/k8s.io/client-go/util/workqueue:go_default_library",
"//staging/src/k8s.io/component-base/metrics:go_default_library",
"//vendor/k8s.io/klog:go_default_library",
"//vendor/sigs.k8s.io/yaml:go_default_library",
],
Expand Down
18 changes: 18 additions & 0 deletions pkg/scheduler/framework/v1alpha1/cycle_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ type StateKey string
type CycleState struct {
mx sync.RWMutex
storage map[StateKey]StateData
// if recordFrameworkMetrics is true, framework metrics will be recorded for this cycle.
recordFrameworkMetrics bool
}

// NewCycleState initializes a new CycleState and returns its pointer.
Expand All @@ -53,6 +55,22 @@ func NewCycleState() *CycleState {
}
}

// ShouldRecordFrameworkMetrics returns whether framework metrics should be recorded.
func (c *CycleState) ShouldRecordFrameworkMetrics() bool {
if c == nil {
return false
}
return c.recordFrameworkMetrics
}

// SetRecordFrameworkMetrics sets recordFrameworkMetrics to the given value.
func (c *CycleState) SetRecordFrameworkMetrics(flag bool) {
if c == nil {
return
}
c.recordFrameworkMetrics = flag
}

// Clone creates a copy of CycleState and returns its pointer. Clone returns
// nil if the context being cloned is nil.
func (c *CycleState) Clone() *CycleState {
Expand Down
Loading

0 comments on commit af6a816

Please sign in to comment.