Skip to content

ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.

fix(logs): keep remote runtime lookups off the panel host

Juan Denisd5577e8bdaed
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 402a90d1..34d6d011 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -38,6 +38,8 @@ Changes after 1.9.28 on the development branch.
- Resolve application logs and metrics from the recorded runtime container
before falling back to Compose files and name matching, and render JSON log
lines as readable structured entries (PR #136).
+- Keep remote application log requests on their assigned server instead of
+ looking up the recorded container on the panel host.
- Close the container inspector when opening Logs or Exec so it can no longer
cover those surfaces (PR #137).
diff --git a/backend/app/api/apps.py b/backend/app/api/apps.py
index e5eb97f2..2caf6714 100644
--- a/backend/app/api/apps.py
+++ b/backend/app/api/apps.py
@@ -1906,7 +1906,7 @@ def get_app_logs(app_id):
# A recorded container is the authoritative runtime for single-container
# deployments. Repositories may still contain an unrelated compose file,
# so file presence alone must not redirect their logs through compose.
- if app.app_type == 'docker' and app.container_id:
+ if app.app_type == 'docker' and app.container_id and not app.server_id:
if DockerService.get_container(app.container_id):
result = DockerService.get_container_logs(
app.container_id, tail=lines, timestamps=False
diff --git a/backend/tests/BASELINE_COUNT b/backend/tests/BASELINE_COUNT
index f00811b2..f2e5995f 100644
--- a/backend/tests/BASELINE_COUNT
+++ b/backend/tests/BASELINE_COUNT
@@ -1 +1 @@
-5109
+5110
diff --git a/backend/tests/test_app_observability_runtime.py b/backend/tests/test_app_observability_runtime.py
index ae29f85e..abb0dd39 100644
--- a/backend/tests/test_app_observability_runtime.py
+++ b/backend/tests/test_app_observability_runtime.py
@@ -1,9 +1,10 @@
"""Runtime-aware application logs keep single-container and compose support."""
+import os
from unittest.mock import patch
import pytest
-from factories import headers_for, make_application, make_user
+from factories import headers_for, make_application, make_server, make_user
@pytest.fixture
@@ -89,3 +90,35 @@ def test_a_stale_recorded_container_keeps_the_compose_fallback(
assert response.get_json()['logs'] == 'fallback-ready'
direct.assert_not_called()
compose.assert_called_once()
+
+
+def test_remote_logs_never_resolve_a_container_on_the_panel(
+ client, db_session, owner):
+ server = make_server(db_session, name='remote-runtime')
+ application = make_application(
+ db_session,
+ name='remote-api',
+ root_path='/srv/remote-api',
+ compose_file='compose.yaml',
+ container_id='runtime-container-id',
+ server_id=server.id,
+ user_id=owner.id,
+ )
+
+ with patch('app.api.apps.DockerService.get_container') as inspect, \
+ patch('app.api.apps.DockerService.get_container_logs') as direct, \
+ patch('app.api.apps.RemoteDockerService.compose_logs',
+ return_value={'success': True,
+ 'data': {'logs': 'remote-ready'}}) as remote:
+ response = client.get(
+ f'/api/v1/apps/{application.id}/logs?lines=75',
+ headers=headers_for(owner),
+ )
+
+ assert response.status_code == 200
+ assert response.get_json()['logs'] == 'remote-ready'
+ inspect.assert_not_called()
+ direct.assert_not_called()
+ remote.assert_called_once_with(
+ server.id, os.path.join('/srv/remote-api', 'compose.yaml'), tail=75,
+ user_id=str(owner.id))