Skip to content

Commit

Permalink
Add desired number of rooms metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
reinaldooli committed Aug 8, 2023
1 parent e59aa14 commit c1a8fd6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
3 changes: 3 additions & 0 deletions internal/core/operations/healthcontroller/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ func (ex *Executor) Execute(ctx context.Context, op *operation.Operation, defini
}

availableRooms, expiredRooms := ex.findAvailableAndExpiredRooms(ctx, op, existentGameRoomsInstancesMap)
reportCurrentNumberOfRooms(scheduler.Game, scheduler.Name, len(availableRooms))

if len(expiredRooms) > 0 {
logger.Sugar().Infof("found %v expired rooms to be deleted", len(expiredRooms))
err = ex.enqueueRemoveExpiredRooms(ctx, op, logger, expiredRooms)
Expand All @@ -107,6 +109,7 @@ func (ex *Executor) Execute(ctx context.Context, op *operation.Operation, defini
logger.Error("error getting the desired number of rooms", zap.Error(err))
return err
}
reportDesiredNumberOfRooms(scheduler.Game, scheduler.Name, desiredNumberOfRooms)

err = ex.ensureDesiredAmountOfInstances(ctx, op, def, logger, len(availableRooms), desiredNumberOfRooms)
if err != nil {
Expand Down
35 changes: 35 additions & 0 deletions internal/core/operations/healthcontroller/metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package healthcontroller

import "github.com/topfreegames/maestro/internal/core/monitoring"

var (
desiredNumberOfRoomsMetric = monitoring.CreateGaugeMetric(&monitoring.MetricOpts{
Namespace: monitoring.Namespace,
Subsystem: monitoring.SubsystemWorker,
Name: "desired_rooms",
Help: "Desired number of rooms for a scheduler, based on the autoscaling policy",
Labels: []string{
monitoring.LabelGame,
monitoring.LabelScheduler,
},
})

currentNumberOfRoomsMetric = monitoring.CreateGaugeMetric(&monitoring.MetricOpts{
Namespace: monitoring.Namespace,
Subsystem: monitoring.SubsystemWorker,
Name: "current_rooms",
Help: "Current number of rooms for a scheduler",
Labels: []string{
monitoring.LabelGame,
monitoring.LabelScheduler,
},
})
)

func reportDesiredNumberOfRooms(game, scheduler string, desired int) {
desiredNumberOfRoomsMetric.WithLabelValues(game, scheduler).Set(float64(desired))
}

func reportCurrentNumberOfRooms(game, scheduler string, current int) {
currentNumberOfRoomsMetric.WithLabelValues(game, scheduler).Set(float64(current))
}

0 comments on commit c1a8fd6

Please sign in to comment.