From: Aleš Mrázek Date: Mon, 4 Jul 2022 16:24:58 +0000 (+0200) Subject: manager: datamodel: supervisor section removed X-Git-Tag: v6.0.0a1~32^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cebd8a3aa1e6349cec3785487d89a5af3a7ad7cd;p=thirdparty%2Fknot-resolver.git manager: datamodel: supervisor section removed - watchdog moved to top-level --- diff --git a/manager/knot_resolver_manager/datamodel/config_schema.py b/manager/knot_resolver_manager/datamodel/config_schema.py index 838b49609..360a41568 100644 --- a/manager/knot_resolver_manager/datamodel/config_schema.py +++ b/manager/knot_resolver_manager/datamodel/config_schema.py @@ -23,9 +23,9 @@ from knot_resolver_manager.datamodel.rpz_schema import RPZSchema from knot_resolver_manager.datamodel.slice_schema import SliceSchema from knot_resolver_manager.datamodel.static_hints_schema import StaticHintsSchema from knot_resolver_manager.datamodel.stub_zone_schema import StubZoneSchema -from knot_resolver_manager.datamodel.supervisor_schema import SupervisorSchema from knot_resolver_manager.datamodel.types.types import IDPattern, IntPositive, UncheckedPath from knot_resolver_manager.datamodel.view_schema import ViewSchema +from knot_resolver_manager.datamodel.watchdog_schema import WatchDogSchema from knot_resolver_manager.datamodel.webmgmt_schema import WebmgmtSchema from knot_resolver_manager.exceptions import DataException from knot_resolver_manager.utils import SchemaNode @@ -92,9 +92,9 @@ class KresConfig(SchemaNode): rundir: Directory where the resolver can create files and which will be it's cwd. workers: The number of running kresd (Knot Resolver daemon) workers. If set to 'auto', it is equal to number of CPUs available. max_workers: The maximum number of workers allowed. Cannot be changed in runtime. + watchdog: Disable supervisord's watchdog, enable with defaults or set new configuration. management: Configuration of management HTTP API. webmgmt: Configuration of legacy web management endpoint. - supervisor: Proceses supervisor configuration. options: Fine-tuning global parameters of DNS resolver operation. network: Network connections and protocols configuration. static_hints: Static hints for forward records (A/AAAA) and reverse records (PTR) @@ -118,9 +118,9 @@ class KresConfig(SchemaNode): rundir: UncheckedPath = UncheckedPath(".") workers: Union[Literal["auto"], IntPositive] = IntPositive(1) max_workers: IntPositive = IntPositive(MAX_WORKERS) + watchdog: Union[bool, WatchDogSchema] = True management: ManagementSchema = ManagementSchema({"unix-socket": "./manager.sock"}) webmgmt: Optional[WebmgmtSchema] = None - supervisor: SupervisorSchema = SupervisorSchema() options: OptionsSchema = OptionsSchema() network: NetworkSchema = NetworkSchema() static_hints: StaticHintsSchema = StaticHintsSchema() @@ -147,7 +147,7 @@ class KresConfig(SchemaNode): max_workers: IntPositive management: ManagementSchema webmgmt: Optional[WebmgmtSchema] - supervisor: SupervisorSchema + watchdog: Union[bool, WatchDogSchema] options: OptionsSchema network: NetworkSchema static_hints: StaticHintsSchema diff --git a/manager/knot_resolver_manager/datamodel/supervisor_schema.py b/manager/knot_resolver_manager/datamodel/supervisor_schema.py deleted file mode 100644 index 05b4a66a4..000000000 --- a/manager/knot_resolver_manager/datamodel/supervisor_schema.py +++ /dev/null @@ -1,38 +0,0 @@ -from typing import Union - -from typing_extensions import Literal - -from knot_resolver_manager.datamodel.types import DNSRecordTypeEnum, DomainName -from knot_resolver_manager.utils import SchemaNode - -BackendEnum = Literal["auto", "systemd", "systemd-session", "supervisord"] - - -class WatchDogSchema(SchemaNode): - """ - Configuration of systemd watchdog. - - --- - qname: Name to internaly query for. - qtype: DNS type to internaly query for. - """ - - qname: DomainName - qtype: DNSRecordTypeEnum - - -class SupervisorSchema(SchemaNode): - """ - Configuration of processes supervisor. - - --- - backend: Forces the manager to use a specific service supervisor. - watchdog: Disable systemd watchdog, enable with defaults or set new configuration. Can only be used with 'systemd' backend. - """ - - backend: BackendEnum = "auto" - watchdog: Union[bool, WatchDogSchema] = True - - def _validate(self) -> None: - if self.watchdog and self.backend not in ["auto", "systemd", "systemd-session"]: - raise ValueError("'watchdog' can only be configured for 'systemd' backend") diff --git a/manager/knot_resolver_manager/datamodel/templates/config.lua.j2 b/manager/knot_resolver_manager/datamodel/templates/config.lua.j2 index d18c7a999..53abea9b9 100644 --- a/manager/knot_resolver_manager/datamodel/templates/config.lua.j2 +++ b/manager/knot_resolver_manager/datamodel/templates/config.lua.j2 @@ -12,8 +12,8 @@ nsid.name('{{ cfg.nsid }}_' .. worker.id) -- LOGGING section ---------------------------------- {% include "logging.lua.j2" %} --- SUPERVISOR section ------------------------------- -{% include "supervisor.lua.j2" %} +-- WATCHDOG section ------------------------------- +{% include "watchdog.lua.j2" %} -- WEBMGMT section ---------------------------------- {% include "webmgmt.lua.j2" %} diff --git a/manager/knot_resolver_manager/datamodel/templates/supervisor.lua.j2 b/manager/knot_resolver_manager/datamodel/templates/supervisor.lua.j2 deleted file mode 100644 index 3d352ec9d..000000000 --- a/manager/knot_resolver_manager/datamodel/templates/supervisor.lua.j2 +++ /dev/null @@ -1,9 +0,0 @@ -{% if cfg.supervisor.watchdog -%} --- supervisor.watchdog -modules.load('watchdog') -{% if cfg.supervisor.watchdog.qname and cfg.supervisor.watchdog.qtype -%} -watchdog.config({ qname = '{{ cfg.supervisor.watchdog.qname.punycode() }}', qtype = kres.type.{{ cfg.supervisor.watchdog.qtype }} }) -{%- endif %} -{% else %} -modules.unload('watchdog') -{%- endif %} \ No newline at end of file diff --git a/manager/knot_resolver_manager/datamodel/templates/watchdog.lua.j2 b/manager/knot_resolver_manager/datamodel/templates/watchdog.lua.j2 new file mode 100644 index 000000000..1288b3d78 --- /dev/null +++ b/manager/knot_resolver_manager/datamodel/templates/watchdog.lua.j2 @@ -0,0 +1,9 @@ +{% if cfg.watchdog -%} +-- watchdog +modules.load('watchdog') +{% if cfg.watchdog.qname and cfg.watchdog.qtype -%} +watchdog.config({ qname = '{{ cfg.watchdog.qname.punycode() }}', qtype = kres.type.{{ cfg.watchdog.qtype }} }) +{%- endif %} +{% else %} +modules.unload('watchdog') +{%- endif %} \ No newline at end of file diff --git a/manager/knot_resolver_manager/datamodel/watchdog_schema.py b/manager/knot_resolver_manager/datamodel/watchdog_schema.py new file mode 100644 index 000000000..99d4a4ec2 --- /dev/null +++ b/manager/knot_resolver_manager/datamodel/watchdog_schema.py @@ -0,0 +1,15 @@ +from knot_resolver_manager.datamodel.types import DNSRecordTypeEnum, DomainName +from knot_resolver_manager.utils import SchemaNode + + +class WatchDogSchema(SchemaNode): + """ + Configuration of supervisord's watchdog which tests whether the started worker is working correctly. + + --- + qname: Name to internaly query for. + qtype: DNS type to internaly query for. + """ + + qname: DomainName + qtype: DNSRecordTypeEnum diff --git a/manager/knot_resolver_manager/server.py b/manager/knot_resolver_manager/server.py index 2381db846..68bf4271c 100644 --- a/manager/knot_resolver_manager/server.py +++ b/manager/knot_resolver_manager/server.py @@ -23,8 +23,6 @@ from knot_resolver_manager.constants import DEFAULT_MANAGER_CONFIG_FILE, PID_FIL from knot_resolver_manager.datamodel.config_schema import KresConfig from knot_resolver_manager.datamodel.management_schema import ManagementSchema from knot_resolver_manager.exceptions import DataException, KresManagerException, SchemaException -from knot_resolver_manager.kresd_controller import get_controller_by_name -from knot_resolver_manager.kresd_controller.interface import SubprocessController from knot_resolver_manager.utils.async_utils import readfile from knot_resolver_manager.utils.functional import Result from knot_resolver_manager.utils.parsing import ParsedTree, parse, parse_yaml @@ -313,14 +311,10 @@ async def _init_manager(config_store: ConfigStore, server: Server) -> KresManage """ Called asynchronously when the application initializes. """ - # if configured, create a subprocess controller manually - controller: Optional[SubprocessController] = None - if config_store.get().supervisor.backend != "auto": - controller = await get_controller_by_name(config_store.get(), config_store.get().supervisor.backend) # Create KresManager. This will perform autodetection of available service managers and # select the most appropriate to use (or use the one configured directly) - manager = await KresManager.create(controller, config_store, server.trigger_shutdown) + manager = await KresManager.create(None, config_store, server.trigger_shutdown) logger.info("Initial configuration applied. Process manager initialized...") return manager diff --git a/manager/tests/unit/datamodel/test_supervisor_schema.py b/manager/tests/unit/datamodel/test_supervisor_schema.py deleted file mode 100644 index 4cc78d519..000000000 --- a/manager/tests/unit/datamodel/test_supervisor_schema.py +++ /dev/null @@ -1,9 +0,0 @@ -import pytest - -from knot_resolver_manager.datamodel.supervisor_schema import SupervisorSchema -from knot_resolver_manager.exceptions import KresManagerException - - -def test_watchdog_backend_invalid(): - with pytest.raises(KresManagerException): - SupervisorSchema({"backend": "supervisord", "watchdog": {"qname": "nic.cz.", "qtype": "A"}})