Skip to content
Open
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: 7 additions & 5 deletions internal/adapters/runtime/kubernetes/game_room_convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,10 @@ func convertPodStatus(pod *v1.Pod) game_room.InstanceStatus {
switch pod.Status.Phase {
case v1.PodSucceeded:
// Completed pods should not be considered available; treat as terminating
zap.L().Info("pod phase -> instance status mapping", zap.String("pod", pod.Namespace+"/"+pod.Name), zap.String("phase", string(pod.Status.Phase)), zap.String("mappedTo", game_room.InstanceTerminating.String()))
zap.L().Debug("pod phase -> instance status mapping", zap.String("pod", pod.Namespace+"/"+pod.Name), zap.String("phase", string(pod.Status.Phase)), zap.String("mappedTo", game_room.InstanceTerminating.String()))
return game_room.InstanceStatus{Type: game_room.InstanceTerminating, Description: "PodSucceeded"}
case v1.PodFailed:
zap.L().Info("pod phase -> instance status mapping", zap.String("pod", pod.Namespace+"/"+pod.Name), zap.String("phase", string(pod.Status.Phase)), zap.String("mappedTo", game_room.InstanceError.String()))
zap.L().Warn("pod phase -> instance status mapping", zap.String("pod", pod.Namespace+"/"+pod.Name), zap.String("phase", string(pod.Status.Phase)), zap.String("mappedTo", game_room.InstanceError.String()))
return game_room.InstanceStatus{Type: game_room.InstanceError, Description: "PodFailed"}
case v1.PodUnknown:
// Unknown pods should not be treated as available
Expand Down Expand Up @@ -335,7 +335,7 @@ func convertPodStatus(pod *v1.Pod) game_room.InstanceStatus {
// If container is terminated, classify based on the termination reason
if state.Terminated != nil {
if state.Terminated.Reason == "Completed" || state.Terminated.ExitCode == 0 {
zap.L().Info(
zap.L().Debug(
"container terminated successfully; mapping to terminating",
zap.String("pod", pod.Namespace+"/"+pod.Name),
zap.String("container", containerStatus.Name),
Expand Down Expand Up @@ -385,11 +385,13 @@ func convertPodStatus(pod *v1.Pod) game_room.InstanceStatus {
// This allows us to catch container-level errors even for Running/Pending pods
switch pod.Status.Phase {
case v1.PodPending:
zap.L().Info("pod phase -> instance status mapping", zap.String("pod", pod.Namespace+"/"+pod.Name), zap.String("phase", string(pod.Status.Phase)), zap.String("mappedTo", game_room.InstancePending.String()))
zap.L().Debug("pod phase -> instance status mapping", zap.String("pod", pod.Namespace+"/"+pod.Name), zap.String("phase", string(pod.Status.Phase)), zap.String("mappedTo", game_room.InstancePending.String()))
return game_room.InstanceStatus{Type: game_room.InstancePending, Description: ""}
case v1.PodRunning:
zap.L().Info("pod phase -> instance status mapping", zap.String("pod", pod.Namespace+"/"+pod.Name), zap.String("phase", string(pod.Status.Phase)), zap.String("mappedTo", game_room.InstanceReady.String()))
zap.L().Debug("pod phase -> instance status mapping", zap.String("pod", pod.Namespace+"/"+pod.Name), zap.String("phase", string(pod.Status.Phase)), zap.String("mappedTo", game_room.InstanceReady.String()))
return game_room.InstanceStatus{Type: game_room.InstanceReady, Description: ""}
case "": // fresh pod, K8s hasn't set phase yet — treat as pending
return game_room.InstanceStatus{Type: game_room.InstancePending, Description: "PodPhaseNotSet"}
default:
// Handle any future pod phases that might be added to Kubernetes
zap.L().Warn("unexpected pod phase; mapping to error", zap.String("pod", pod.Namespace+"/"+pod.Name), zap.String("phase", string(pod.Status.Phase)), zap.String("mappedTo", game_room.InstanceError.String()))
Expand Down
96 changes: 96 additions & 0 deletions internal/adapters/runtime/kubernetes/game_room_convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,102 @@ func TestConvertPodStatus(t *testing.T) {
Description: "RunContainerError: failed to find executable",
},
},
"empty phase fresh pod": {
pod: &v1.Pod{
Status: v1.PodStatus{
Phase: "",
},
},
expectedStatus: game_room.InstanceStatus{
Type: game_room.InstancePending,
Description: "PodPhaseNotSet",
},
},
"pod failed": {
pod: &v1.Pod{
Status: v1.PodStatus{
Phase: v1.PodFailed,
},
},
expectedStatus: game_room.InstanceStatus{
Type: game_room.InstanceError,
Description: "PodFailed",
},
},
"pod succeeded": {
pod: &v1.Pod{
Status: v1.PodStatus{
Phase: v1.PodSucceeded,
},
},
expectedStatus: game_room.InstanceStatus{
Type: game_room.InstanceTerminating,
Description: "PodSucceeded",
},
},
"pod unknown": {
pod: &v1.Pod{
Status: v1.PodStatus{
Phase: v1.PodUnknown,
},
},
expectedStatus: game_room.InstanceStatus{
Type: game_room.InstanceError,
Description: "PodUnknown",
},
},
"pod being deleted": {
pod: &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
DeletionTimestamp: &metav1.Time{Time: time.Now()},
},
Status: v1.PodStatus{
Phase: v1.PodRunning,
},
},
expectedStatus: game_room.InstanceStatus{
Type: game_room.InstanceTerminating,
},
},
"container terminated successfully": {
pod: &v1.Pod{
Status: v1.PodStatus{
Phase: v1.PodRunning,
ContainerStatuses: []v1.ContainerStatus{
{State: v1.ContainerState{Terminated: &v1.ContainerStateTerminated{Reason: "Completed", ExitCode: 0}}},
},
},
},
expectedStatus: game_room.InstanceStatus{
Type: game_room.InstanceTerminating,
Description: "Completed",
},
},
"container terminated with error": {
pod: &v1.Pod{
Status: v1.PodStatus{
Phase: v1.PodRunning,
ContainerStatuses: []v1.ContainerStatus{
{State: v1.ContainerState{Terminated: &v1.ContainerStateTerminated{Reason: "OOMKilled", ExitCode: 137}}},
},
},
},
expectedStatus: game_room.InstanceStatus{
Type: game_room.InstanceError,
Description: "OOMKilled",
},
},
"running without ready condition": {
pod: &v1.Pod{
Status: v1.PodStatus{
Phase: v1.PodRunning,
},
},
expectedStatus: game_room.InstanceStatus{
Type: game_room.InstanceReady,
Description: "",
},
},
}

for name, test := range cases {
Expand Down
2 changes: 1 addition & 1 deletion internal/api/handlers/operations_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func (h *OperationsHandler) CancelOperation(ctx context.Context, request *api.Ca

func (h *OperationsHandler) GetOperation(ctx context.Context, request *api.GetOperationRequest) (*api.GetOperationResponse, error) {
handlerLogger := h.logger.With(zap.String(logs.LogFieldSchedulerName, request.GetSchedulerName()), zap.String(logs.LogFieldOperationID, request.GetOperationId()))
handlerLogger.Info("received request to get operation by id")
handlerLogger.Debug("received request to get operation by id")
op, _, err := h.operationManager.GetOperation(ctx, request.GetSchedulerName(), request.GetOperationId())
if err != nil {
if errors.Is(err, portsErrors.ErrNotFound) {
Expand Down
12 changes: 6 additions & 6 deletions internal/core/operations/healthcontroller/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (ex *Executor) Execute(ctx context.Context, op *operation.Operation, defini
reportCurrentNumberOfRooms(scheduler.Game, scheduler.Name, len(availableRooms))

if len(expiredRooms) > 0 {
logger.Sugar().Infof("found %v expired rooms to be deleted", len(expiredRooms))
logger.Sugar().Debugf("found %v expired rooms to be deleted", len(expiredRooms))
err = ex.enqueueRemoveExpiredRooms(ctx, op, logger, expiredRooms)
if err != nil {
logger.Error("could not enqueue operation to delete expired rooms", zap.Error(err))
Expand Down Expand Up @@ -187,7 +187,7 @@ func (ex *Executor) tryEnsureCorrectRoomsOnStorage(ctx context.Context, op *oper
continue
}

logger.Sugar().Infof("removed nonexistent room from instance and game room storage: %s", gameRoomID)
logger.Sugar().Warnf("removed nonexistent room from instance and game room storage: %s", gameRoomID)
}
}

Expand Down Expand Up @@ -228,7 +228,7 @@ func (ex *Executor) ensureDesiredAmountOfInstances(ctx context.Context, op *oper
msgToAppend = "current amount of rooms is equal to desired amount, no changes needed"
}

logger.Info(msgToAppend)
logger.Debug(msgToAppend)
ex.setTookAction(def, tookAction)
if tookAction {
ex.operationManager.AppendOperationEventToExecutionHistory(ctx, op, msgToAppend)
Expand Down Expand Up @@ -310,7 +310,7 @@ func (ex *Executor) enqueueRemoveExpiredRooms(ctx context.Context, op *operation
}

msgToAppend := fmt.Sprintf("created operation (id: %s) to remove expired %v rooms.", removeOperation.ID, len(roomsIDs))
logger.Info(msgToAppend)
logger.Debug(msgToAppend)
ex.operationManager.AppendOperationEventToExecutionHistory(ctx, op, msgToAppend)

return nil
Expand Down Expand Up @@ -445,7 +445,7 @@ func GetDesiredNumberOfRooms(
}
}

logger.Sugar().Infof("[GetDesiredNumberOfRooms] desired %d, current %d, isRollingUpdating %t", desiredNumber, len(availableRooms), isRollingUpdating)
logger.Sugar().Debugf("[GetDesiredNumberOfRooms] desired %d, current %d, isRollingUpdating %t", desiredNumber, len(availableRooms), isRollingUpdating)
return
}

Expand Down Expand Up @@ -510,7 +510,7 @@ func IsRollingUpdating(
}

if schedulerCache[room.Version].IsMajorVersion(scheduler) {
logger.Info(
logger.Debug(
"Rolling update detected, system has rooms with a major version of difference",
zap.String("activeScheduler", scheduler.Spec.Version),
zap.String("nonActiveSchedulerFound", room.Version),
Expand Down
6 changes: 5 additions & 1 deletion internal/core/operations/rooms/add/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,11 @@ func (ex *Executor) Execute(ctx context.Context, op *operation.Operation, defini
ex.operationManager.AppendOperationEventToExecutionHistory(ctx, op, ErrMajorityRooms.Error())
return ErrMajorityRooms
default:
executionLogger.Sugar().Infof("added rooms successfully with errors: %d and success: %d of amount: %d", errCount, successCount, amount)
if errCount == 0 {
executionLogger.Sugar().Debugf("added rooms successfully with errors: %d and success: %d of amount: %d", errCount, successCount, amount)
} else {
executionLogger.Sugar().Infof("added rooms successfully with errors: %d and success: %d of amount: %d", errCount, successCount, amount)
}
ex.operationManager.AppendOperationEventToExecutionHistory(ctx, op, fmt.Sprintf("added %d rooms", amount))
return nil
}
Expand Down
8 changes: 4 additions & 4 deletions internal/core/operations/rooms/remove/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (e *Executor) Execute(ctx context.Context, op *operation.Operation, definit
removeDefinition := definition.(*Definition)

if len(removeDefinition.RoomsIDs) > 0 {
logger.Info("start removing rooms", zap.Strings("RoomIDs", removeDefinition.RoomsIDs))
logger.Debug("start removing rooms", zap.Strings("RoomIDs", removeDefinition.RoomsIDs))
err := e.removeRoomsByIDs(ctx, op.SchedulerName, removeDefinition.RoomsIDs, op, removeDefinition.Reason)
if err != nil {
reportDeletionFailedTotal(op.SchedulerName, op.ID)
Expand All @@ -97,7 +97,7 @@ func (e *Executor) Execute(ctx context.Context, op *operation.Operation, definit
}

if removeDefinition.Amount > 0 {
logger.Info("start removing rooms", zap.Int("amount", removeDefinition.Amount))
logger.Debug("start removing rooms", zap.Int("amount", removeDefinition.Amount))
err := e.removeRoomsByAmount(ctx, logger, op.SchedulerName, removeDefinition.Amount, op, removeDefinition.Reason)
if err != nil {
reportDeletionFailedTotal(op.SchedulerName, op.ID)
Expand All @@ -108,7 +108,7 @@ func (e *Executor) Execute(ctx context.Context, op *operation.Operation, definit
e.operationManager.AppendOperationEventToExecutionHistory(ctx, op, fmt.Sprintf("removed %d rooms", removeDefinition.Amount))
}

logger.Info("finished deleting rooms")
logger.Debug("finished deleting rooms")
return nil
}

Expand Down Expand Up @@ -138,7 +138,7 @@ func (e *Executor) removeRoomsByAmount(ctx context.Context, logger *zap.Logger,
return err
}

logger.Info("removing rooms by amount sorting by version",
logger.Debug("removing rooms by amount sorting by version",
zap.Array("rooms:", zapcore.ArrayMarshalerFunc(func(enc zapcore.ArrayEncoder) error {
for _, room := range rooms {
enc.AppendString(fmt.Sprintf("%s-%s-%s", room.ID, room.Version, room.Status.String()))
Expand Down
4 changes: 2 additions & 2 deletions internal/core/operations/schedulers/newversion/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ func (ex *Executor) Execute(ctx context.Context, op *operation.Operation, defini
}

ex.operationManager.AppendOperationEventToExecutionHistory(ctx, op, fmt.Sprintf(enqueuedSwitchVersionMessageTemplate, switchOpID))
logger.Sugar().Infof("new scheduler version created: %s, is major: %t", newScheduler.Spec.Version, isSchedulerMajorVersion)
logger.Sugar().Infof("%s operation succeded, %s operation enqueued to continue scheduler update process, switching to version %s", opDef.Name(), switchversion.OperationName, newScheduler.Spec.Version)
logger.Sugar().Debugf("new scheduler version created: %s, is major: %t", newScheduler.Spec.Version, isSchedulerMajorVersion)
logger.Sugar().Debugf("%s operation succeded, %s operation enqueued to continue scheduler update process, switching to version %s", opDef.Name(), switchversion.OperationName, newScheduler.Spec.Version)
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions internal/core/operations/schedulers/switchversion/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (ex *Executor) Execute(ctx context.Context, op *operation.Operation, defini
zap.String(logs.LogFieldOperationPhase, "Execute"),
zap.String(logs.LogFieldOperationID, op.ID),
)
logger.Info("start switching scheduler active version")
logger.Debug("start switching scheduler active version")

updateDefinition, ok := definition.(*Definition)
if !ok {
Expand All @@ -81,7 +81,7 @@ func (ex *Executor) Execute(ctx context.Context, op *operation.Operation, defini
return updateSchedulerErr
}

logger.Info("scheduler update finishes with success")
logger.Debug("scheduler update finishes with success")
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion internal/core/services/events/events_forwarder_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ func (es *EventsForwarderService) isValidationRoom(ctx context.Context, event *e
}

if gameRoom.IsValidationRoom {
es.logger.Info(fmt.Sprintf("not producing events for room \"%s\", scheduler \"%s\" since it's a validation room", gameRoom.ID, gameRoom.SchedulerID))
es.logger.Debug(fmt.Sprintf("not producing events for room \"%s\", scheduler \"%s\" since it's a validation room", gameRoom.ID, gameRoom.SchedulerID))
}

return gameRoom.IsValidationRoom, nil
Expand Down
4 changes: 2 additions & 2 deletions internal/core/services/rooms/room_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func (m *RoomManager) UpdateRoomInstance(ctx context.Context, gameRoomInstance *
}

func (m *RoomManager) CleanRoomState(ctx context.Context, schedulerName, roomId string) error {
m.Logger.Sugar().Infof("Cleaning room \"%v\", scheduler \"%v\"", roomId, schedulerName)
m.Logger.Sugar().Debugf("Cleaning room \"%v\", scheduler \"%v\"", roomId, schedulerName)
err := m.RoomStorage.DeleteRoom(ctx, schedulerName, roomId)
if err != nil && !errors.Is(err, porterrors.ErrNotFound) {
return fmt.Errorf("failed to delete room state: %w", err)
Expand All @@ -201,7 +201,7 @@ func (m *RoomManager) CleanRoomState(ctx context.Context, schedulerName, roomId
SchedulerID: schedulerName,
})

m.Logger.Info("cleaning room success")
m.Logger.Debug("cleaning room success")
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions internal/core/services/workers/workers_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,14 @@ func (w *WorkersManager) SyncWorkers(ctx context.Context) error {
desirableWorkers := w.getDesirableWorkers(schedulers)
for name, worker := range desirableWorkers {
w.startWorker(ctx, name, worker)
w.logger.Info("new operation worker running", zap.String("scheduler", name))
w.logger.Debug("new operation worker running", zap.String("scheduler", name))
reportWorkerStart(name, w.builder.ComponentName)
}

dispensableWorkers := w.getDispensableWorkers(schedulers)
for name, worker := range dispensableWorkers {
worker.Stop(ctx)
w.logger.Info("canceling operation worker", zap.String("scheduler", name))
w.logger.Debug("canceling operation worker", zap.String("scheduler", name))
reportWorkerStop(name, w.builder.ComponentName)
}

Expand Down
Loading
Loading