Skip to content

Commit

Permalink
feat: add metrics about room termination (#604)
Browse files Browse the repository at this point in the history
  • Loading branch information
reinaldooli authored Jan 2, 2024
1 parent 8326acd commit 30df220
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
12 changes: 10 additions & 2 deletions internal/core/operations/healthcontroller/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (ex *Executor) Execute(ctx context.Context, op *operation.Operation, defini
ex.tryEnsureCorrectRoomsOnStorage(ctx, op, logger, nonexistentGameRoomsIDs)
}

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

if len(expiredRooms) > 0 {
Expand Down Expand Up @@ -215,7 +215,10 @@ func (ex *Executor) ensureDesiredAmountOfInstances(ctx context.Context, op *oper
return nil
}

func (ex *Executor) findAvailableAndExpiredRooms(ctx context.Context, op *operation.Operation, existentGameRoomsInstancesMap map[string]*game_room.Instance) (availableRoomsIDs, expiredRoomsIDs []string) {
func (ex *Executor) findAvailableAndExpiredRooms(ctx context.Context, scheduler *entities.Scheduler, op *operation.Operation, existentGameRoomsInstancesMap map[string]*game_room.Instance) (availableRoomsIDs, expiredRoomsIDs []string) {
terminationTimedOutRooms := 0
terminatedRooms := 0

for gameRoomId, instance := range existentGameRoomsInstancesMap {
if instance.Status.Type == game_room.InstancePending {
availableRoomsIDs = append(availableRoomsIDs, gameRoomId)
Expand All @@ -234,8 +237,10 @@ func (ex *Executor) findAvailableAndExpiredRooms(ctx context.Context, op *operat
expiredRoomsIDs = append(expiredRoomsIDs, gameRoomId)
case ex.isRoomTerminatingExpired(room):
expiredRoomsIDs = append(expiredRoomsIDs, gameRoomId)
terminationTimedOutRooms += 1
case ex.isRoomStatus(room, game_room.GameStatusTerminated):
expiredRoomsIDs = append(expiredRoomsIDs, gameRoomId)
terminatedRooms += 1
case ex.isRoomStatus(room, game_room.GameStatusTerminating):
continue
case ex.isRoomStatus(room, game_room.GameStatusError):
Expand All @@ -245,6 +250,9 @@ func (ex *Executor) findAvailableAndExpiredRooms(ctx context.Context, op *operat
}
}

reportRoomsWithTerminationTimeout(scheduler.Game, scheduler.Name, terminationTimedOutRooms)
reportRoomsProperlyTerminated(scheduler.Game, scheduler.Name, terminatedRooms)

return availableRoomsIDs, expiredRoomsIDs
}

Expand Down
30 changes: 30 additions & 0 deletions internal/core/operations/healthcontroller/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,28 @@ var (
monitoring.LabelScheduler,
},
})

roomsWithTerminationTimeout = monitoring.CreateGaugeMetric(&monitoring.MetricOpts{
Namespace: monitoring.Namespace,
Subsystem: monitoring.SubsystemWorker,
Name: "rooms_with_termination_timeout",
Help: "Number of rooms that extrapolate the graceful termination period",
Labels: []string{
monitoring.LabelGame,
monitoring.LabelScheduler,
},
})

roomsProperlyTerminated = monitoring.CreateGaugeMetric(&monitoring.MetricOpts{
Namespace: monitoring.Namespace,
Subsystem: monitoring.SubsystemWorker,
Name: "rooms_properly_terminated",
Help: "Number of rooms that were properly terminated",
Labels: []string{
monitoring.LabelGame,
monitoring.LabelScheduler,
},
})
)

func reportDesiredNumberOfRooms(game, scheduler string, desired int) {
Expand All @@ -55,3 +77,11 @@ func reportDesiredNumberOfRooms(game, scheduler string, desired int) {
func reportCurrentNumberOfRooms(game, scheduler string, current int) {
currentNumberOfRoomsMetric.WithLabelValues(game, scheduler).Set(float64(current))
}

func reportRoomsWithTerminationTimeout(game, scheduler string, rooms int) {
roomsWithTerminationTimeout.WithLabelValues(game, scheduler).Set(float64(rooms))
}

func reportRoomsProperlyTerminated(game, scheduler string, rooms int) {
roomsProperlyTerminated.WithLabelValues(game, scheduler).Set(float64(rooms))
}

0 comments on commit 30df220

Please sign in to comment.