Relax rate limits, reduce SSH warning noise, add step logging helpers

This commit is contained in:
Reditus committed 2026-05-16 19:50:54 +01:00
1 parent 7f3ef08e7e
commit 27d87b3d31
4 files changed
+68 -15

No files matched your search

+10 -10
View File
@@ -41,7 +41,7 @@ def register_api_routes(app, services, settings):
limiter = Limiter(
app=app,
key_func=get_remote_address,
default_limits=["200 per day", "50 per hour"],
default_limits=["2000 per day", "500 per hour"],
storage_uri="memory://",
)
else:
@@ -53,7 +53,7 @@ def register_api_routes(app, services, settings):
# Server actions
@app.route('/server/action', methods=['POST'])
@auth_req
@limiter.limit("10 per hour")
@limiter.limit("500 per hour")
def server_action():
deployment = request.form.get('deployment', '')
action = request.form.get('action', '')
@@ -104,7 +104,7 @@ def register_api_routes(app, services, settings):
@app.route('/server/battlegroup/action', methods=['POST'])
@auth_req
@limiter.limit("10 per hour")
@limiter.limit("500 per hour")
def battlegroup_action():
action = request.form.get('action', '')
if action not in ('start', 'stop', 'restart'):
@@ -115,7 +115,7 @@ def register_api_routes(app, services, settings):
@app.route('/server/battlegroup/update', methods=['POST'])
@auth_req
@limiter.limit("5 per hour")
@limiter.limit("1000 per hour")
def battlegroup_update():
bg_script = settings['kubernetes']['battlegroup_script']
out, err, rc = ssh.run(f'{bg_script} update', timeout=600)
@@ -186,7 +186,7 @@ def register_api_routes(app, services, settings):
@app.route('/server/firewall/block', methods=['POST'])
@auth_req
@limiter.limit("10 per hour")
@limiter.limit("500 per hour")
def firewall_block():
port = request.form.get('port', type=int)
bgd_port = _get_bgd_nodeport()
@@ -232,7 +232,7 @@ def register_api_routes(app, services, settings):
@app.route('/server/firewall/unblock', methods=['POST'])
@auth_req
@limiter.limit("10 per hour")
@limiter.limit("500 per hour")
def firewall_unblock():
port = request.form.get('port', type=int)
bgd_port = _get_bgd_nodeport()
@@ -340,7 +340,7 @@ def register_api_routes(app, services, settings):
# Ban management
@app.route('/api/ban_player', methods=['POST'])
@auth_req
@limiter.limit("5 per hour")
@limiter.limit("1000 per hour")
def api_ban_player():
try:
player_id = request.form.get('player_id', type=int)
@@ -403,7 +403,7 @@ def register_api_routes(app, services, settings):
@app.route('/api/unban_player', methods=['POST'])
@auth_req
@limiter.limit("5 per hour")
@limiter.limit("1000 per hour")
def api_unban_player():
try:
player_id = request.form.get('player_id', type=int)
@@ -429,7 +429,7 @@ def register_api_routes(app, services, settings):
@app.route('/api/kick_player', methods=['POST'])
@auth_req
@limiter.limit("10 per hour")
@limiter.limit("500 per hour")
def api_kick_player():
try:
player_id = request.form.get('player_id', type=int)
@@ -444,7 +444,7 @@ def register_api_routes(app, services, settings):
# Vitals editing
@app.route('/api/edit_vitals', methods=['POST'])
@auth_req
@limiter.limit("10 per hour")
@limiter.limit("500 per hour")
def api_edit_vitals():
try:
pawn_id = request.form.get('pawn_id', type=int)
+2 -2
View File
@@ -107,14 +107,14 @@ class ChatService:
logger.warning("Cannot catch up - no text-router pod found")
return 0
logger.info(f"Attempting to catch up chat from pod: {pod_name}")
logger.debug(f"Attempting to catch up chat from pod: {pod_name}")
# Get pod logs first, then filter locally
log_cmd = f"sudo kubectl logs -n {namespace} {pod_name} --tail=2000 2>/dev/null"
out, err, rc = self.ssh.run(log_cmd, timeout=30)
if rc != 0 or not out:
logger.warning(f"Cannot catch up - failed to get pod logs: {err}")
logger.debug(f"Cannot catch up - failed to get pod logs (rc={rc})")
return 0
# Filter for chat messages locally
+2 -1
View File
@@ -85,7 +85,8 @@ class SSHService:
err = stderr.read().decode('utf-8', errors='replace')
rc = stdout.channel.recv_exit_status()
if rc != 0:
logger.warning("SSH command failed (rc=%d): %s", rc, err[:200])
cmd_short = command[:80] + '...' if len(command) > 80 else command
logger.warning("SSH command failed (rc=%d): cmd=%s err=%s", rc, cmd_short, err[:100] if err else 'none')
return out, err, rc
except paramiko.SSHException as e:
logger.error("SSH command error: %s", e)
+54 -2
View File
@@ -160,6 +160,57 @@ function Start-LogSession {
return $sessionFile
}
function Write-Step {
param([string]$Name, [string]$Category = "general")
if (-not $global:StepCounter) { $global:StepCounter = @{} }
if (-not $global:StepCounter[$Category]) { $global:StepCounter[$Category] = 0 }
$global:StepCounter[$Category]++
$num = $global:StepCounter[$Category]
Write-Log -Message "[$num] $Name" -Level "INFO" -Category $Category
}
function Write-Success {
param([string]$Message, [string]$Category = "general")
Write-Log -Message $Message -Level "INFO" -Category $Category
}
function Write-DebugLog {
param([string]$Message, [string]$Category = "general")
Write-Log -Message $Message -Level "DEBUG" -Category $Category
}
function Write-Sep {
param([string]$Title, [string]$Category = "general")
$sep = "-" * 55
$msg = if ($Title) { "$Title $sep" } else { $sep }
$logFile = Join-Path $LauncherLogDir "$Category\$LogDate.log"
if (-not (Test-Path (Split-Path $logFile))) {
New-Item -ItemType Directory -Path (Split-Path $logFile) -Force | Out-Null
}
Add-Content -Path $logFile -Value $msg -Encoding UTF8
Write-Host $msg -ForegroundColor DarkGray
}
$Script:LogIndent = 0
function Push-Indent {
$Script:LogIndent++
}
function Pop-Indent {
$Script:LogIndent = [Math]::Max(0, $Script:LogIndent - 1)
}
function Write-LogStyled {
param(
[string]$Message,
[string]$Level = "INFO",
[string]$Category = "general"
)
$prefix = if ($Script:LogIndent -gt 0) { " " * $Script:LogIndent } else { "" }
Write-Log -Message "$prefix$Message" -Level $Level -Category $Category
}
# ── Log Rotation & Cleanup ────────────────────────────────────────────
# Prevents logs from growing unbounded.
# - Deletes log files older than $LogRetentionDays
@@ -1803,8 +1854,8 @@ print(json.dumps(s))
Write-Host "============================================================" -ForegroundColor Cyan
Write-Host ""
Write-Log -Message "Dashboard launch started" -Category "general"
Write-Log -Message "Server: $ServerHost, User: $SSHUser" -Category "ssh"
Write-Sep -Title "Dashboard Launch" -Category "general"
Write-Log -Message "Server: $ServerHost, User: $SSHUser" -Category "general"
Write-Log -Message "Ports: DB=$LocalPort, Director=$DirectorPort, Dashboard=$DashboardPort" -Category "general"
Write-Log -Message "Namespace: $Namespace" -Category "k8s"
@@ -1819,6 +1870,7 @@ print(json.dumps(s))
Start-Sleep 1
# [1/4] SSH Tunnel
Write-Step -Name "SSH Tunnel" -Category "ssh"
Write-Host "[1/4] Starting SSH tunnel (localhost:$LocalPort -> VM)..." -ForegroundColor Yellow
Write-Log -Message "Starting SSH tunnel to ${SSHUser}@${ServerHost}" -Category "ssh"
$sshArgs = @(