v0.7.5: silence benign log noise, graceful SSL permission errors, README trim

This commit is contained in:
Reditus committed 2026-09-22 08:38:16 +01:00
1 parent 421b37e854
commit 91944a0213
11 files changed
+270 -70

No files matched your search

+4 -2
View File
@@ -388,7 +388,7 @@ class BackupService:
with open(meta_path) as f:
return json.load(f)
except Exception as e:
logger.warning(f'Could not read sidecar meta from {meta_path}: {e}')
logger.debug(f'Could not read sidecar meta from {meta_path}: {e}')
try:
with tarfile.open(path, 'r:gz') as tar:
for m in tar.getmembers():
@@ -396,7 +396,9 @@ class BackupService:
with tar.extractfile(m) as f:
return json.loads(f.read().decode('utf-8'))
except Exception as e:
logger.warning(f'Could not read metadata from {path}: {e}')
# Expected for encrypted archives (handled by verify with a
# password) and pre-sidecar backups; not worth a warning.
logger.debug(f'Could not read metadata from {path}: {e}')
return {}
def delete_backup(self, name):
+8 -1
View File
@@ -256,8 +256,15 @@ class DirectorService:
def get_server_set_scale(self, map_name: str) -> Optional[Dict]:
name = self._map_to_scale_name(map_name)
cm_out, cm_err, cm_rc = self.k8s.run(
f'get serversetscale {name} -o json')
f'get serversetscale {name} -o json', quiet=True)
if cm_rc != 0 or not cm_out:
# A missing ServerSetScale just means the map has none; only
# unexpected failures deserve a warning.
if cm_rc != 0 and 'not found' not in (cm_err or '').lower():
logger.warning("ServerSetScale lookup failed for %s: %s",
map_name, (cm_err or '')[:150])
else:
logger.debug("No ServerSetScale for %s", map_name)
return None
return json.loads(cm_out)
+2 -2
View File
@@ -11,10 +11,10 @@ class K8sService:
self.ssh = ssh_service
self.namespace = namespace
def run(self, kubectl_command, timeout=30):
def run(self, kubectl_command, timeout=30, quiet=False):
full_cmd = f'sudo kubectl {kubectl_command} -n {shlex.quote(str(self.namespace))}'
logger.debug(f"K8s executing: kubectl {kubectl_command} -n {self.namespace}")
result = self.ssh.run(full_cmd, timeout=timeout)
result = self.ssh.run(full_cmd, timeout=timeout, quiet=quiet)
out, err, rc = result
if rc != 0:
logger.debug(f"K8s command failed (rc={rc}): {err[:100] if err else 'no error'}")
+15 -6
View File
@@ -79,19 +79,22 @@ class SSHService:
self._client = client
return self._client
def run(self, command, timeout=30):
def run(self, command, timeout=30, quiet=False):
"""Execute a remote command via SSH.
Args:
command: The shell command to execute.
timeout: Maximum time in seconds to wait for the command.
quiet: When True, expected non-zero results (e.g. probing for
an optional resource) are logged at debug level instead of
warning. Return values are unchanged.
Returns:
Tuple of (stdout, stderr, return_code).
"""
cmd_display = command[:150] + '...' if len(command) > 150 else command
logger.debug(f"SSH executing: {cmd_display}")
try:
client = self._get_client()
stdin, stdout, stderr = client.exec_command(command, timeout=timeout)
@@ -99,17 +102,23 @@ class SSHService:
out = stdout.read().decode('utf-8', errors='replace')
err = stderr.read().decode('utf-8', errors='replace')
rc = stdout.channel.recv_exit_status()
# Debug logging for result
logger.debug(f"SSH result: host={self.host}, user={self.user}, rc={rc}, stdout_len={len(out)}, stderr_len={len(err)}")
if err and rc != 0:
logger.warning(f"SSH stderr (rc={rc}): {err[:200]}")
if quiet:
logger.debug(f"SSH stderr (rc={rc}): {err[:200]}")
else:
logger.warning(f"SSH stderr (rc={rc}): {err[:200]}")
if out:
logger.debug(f"SSH stdout preview: {out[:200]}")
if rc != 0:
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')
if quiet:
logger.debug("SSH command rc=%d (quiet): cmd=%s err=%s", rc, cmd_short, err[:100] if err else 'none')
else:
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(f"SSH command error ({self.host}): {e}")
+55
View File
@@ -0,0 +1,55 @@
"""Production HTTP server builder (cheroot) with noise filtering.
Cheroot writes server-level errors (e.g. scanners dropping TLS handshakes)
straight to stderr, bypassing the dashboard's log levels. The filter below
sends the known-benign handshake noise to the debug log and lets everything
else through untouched.
"""
import logging
logger = logging.getLogger(__name__)
# Fragments identifying a peer that vanished mid-handshake (typically an
# internet scanner hitting the public HTTPS port). Never real failures.
_HANDSHAKE_NOISE = (
'during handshake',
'SSLV3_ALERT',
'UNEXPECTED_EOF',
'TLSV1_ALERT',
)
def cheroot_error_filter(original_error_log, msg='', level=20, traceback=False):
"""Drop-in replacement for ``server.error_log``.
Handshake noise -> debug log. Everything else -> original handler.
"""
text = str(msg)
lowered = text.lower()
if any(fragment.lower() in lowered for fragment in _HANDSHAKE_NOISE):
logger.debug('TLS handshake dropped by peer: %s', text[:200])
return
original_error_log(msg, level=level, traceback=traceback)
def build_server(host, port, wsgi_app, cert_path=None, key_path=None,
numthreads=16, socket_timeout=60):
"""Build a cheroot server with timeouts, bounded queues and TLS support."""
from cheroot import wsgi as cheroot_wsgi
server = cheroot_wsgi.Server(
(host, port), wsgi_app,
numthreads=numthreads,
request_queue_size=128,
timeout=socket_timeout,
accepted_queue_size=128,
accepted_queue_timeout=10,
)
if cert_path and key_path:
from cheroot.ssl.builtin import BuiltinSSLAdapter
server.ssl_adapter = BuiltinSSLAdapter(cert_path, key_path)
original = server.error_log
server.error_log = lambda msg='', level=20, traceback=False: \
cheroot_error_filter(original, msg, level=level, traceback=traceback)
return server