diff --git a/modules/predict/README.rst b/modules/predict/README.rst index bd5a8dd4868787bcf179344f320310c40b961e30..6c4b442ad834588413d55dd1dd49b944c5fcafdd 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 7dd38754c56254865ab7ad24c292e3937d5fab17..846d4ef7d53867f64e364d66631d393938fcbd51 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 e4694b635a6f76e6c0d2c9a50ffc1099bbbf5799..10431045e60d4c4bfef37a83e9dc1fb8c6024b6e 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 +}