-
Notifications
You must be signed in to change notification settings - Fork 894
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: junqian <junqian@tencent.com>
- Loading branch information
1 parent
fd89085
commit 72ef4cc
Showing
7 changed files
with
170 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package metrics | ||
|
||
import ( | ||
"sync" | ||
"time" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
) | ||
|
||
// SchedulerSubsystem - subsystem name used by scheduler | ||
const SchedulerSubsystem = "karmada_scheduler" | ||
|
||
var ( | ||
scheduleAttempts = prometheus.NewCounterVec( | ||
prometheus.CounterOpts{ | ||
Subsystem: SchedulerSubsystem, | ||
Name: "schedule_attempts_total", | ||
Help: "Number of attempts to schedule resourceBinding", | ||
}, []string{"result", "scheduleType"}) | ||
|
||
e2eSchedulingLatency = prometheus.NewHistogramVec( | ||
prometheus.HistogramOpts{ | ||
Subsystem: SchedulerSubsystem, | ||
Name: "e2e_scheduling_duration_seconds", | ||
Help: "E2e scheduling latency in seconds", | ||
Buckets: prometheus.ExponentialBuckets(0.001, 2, 15), | ||
}, []string{"result", "scheduleType"}) | ||
|
||
schedulingAlgorithmLatency = prometheus.NewHistogramVec( | ||
prometheus.HistogramOpts{ | ||
Subsystem: SchedulerSubsystem, | ||
Name: "scheduling_algorithm_duration_seconds", | ||
Help: "Scheduling algorithm latency in seconds(exclude scale scheduler)", | ||
Buckets: prometheus.ExponentialBuckets(0.001, 2, 15), | ||
}, []string{"scheduleStep"}) | ||
|
||
schedulerQueueIncomingBindings = prometheus.NewCounterVec( | ||
prometheus.CounterOpts{ | ||
Subsystem: SchedulerSubsystem, | ||
Name: "queue_incoming_bindings_total", | ||
Help: "Number of bindings added to scheduling queues by event type.", | ||
}, []string{"event"}) | ||
|
||
metricsList = []prometheus.Collector{ | ||
scheduleAttempts, | ||
e2eSchedulingLatency, | ||
schedulingAlgorithmLatency, | ||
schedulerQueueIncomingBindings, | ||
} | ||
) | ||
|
||
var registerMetrics sync.Once | ||
|
||
// Register all metrics. | ||
func Register() { | ||
// Register the metrics. | ||
registerMetrics.Do(func() { | ||
RegisterMetrics(metricsList...) | ||
}) | ||
} | ||
|
||
// RegisterMetrics registers a list of metrics. | ||
// This function is exported because it is intended to be used by out-of-tree plugins to register their custom metrics. | ||
func RegisterMetrics(extraMetrics ...prometheus.Collector) { | ||
for _, metric := range extraMetrics { | ||
prometheus.MustRegister(metric) | ||
} | ||
} | ||
|
||
// SinceInSeconds gets the time since the specified start in seconds. | ||
func SinceInSeconds(start time.Time) float64 { | ||
return time.Since(start).Seconds() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package metrics | ||
|
||
import "time" | ||
|
||
const ( | ||
scheduledResult = "scheduled" | ||
errorResult = "error" | ||
) | ||
|
||
const ( | ||
// BindingAdd is the event when a new binding is added to API server. | ||
BindingAdd = "BindingAdd" | ||
// BindingUpdate is the event when a new binding is updated to API server. | ||
BindingUpdate = "BindingUpdate" | ||
// ScheduleAttemptFailure is the event when a schedule attempt fails. | ||
ScheduleAttemptFailure = "ScheduleAttemptFailure" | ||
// PolicyChanged means binding needs to be rescheduled for the policy changed | ||
PolicyChanged = "PolicyChanged" | ||
// ClusterNotReady means binding needs to be rescheduled for cluster is not ready | ||
ClusterNotReady = "ClusterNotReady" | ||
) | ||
|
||
const ( | ||
// ScheduleStepFilter means the step in generic scheduler to filter clusters | ||
ScheduleStepFilter = "Filter" | ||
// ScheduleStepScore means the step in generic scheduler to score clusters | ||
ScheduleStepScore = "Score" | ||
// ScheduleStepSelect means the step in generic scheduler to select clusters | ||
ScheduleStepSelect = "Select" | ||
// ScheduleStepAssignReplicas means the step in generic scheduler to assign replicas | ||
ScheduleStepAssignReplicas = "AssignReplicas" | ||
) | ||
|
||
// BindingSchedule can record a scheduling attempt and the duration | ||
// since `start`. | ||
func BindingSchedule(scheduleType string, duration float64, err error) { | ||
if err != nil { | ||
observeScheduleAttemptAndLatency(errorResult, scheduleType, duration) | ||
} else { | ||
observeScheduleAttemptAndLatency(scheduledResult, scheduleType, duration) | ||
} | ||
} | ||
|
||
func observeScheduleAttemptAndLatency(result, scheduleType string, duration float64) { | ||
e2eSchedulingLatency.WithLabelValues(result, scheduleType).Observe(duration) | ||
scheduleAttempts.WithLabelValues(result, scheduleType).Inc() | ||
} | ||
|
||
// ScheduleStep can record each scheduling step duration. | ||
func ScheduleStep(action string, startTime time.Time) { | ||
schedulingAlgorithmLatency.WithLabelValues(action).Observe(SinceInSeconds(startTime)) | ||
} | ||
|
||
// CountSchedulerBindings records the number of binding added to scheduling queues by event type. | ||
func CountSchedulerBindings(event string) { | ||
schedulerQueueIncomingBindings.WithLabelValues(event).Inc() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters