remove stroing of the Game Board State into Redis or Memory

This commit is contained in:
2026-04-08 08:36:54 +02:00
parent f6e19e18e6
commit a62501cf22
11 changed files with 13 additions and 296 deletions
+4 -22
View File
@@ -3,12 +3,11 @@ from server.metrics.backends.Template import StoreTemplate
import time
class MetricsCollector:
def __init__(self, metrics_manager:StoreTemplate, game_state_local_cache:bool, metrics_backend:str, game_state_backend:str, stale_game_timeout_sec:int, game_last_seen_unix:dict, game_move_counts:dict):
def __init__(self, metrics_manager:StoreTemplate, metrics_backend:str, stale_game_timeout_sec:int, game_last_seen_unix:dict, game_move_counts:dict):
self._manager = metrics_manager
self._stale_game_timeout_sec = stale_game_timeout_sec
self._game_last_seen_unix = game_last_seen_unix
self._game_move_counts = game_move_counts
self._game_state_backend_is_redis = game_state_backend.strip().lower() == 'redis'
self._metrics = {
'games_started': 0,
'games_ended': 0,
@@ -39,7 +38,6 @@ class MetricsCollector:
'last_game_end_unix': 0,
'last_move_unix': 0,
'games_stuck_removed': 0,
'game_state_local_cache_enabled': bool(game_state_local_cache),
'metrics_backend': metrics_backend,
}
@@ -101,8 +99,6 @@ class MetricsCollector:
await self._auto_publish()
async def record_stuck_removed(self) -> None:
if self._game_state_backend_is_redis:
return
self._metrics['games_stuck_removed'] += 1
await self._auto_publish()
@@ -117,23 +113,9 @@ class MetricsCollector:
if now - last_seen >= self._stale_game_timeout_sec
)
if self._game_state_backend_is_redis:
# Redis auto-expires stale keys via TTL, so stale games are already gone from the
# server's perspective. We exclude them from all metrics so we only report games
# that are actually still alive in Redis.
report_active_games = len(game_last_seen_unix) - stale_candidates
report_stale_candidates = 0
# Only include non-stale timestamps when calculating the oldest active game age,
# so a game that Redis already deleted doesn't inflate the age metric.
active_last_seen = [
last_seen
for last_seen in game_last_seen_unix.values()
if now - last_seen < self._stale_game_timeout_sec
]
else:
report_active_games = len(game_last_seen_unix)
report_stale_candidates = stale_candidates
active_last_seen = list(game_last_seen_unix.values())
report_active_games = len(game_last_seen_unix)
report_stale_candidates = stale_candidates
active_last_seen = list(game_last_seen_unix.values())
oldest_active_age = max(0, now - min(active_last_seen)) if active_last_seen else 0
return report_active_games, report_stale_candidates, oldest_active_age