Skip to content

Commit d46128a

Browse files
committed
Addressed review comments
- NodesTried and ApplicationsTried are tracked in the result structure - Local applicationsTried counter increments for each application tried; returns a total count when returning the result - add application tried counter field to SchedulerMetrics - partition context records both NodesTried and ApplicationsTried - added reset calls in ClusterContext.schedule() - fixed linting issues
1 parent bce7a1d commit d46128a

11 files changed

Lines changed: 183 additions & 244 deletions

pkg/metrics/scheduler.go

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ type SchedulerMetrics struct {
6969
tryNodeEvaluation prometheus.Histogram
7070
lock locking.RWMutex
7171
tryNodeCount *prometheus.CounterVec
72+
tryApplicationCount *prometheus.CounterVec
7273
}
7374

7475
// InitSchedulerMetrics to initialize scheduler metrics
@@ -79,6 +80,16 @@ func InitSchedulerMetrics() *SchedulerMetrics {
7980

8081
s.nodeResourceUsage = make(map[string]*prometheus.GaugeVec) // Note: This map might be updated at runtime
8182

83+
initCounterMetrics(s)
84+
initGaugeMetrics(s)
85+
initHistogramMetrics(s)
86+
registerSchedulerMetrics(s)
87+
88+
return s
89+
}
90+
91+
// initCounterMetrics initializes counter-based metrics
92+
func initCounterMetrics(s *SchedulerMetrics) {
8293
s.containerAllocation = prometheus.NewCounterVec(
8394
prometheus.CounterOpts{
8495
Namespace: Namespace,
@@ -95,6 +106,25 @@ func InitSchedulerMetrics() *SchedulerMetrics {
95106
Help: "Total number of application submissions. State of the attempt includes `new`, `accepted` and `rejected`.",
96107
}, []string{"result"})
97108

109+
s.tryNodeCount = prometheus.NewCounterVec(
110+
prometheus.CounterOpts{
111+
Namespace: Namespace,
112+
Subsystem: SchedulerSubsystem,
113+
Name: "trynode_count",
114+
Help: "Total number of nodes evaluated during scheduling cycle",
115+
}, nil)
116+
117+
s.tryApplicationCount = prometheus.NewCounterVec(
118+
prometheus.CounterOpts{
119+
Namespace: Namespace,
120+
Subsystem: SchedulerSubsystem,
121+
Name: "tryapplication_count",
122+
Help: "Total number of applications evaluated during scheduling cycle",
123+
}, nil)
124+
}
125+
126+
// initGaugeMetrics initializes gauge-based metrics
127+
func initGaugeMetrics(s *SchedulerMetrics) {
98128
s.application = prometheus.NewGaugeVec(
99129
prometheus.GaugeOpts{
100130
Namespace: Namespace,
@@ -110,7 +140,10 @@ func InitSchedulerMetrics() *SchedulerMetrics {
110140
Name: "node",
111141
Help: "Total number of nodes. State of the node includes `active` and `failed`.",
112142
}, []string{"state"})
143+
}
113144

145+
// initHistogramMetrics initializes histogram-based metrics
146+
func initHistogramMetrics(s *SchedulerMetrics) {
114147
s.schedulingLatency = prometheus.NewHistogram(
115148
prometheus.HistogramOpts{
116149
Namespace: Namespace,
@@ -169,15 +202,10 @@ func InitSchedulerMetrics() *SchedulerMetrics {
169202
Buckets: prometheus.ExponentialBuckets(0.0001, 10, 8),
170203
},
171204
)
205+
}
172206

173-
s.tryNodeCount = prometheus.NewCounterVec(
174-
prometheus.CounterOpts{
175-
Namespace: Namespace,
176-
Subsystem: SchedulerSubsystem,
177-
Name: "trynode_count",
178-
Help: "Total number of nodes evaluated during scheduling cycle",
179-
}, nil)
180-
// Register the metrics
207+
// registerSchedulerMetrics registers all scheduler metrics with Prometheus
208+
func registerSchedulerMetrics(s *SchedulerMetrics) {
181209
var metricsList = []prometheus.Collector{
182210
s.containerAllocation,
183211
s.applicationSubmission,
@@ -190,13 +218,13 @@ func InitSchedulerMetrics() *SchedulerMetrics {
190218
s.tryNodeEvaluation,
191219
s.tryPreemptionLatency,
192220
s.tryNodeCount,
221+
s.tryApplicationCount,
193222
}
194223
for _, metric := range metricsList {
195224
if err := prometheus.Register(metric); err != nil {
196225
log.Log(log.Metrics).Warn("failed to register metrics collector", zap.Error(err))
197226
}
198227
}
199-
return s
200228
}
201229

202230
// Reset all metrics that implement the Reset functionality.
@@ -207,6 +235,7 @@ func (m *SchedulerMetrics) Reset() {
207235
m.applicationSubmission.Reset()
208236
m.containerAllocation.Reset()
209237
m.tryNodeCount.Reset()
238+
m.tryApplicationCount.Reset()
210239
}
211240

212241
func SinceInSeconds(start time.Time) float64 {
@@ -284,8 +313,20 @@ func (m *SchedulerMetrics) GetSchedulingErrors() (int, error) {
284313
return -1, err
285314
}
286315

287-
func (m *SchedulerMetrics) IncTryNodeCount() {
288-
m.tryNodeCount.With(nil).Inc()
316+
func (m *SchedulerMetrics) AddTryNodeCount(count int64) {
317+
m.tryNodeCount.With(nil).Add(float64(count))
318+
}
319+
320+
func (m *SchedulerMetrics) ResetTryNodeCount() {
321+
m.tryNodeCount.Reset()
322+
}
323+
324+
func (m *SchedulerMetrics) AddTryApplicationCount(count int64) {
325+
m.tryApplicationCount.With(nil).Add(float64(count))
326+
}
327+
328+
func (m *SchedulerMetrics) ResetTryApplicationCount() {
329+
m.tryApplicationCount.Reset()
289330
}
290331

291332
func (m *SchedulerMetrics) GetTryNodeCount() (int64, error) {

pkg/metrics/scheduler_test.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -184,16 +184,6 @@ func TestTryNodeEvaluation(t *testing.T) {
184184
verifyHistogram(t, "trynode_evaluation_milliseconds", 60, 1)
185185
}
186186

187-
func TestTryNodeCount(t *testing.T) {
188-
sm = getSchedulerMetrics(t)
189-
defer unregisterMetrics()
190-
191-
sm.IncTryNodeCount()
192-
count, err := sm.GetTryNodeCount()
193-
assert.NilError(t, err)
194-
assert.Equal(t, int64(1), count)
195-
}
196-
197187
func getSchedulerMetrics(t *testing.T) *SchedulerMetrics {
198188
unregisterMetrics()
199189
return InitSchedulerMetrics()

pkg/scheduler/context.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ func (cc *ClusterContext) schedule() bool {
121121
// schedule each partition defined in the cluster
122122
activity := false
123123
scheduleCycleStart := time.Now()
124+
125+
// Reset scheduling cycle counters at the start of each cycle
126+
metrics.GetSchedulerMetrics().ResetTryNodeCount()
127+
metrics.GetSchedulerMetrics().ResetTryApplicationCount()
128+
124129
for _, psc := range cc.GetPartitionMapClone() {
125130
// if there are no resources in the partition just skip
126131
if psc.root.GetMaxResource() == nil {

pkg/scheduler/objects/allocation_result.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ type AllocationResult struct {
4141
NodeID string
4242
ReservedNodeID string
4343
CancelledReservations int
44+
NodesTried int64
45+
ApplicationsTried int64
4446
}
4547

4648
func (ar *AllocationResult) String() string {

0 commit comments

Comments
 (0)