Run Console service diagnostics in parallel
This commit is contained in:
parent
16d0e5959a
commit
ee0c719bee
|
|
@ -0,0 +1,11 @@
|
||||||
|
# Console 3.1.38 — parallel service diagnostics
|
||||||
|
|
||||||
|
- Execute independent provider modules concurrently with a maximum of four
|
||||||
|
workers while preserving their canonical card order.
|
||||||
|
- Execute the independent core service checks for It-Screen, MQTT, Zigbee,
|
||||||
|
tunnels, FFmpeg, display and managed system services through the same bounded
|
||||||
|
worker contract.
|
||||||
|
- Keep the shared snapshot, explicit Refresh bypass and wide technical-value
|
||||||
|
layout introduced in Console 3.1.37.
|
||||||
|
- Contract tests verify that provider and core-card checks actually overlap and
|
||||||
|
that the resulting cards remain in the established product order.
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
"version": "1.0.1"
|
"version": "1.0.1"
|
||||||
},
|
},
|
||||||
"stage_ui": {
|
"stage_ui": {
|
||||||
"version": "3.1.37"
|
"version": "3.1.38"
|
||||||
},
|
},
|
||||||
"stage_avahi": {
|
"stage_avahi": {
|
||||||
"version": "1.0.0"
|
"version": "1.0.0"
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ import time
|
||||||
import wave
|
import wave
|
||||||
import crypt
|
import crypt
|
||||||
import spwd
|
import spwd
|
||||||
|
from concurrent.futures import ThreadPoolExecutor
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from http.cookies import SimpleCookie
|
from http.cookies import SimpleCookie
|
||||||
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
|
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
|
||||||
|
|
@ -61,7 +62,7 @@ APP_DIR = "/opt/iomatex-console"
|
||||||
PUBLIC_DIR = os.path.join(APP_DIR, "public")
|
PUBLIC_DIR = os.path.join(APP_DIR, "public")
|
||||||
PROVIDERS_DIR = os.path.join(APP_DIR, "providers.d")
|
PROVIDERS_DIR = os.path.join(APP_DIR, "providers.d")
|
||||||
CONFIG_PATH = "/etc/iomatex/console.json"
|
CONFIG_PATH = "/etc/iomatex/console.json"
|
||||||
UI_VERSION = "V 3.1.37"
|
UI_VERSION = "V 3.1.38"
|
||||||
STORAGE_HEALTH_COMMAND = "/usr/local/sbin/iomatex-storage-health"
|
STORAGE_HEALTH_COMMAND = "/usr/local/sbin/iomatex-storage-health"
|
||||||
ZONEINFO_ROOT = "/usr/share/zoneinfo"
|
ZONEINFO_ROOT = "/usr/share/zoneinfo"
|
||||||
|
|
||||||
|
|
@ -2526,9 +2527,11 @@ def build_provider_context():
|
||||||
|
|
||||||
def collect_provider_cards(context, entrypoint="get_cards"):
|
def collect_provider_cards(context, entrypoint="get_cards"):
|
||||||
cards = []
|
cards = []
|
||||||
provider_names = []
|
providers = load_providers(entrypoint)
|
||||||
for path, provider in load_providers(entrypoint):
|
provider_names = [os.path.basename(path) for path, _provider in providers]
|
||||||
provider_names.append(os.path.basename(path))
|
|
||||||
|
def collect(item):
|
||||||
|
path, provider = item
|
||||||
try:
|
try:
|
||||||
result = provider(context)
|
result = provider(context)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
|
|
@ -2545,8 +2548,12 @@ def collect_provider_cards(context, entrypoint="get_cards"):
|
||||||
}]
|
}]
|
||||||
if isinstance(result, dict):
|
if isinstance(result, dict):
|
||||||
result = [result]
|
result = [result]
|
||||||
for card in result or []:
|
return [normalize_card(card) for card in result or []]
|
||||||
cards.append(normalize_card(card))
|
|
||||||
|
if providers:
|
||||||
|
with ThreadPoolExecutor(max_workers=min(4, len(providers)), thread_name_prefix="console-provider") as executor:
|
||||||
|
for result in executor.map(collect, providers):
|
||||||
|
cards.extend(result)
|
||||||
return cards, provider_names
|
return cards, provider_names
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
import importlib.util
|
import importlib.util
|
||||||
import pathlib
|
import pathlib
|
||||||
|
import threading
|
||||||
import unittest
|
import unittest
|
||||||
|
from unittest import mock
|
||||||
|
|
||||||
|
|
||||||
PROVIDER_PATH = pathlib.Path(__file__).resolve().parents[1] / "providers" / "00_core_services.py"
|
PROVIDER_PATH = pathlib.Path(__file__).resolve().parents[1] / "providers" / "00_core_services.py"
|
||||||
|
|
@ -10,6 +12,26 @@ SPEC.loader.exec_module(provider)
|
||||||
|
|
||||||
|
|
||||||
class ReverseTunnelBootstrapTest(unittest.TestCase):
|
class ReverseTunnelBootstrapTest(unittest.TestCase):
|
||||||
|
def test_core_cards_run_in_parallel_and_keep_product_order(self):
|
||||||
|
barrier = threading.Barrier(4)
|
||||||
|
names = [
|
||||||
|
"itscreen_card", "mosquitto_card", "mqtt_bridge_card", "zigbee_card",
|
||||||
|
"reverse_tunnel_card", "ip_stream_card", "display_card", "managed_system_cards",
|
||||||
|
]
|
||||||
|
patches = {}
|
||||||
|
for index, name in enumerate(names):
|
||||||
|
def build(_context, card_id=name, wait=index < 4):
|
||||||
|
if wait:
|
||||||
|
barrier.wait(1)
|
||||||
|
card = {"id": card_id}
|
||||||
|
return [card] if card_id == "managed_system_cards" else card
|
||||||
|
patches[name] = build
|
||||||
|
|
||||||
|
with mock.patch.multiple(provider, **patches):
|
||||||
|
cards = provider.get_cards({})
|
||||||
|
|
||||||
|
self.assertEqual(names, [card["id"] for card in cards])
|
||||||
|
|
||||||
def test_tunnel_is_active_only_when_ssh_child_has_established_connection(self):
|
def test_tunnel_is_active_only_when_ssh_child_has_established_connection(self):
|
||||||
unit = {"active": True, "active_state": "active", "main_pid": 100}
|
unit = {"active": True, "active_state": "active", "main_pid": 100}
|
||||||
responses = {
|
responses = {
|
||||||
|
|
|
||||||
|
|
@ -70,6 +70,25 @@ class HealthServicesCacheTest(unittest.TestCase):
|
||||||
|
|
||||||
self.assertEqual(1, len(calls))
|
self.assertEqual(1, len(calls))
|
||||||
|
|
||||||
|
def test_provider_modules_run_in_parallel_and_keep_order(self):
|
||||||
|
barrier = threading.Barrier(2)
|
||||||
|
|
||||||
|
def provider(service_id):
|
||||||
|
def collect(_context):
|
||||||
|
barrier.wait(1)
|
||||||
|
return {"id": service_id}
|
||||||
|
return collect
|
||||||
|
|
||||||
|
providers = [
|
||||||
|
("/providers/first.py", provider("first")),
|
||||||
|
("/providers/second.py", provider("second")),
|
||||||
|
]
|
||||||
|
with mock.patch.object(app, "load_providers", return_value=providers):
|
||||||
|
cards, names = app.collect_provider_cards({})
|
||||||
|
|
||||||
|
self.assertEqual(["first", "second"], [card["id"] for card in cards])
|
||||||
|
self.assertEqual(["first.py", "second.py"], names)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@
|
||||||
{ mode: "test_by", label: "test.it-screen.by", host: "rest.test.it-screen.by" },
|
{ mode: "test_by", label: "test.it-screen.by", host: "rest.test.it-screen.by" },
|
||||||
{ mode: "custom", label: "Custom", host: "" }
|
{ mode: "custom", label: "Custom", host: "" }
|
||||||
];
|
];
|
||||||
const UI_VERSION = "V 3.1.37";
|
const UI_VERSION = "V 3.1.38";
|
||||||
const ITSCREEN_LOG_INITIAL_LINES = 50;
|
const ITSCREEN_LOG_INITIAL_LINES = 50;
|
||||||
const ITSCREEN_LOG_BUFFER_LIMIT = 300;
|
const ITSCREEN_LOG_BUFFER_LIMIT = 300;
|
||||||
const ITSCREEN_LOG_BATCH_MS = 250;
|
const ITSCREEN_LOG_BATCH_MS = 250;
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@
|
||||||
} catch (error) {}
|
} catch (error) {}
|
||||||
})();
|
})();
|
||||||
</script>
|
</script>
|
||||||
<link rel="stylesheet" href="/console.css?v=3.1.37&rev=edge-runtime-profile-1">
|
<link rel="stylesheet" href="/console.css?v=3.1.38&rev=edge-runtime-profile-1">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<main class="shell">
|
<main class="shell">
|
||||||
|
|
@ -109,7 +109,7 @@
|
||||||
</main>
|
</main>
|
||||||
<div id="menuBackdrop" class="menuBackdrop" hidden></div>
|
<div id="menuBackdrop" class="menuBackdrop" hidden></div>
|
||||||
<div id="toastStack" class="toastStack" aria-live="polite" aria-atomic="true"></div>
|
<div id="toastStack" class="toastStack" aria-live="polite" aria-atomic="true"></div>
|
||||||
<script src="/console.i18n.js?v=3.1.37&rev=edge-runtime-profile-1"></script>
|
<script src="/console.i18n.js?v=3.1.38&rev=edge-runtime-profile-1"></script>
|
||||||
<script src="/console.js?v=3.1.37&rev=edge-runtime-profile-1"></script>
|
<script src="/console.js?v=3.1.38&rev=edge-runtime-profile-1"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import os
|
||||||
import re
|
import re
|
||||||
import shlex
|
import shlex
|
||||||
import shutil
|
import shutil
|
||||||
|
from concurrent.futures import ThreadPoolExecutor
|
||||||
|
|
||||||
|
|
||||||
DRM_ROOT = "/sys/class/drm"
|
DRM_ROOT = "/sys/class/drm"
|
||||||
|
|
@ -1046,16 +1047,21 @@ def managed_system_cards(ctx):
|
||||||
|
|
||||||
|
|
||||||
def get_cards(ctx):
|
def get_cards(ctx):
|
||||||
return [
|
builders = (
|
||||||
itscreen_card(ctx),
|
itscreen_card,
|
||||||
mosquitto_card(ctx),
|
mosquitto_card,
|
||||||
mqtt_bridge_card(ctx),
|
mqtt_bridge_card,
|
||||||
zigbee_card(ctx),
|
zigbee_card,
|
||||||
reverse_tunnel_card(ctx),
|
reverse_tunnel_card,
|
||||||
ip_stream_card(ctx),
|
ip_stream_card,
|
||||||
display_card(ctx),
|
display_card,
|
||||||
*managed_system_cards(ctx),
|
managed_system_cards,
|
||||||
]
|
)
|
||||||
|
cards = []
|
||||||
|
with ThreadPoolExecutor(max_workers=4, thread_name_prefix="console-card") as executor:
|
||||||
|
for result in executor.map(lambda builder: builder(ctx), builders):
|
||||||
|
cards.extend(result if isinstance(result, list) else [result])
|
||||||
|
return cards
|
||||||
|
|
||||||
|
|
||||||
def get_runtime_cards(ctx):
|
def get_runtime_cards(ctx):
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
{
|
{
|
||||||
"version": "3.1.37"
|
"version": "3.1.38"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue