Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add metrics about room termination #604

Merged
merged 1 commit into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
}
Loading