diff options
Diffstat (limited to 'python/knot_resolver')
6 files changed, 46 insertions, 1 deletions
diff --git a/python/knot_resolver/datamodel/config_schema.py b/python/knot_resolver/datamodel/config_schema.py index 641032dc..6329add3 100644 --- a/python/knot_resolver/datamodel/config_schema.py +++ b/python/knot_resolver/datamodel/config_schema.py @@ -17,6 +17,7 @@ from knot_resolver.datamodel.monitoring_schema import MonitoringSchema from knot_resolver.datamodel.network_schema import NetworkSchema from knot_resolver.datamodel.options_schema import OptionsSchema from knot_resolver.datamodel.rate_limiting_schema import RateLimitingSchema +from knot_resolver.datamodel.defer_schema import DeferSchema from knot_resolver.datamodel.templates import POLICY_CONFIG_TEMPLATE, WORKER_CONFIG_TEMPLATE from knot_resolver.datamodel.types import EscapedStr, IntPositive, WritableDir from knot_resolver.datamodel.view_schema import ViewSchema @@ -108,6 +109,7 @@ class KresConfig(ConfigSchema): monitoring: Metrics exposisition configuration (Prometheus, Graphite) lua: Custom Lua configuration. rate_limiting: Configuration of rate limiting. + defer: Configuration of request prioritization (defer). """ version: int = 1 @@ -129,6 +131,7 @@ class KresConfig(ConfigSchema): logging: LoggingSchema = LoggingSchema() monitoring: MonitoringSchema = MonitoringSchema() rate_limiting: Optional[RateLimitingSchema] = None + defer: DeferSchema = DeferSchema() lua: LuaSchema = LuaSchema() _LAYER = Raw @@ -151,6 +154,7 @@ class KresConfig(ConfigSchema): logging: LoggingSchema monitoring: MonitoringSchema rate_limiting: Optional[RateLimitingSchema] + defer: DeferSchema lua: LuaSchema def _hostname(self, obj: Raw) -> Any: diff --git a/python/knot_resolver/datamodel/defer_schema.py b/python/knot_resolver/datamodel/defer_schema.py new file mode 100644 index 00000000..38301e55 --- /dev/null +++ b/python/knot_resolver/datamodel/defer_schema.py @@ -0,0 +1,15 @@ +from knot_resolver.utils.modeling import ConfigSchema +from knot_resolver.datamodel.types import TimeUnit + + +class DeferSchema(ConfigSchema): + """ + Configuration of request prioritization (defer). + + --- + enabled: Use request prioritization. + log_period: Minimal time between two log messages, or '0s' to disable. + """ + + enabled: bool = False + log_period: TimeUnit = TimeUnit("0s") diff --git a/python/knot_resolver/datamodel/templates/defer.lua.j2 b/python/knot_resolver/datamodel/templates/defer.lua.j2 new file mode 100644 index 00000000..131b71c4 --- /dev/null +++ b/python/knot_resolver/datamodel/templates/defer.lua.j2 @@ -0,0 +1,10 @@ +{% from 'macros/common_macros.lua.j2' import boolean %} + +{% if cfg.defer.enabled and not disable_defer -%} +assert(C.defer_init( + '{{ cfg.rundir }}/defer', + {{ cfg.defer.log_period.millis() }}, + {{ cfg.workers }}) == 0) +{% else %} +assert(C.defer_init(nil, 0, 0) == 0) +{%- endif %} diff --git a/python/knot_resolver/datamodel/templates/policy-config.lua.j2 b/python/knot_resolver/datamodel/templates/policy-config.lua.j2 index 4c5c9048..9d88537a 100644 --- a/python/knot_resolver/datamodel/templates/policy-config.lua.j2 +++ b/python/knot_resolver/datamodel/templates/policy-config.lua.j2 @@ -35,6 +35,12 @@ cache.open({{ cfg.cache.size_max.bytes() }}, 'lmdb://{{ cfg.cache.storage }}') -- FORWARD section ---------------------------------- {% include "forward.lua.j2" %} +-- DEFER section ------------------------------------ +-- Force-disable defer to avoid the default defer config. +{% set disable_defer = true %} +{% include "defer.lua.j2" %} + + {% endif %} quit() diff --git a/python/knot_resolver/datamodel/templates/worker-config.lua.j2 b/python/knot_resolver/datamodel/templates/worker-config.lua.j2 index c97f0820..be7fe150 100644 --- a/python/knot_resolver/datamodel/templates/worker-config.lua.j2 +++ b/python/knot_resolver/datamodel/templates/worker-config.lua.j2 @@ -46,6 +46,9 @@ nsid.name('{{ cfg.nsid }}' .. worker.id) -- RATE-LIMITING section ------------------------------------ {% include "rate_limiting.lua.j2" %} +-- DEFER section ------------------------------------ +{% include "defer.lua.j2" %} + {% endif %} -- LUA section -------------------------------------- diff --git a/python/knot_resolver/manager/manager.py b/python/knot_resolver/manager/manager.py index 952c8b7d..68edb915 100644 --- a/python/knot_resolver/manager/manager.py +++ b/python/knot_resolver/manager/manager.py @@ -135,6 +135,7 @@ class KresManager: # pylint: disable=too-many-instance-attributes config.monitoring, config.lua, config.rate_limiting, + config.defer, ] # register and immediately call a verifier that validates config with 'canary' kresd process @@ -224,11 +225,17 @@ class KresManager: # pylint: disable=too-many-instance-attributes async def validate_config(self, _old: KresConfig, new: KresConfig) -> Result[NoneType, str]: async with self._manager_lock: if _old.rate_limiting != new.rate_limiting: - logger.debug("Unlinking shared RRL memory") + logger.debug("Unlinking shared ratelimiting memory") try: os.unlink(str(_old.rundir) + "/ratelimiting") except FileNotFoundError: pass + if _old.workers != new.workers or _old.defer != new.defer: + logger.debug("Unlinking shared defer memory") + try: + os.unlink(str(_old.rundir) + "/defer") + except FileNotFoundError: + pass logger.debug("Testing the new config with a canary process") try: # technically, this has side effects of leaving a new process runnning |