Skip to content

Commit

Permalink
feat: report metric with scheduler max matches
Browse files Browse the repository at this point in the history
  • Loading branch information
reinaldooli committed Jan 20, 2025
1 parent d2f577e commit 9c7f8c8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
15 changes: 15 additions & 0 deletions internal/core/worker/metricsreporter/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,17 @@ var (
},
})

schedulerMaxMatchesGaugeMetric = monitoring.CreateGaugeMetric(&monitoring.MetricOpts{
Namespace: monitoring.Namespace,
Subsystem: monitoring.SubsystemWorker,
Name: "max_matches",
Help: "The max number of matches that each Game Room can handle",
Labels: []string{
monitoring.LabelGame,
monitoring.LabelScheduler,
},
})

schedulerAutoscalePolicyReadyTargetGaugeMetric = monitoring.CreateGaugeMetric(&monitoring.MetricOpts{
Namespace: monitoring.Namespace,
Subsystem: monitoring.SubsystemWorker,
Expand Down Expand Up @@ -232,6 +243,10 @@ func reportTotalRunningMatches(game, schedulerName string, runningMatches int) {
runningMatchesGaugeMetric.WithLabelValues(game, schedulerName).Set(float64(runningMatches))
}

func reportSchedulerMaxMatches(game, schedulerName string, availableSlots int) {
schedulerMaxMatchesGaugeMetric.WithLabelValues(game, schedulerName).Set(float64(availableSlots))
}

func reportSchedulerPolicyReadyTarget(game, schedulerName string, readyTarget float64) {
schedulerAutoscalePolicyReadyTargetGaugeMetric.WithLabelValues(game, schedulerName).Set(readyTarget)
}
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ func (w *MetricsReporterWorker) reportGameRoomMetrics() {
func (w *MetricsReporterWorker) reportSchedulerMetrics() {
w.logger.Info("Reporting scheduler metrics")
w.reportSchedulerAutoscale()
w.reportSchedulerMaxMatches()
}

func (w *MetricsReporterWorker) reportSchedulerAutoscale() {
Expand All @@ -153,6 +154,13 @@ func (w *MetricsReporterWorker) reportSchedulerAutoscale() {
}
}

func (w *MetricsReporterWorker) reportSchedulerMaxMatches() {
if w.scheduler.MatchAllocation == nil {
return
}
reportSchedulerMaxMatches(w.scheduler.Game, w.scheduler.Name, w.scheduler.MatchAllocation.MaxMatches)
}

func (w *MetricsReporterWorker) reportPendingRooms() {
pendingRooms, err := w.roomStorage.GetRoomCountByStatus(w.workerContext, w.scheduler.Name, game_room.GameStatusPending)
if err != nil {
Expand Down

0 comments on commit 9c7f8c8

Please sign in to comment.