From 3c29efde51ef29752716d0398b3f30069f08ea0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20=C4=8Cun=C3=A1t?= <vladimir.cunat@nic.cz> Date: Thu, 29 Mar 2018 13:50:19 +0200 Subject: [PATCH] predict: don't auto-load stats if not needed and make docs conform to the reality. --- modules/predict/README.rst | 8 ++++---- modules/predict/predict.lua | 4 ++-- modules/predict/tests/predict.test.lua | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/predict/README.rst b/modules/predict/README.rst index bd5a8dd48..6c4b442ad 100644 --- a/modules/predict/README.rst +++ b/modules/predict/README.rst @@ -15,8 +15,6 @@ ahead of time. This is helpful to minimize the perceived latency and keeps the c Example configuration ^^^^^^^^^^^^^^^^^^^^^ -.. warning:: This module requires 'stats' module to be present and loaded. - .. code-block:: lua modules = { @@ -29,7 +27,9 @@ Example configuration Defaults are 15 minutes window, 6 hours period. .. tip:: Use period 0 to turn off prediction and just do prefetching of expiring records. - That works even without the 'stats' module. + That works even without the :ref:`stats <mod-stats>` module. + +.. note:: Otherwise this module requires :ref:`stats <mod-stats>` module and loads it if not present. Exported metrics ^^^^^^^^^^^^^^^^ @@ -45,7 +45,7 @@ Properties ^^^^^^^^^^ .. function:: predict.config({ window = 15, period = 24}) - + Reconfigure the predictor to given tracking window and period length. Both parameters are optional. Window length is in minutes, period is a number of windows that can be kept in memory. e.g. if a ``window`` is 15 minutes, a ``period`` of "24" means 6 hours. diff --git a/modules/predict/predict.lua b/modules/predict/predict.lua index 7dd38754c..846d4ef7d 100644 --- a/modules/predict/predict.lua +++ b/modules/predict/predict.lua @@ -13,8 +13,6 @@ local predict = { log = {}, } --- Load dependent modules -if not stats then modules.load('stats') end -- Calculate next sample with jitter [1-2/5 of window] local function next_event() @@ -163,6 +161,8 @@ function predict.config(config) if type(config) ~= 'table' then return end if config.window then predict.window = config.window end if config.period then predict.period = config.period end + -- Load dependent modules + if (predict.period or 0) ~= 0 and not stats then modules.load('stats') end -- Reinitialize to reset timers predict.deinit() predict.init() diff --git a/modules/predict/tests/predict.test.lua b/modules/predict/tests/predict.test.lua index e4694b635..10431045e 100644 --- a/modules/predict/tests/predict.test.lua +++ b/modules/predict/tests/predict.test.lua @@ -1,5 +1,5 @@ -- setup resolver -modules = { 'predict' } +modules = { 'predict', 'stats' } -- mock global functions local resolve_count = 0 @@ -57,4 +57,4 @@ end return { test_predict_drain, test_predict_process -} \ No newline at end of file +} -- GitLab