[patches] [feedback_daemon 1/1] daemon: Introduce feedback daemon
Konstantin Osipov
kostja at tarantool.org
Mon Mar 5 09:20:55 MSK 2018
* Ilya Markov <imarkov at tarantool.org> [18/03/02 22:33]:
> From: Roman Proskin <opomuc at gmail.com>
>
> * feedback daemon sends information about instance to the
> specified host.
> * Add new options to box.cfg:
> - feedback_enabled - switch on/off daemon, default=true.
> - feedback_host - host to which feedbacks are sent,
> default="https://feedback.tarantool.io".
> - feedback_interval - time interval in seconds of feedbacks
> sending, default=3600.
> * Add possibility to generate feedback file in json format with
> function box.feedback.save
The test suite is failing:
TAP version 13
1..9
2018-03-05 09:04:33.542 [29759] main/101/feedback_daemon.test.lua F> ...cal/wo
no field package.preload['http.server']
no file './http/server.lua'
no file './http/server/init.lua'
no file './http/server.so'
no file '/opt/local/work/tarantool/test/var/001_box-tap/.rocks/share/taran
no file '/opt/local/work/tarantool/test/var/001_box-tap/.rocks/share/taran
no file '/opt/local/work/tarantool/test/var/.rocks/share/tarantool/http/
I suggest you write a primitive http server for test purposes - it should
be 100-200 lines of code, print http greeting and read any input
without validating it.
> +local function stop(self)
> + if (get_fiber_id(self.guard) ~= 0) then
> + self.guard:cancel()
> + --
> + -- this cycle may be replaced with fiber_join
> + -- so guard fiber may be set joinable
> + --
> + while self.guard:status() ~= 'dead' do
> + fiber.sleep(0.001)
> + end
Please avoid using fiber.sleep() in a loop. Please use
a separate shutdown channel instead, until we get joinable
fibers.
> + self.guard = nil
> + end
> + if (get_fiber_id(self.fiber) ~= 0) then
> + self.control:put("shutdown")
> + while self.fiber:status() ~= 'dead' do
> + fiber.sleep(0.001)
> + end
> + self.fiber = nil
> + self.control = nil
> + end
> + log.verbose("%s stopped", PREFIX)
> +end
Same here.
> +
> +local function reload(self)
> + self:stop()
> + self:start()
> +end
> +
> +setmetatable(daemon, {
> + __index = {
> + set_feedback_params = function()
> + daemon.enabled = box.cfg.feedback_enabled
> + daemon.host = box.cfg.feedback_host
> + daemon.interval = box.cfg.feedback_interval
> + reload(daemon)
> + return
> + end,
> + -- this function is used in saving feedback in file
> + generate_feedback = function()
> + return fill_in_feedback({ feedback_type = "version", feedback_version = 1 })
> + end,
> + start = function()
> + start(daemon)
> + end,
> + stop = function()
> + stop(daemon)
> + end,
> + reload = function()
> + reload(daemon)
> + end,
> + send_test = function()
> + if daemon.control ~= nil then
> + daemon.control:put("send")
> + end
> + end
> + }
> +})
> +
> +if box.internal == nil then
> + box.internal = { [PREFIX] = daemon }
> +else
> + box.internal[PREFIX] = daemon
> +end
> diff --git a/src/box/lua/init.c b/src/box/lua/init.c
> index 7547758..d4b5788 100644
> --- a/src/box/lua/init.c
> +++ b/src/box/lua/init.c
> @@ -65,6 +65,7 @@ extern char session_lua[],
> load_cfg_lua[],
> xlog_lua[],
> checkpoint_daemon_lua[],
> + feedback_daemon_lua[],
> net_box_lua[],
> upgrade_lua[],
> console_lua[];
> @@ -74,6 +75,7 @@ static const char *lua_sources[] = {
> "box/tuple", tuple_lua,
> "box/schema", schema_lua,
> "box/checkpoint_daemon", checkpoint_daemon_lua,
> + "box/feedback_daemon", feedback_daemon_lua,
> "box/upgrade", upgrade_lua,
> "box/net_box", net_box_lua,
> "box/console", console_lua,
> diff --git a/src/box/lua/load_cfg.lua b/src/box/lua/load_cfg.lua
> index d4f2128..89fd774 100644
> --- a/src/box/lua/load_cfg.lua
> +++ b/src/box/lua/load_cfg.lua
> @@ -59,6 +59,9 @@ local default_cfg = {
> replication_sync_lag = 10,
> replication_connect_timeout = 4,
> replication_connect_quorum = nil, -- connect all
> + feedback_enabled = true,
> + feedback_host = "https://feedback.tarantool.io",
> + feedback_interval = 3600,
> }
>
> -- types of available options
> @@ -115,6 +118,9 @@ local template_cfg = {
> replication_sync_lag = 'number',
> replication_connect_timeout = 'number',
> replication_connect_quorum = 'number',
> + feedback_enabled = 'boolean',
> + feedback_host = 'string',
> + feedback_interval = 'number',
> }
>
> local function normalize_uri(port)
> @@ -175,6 +181,9 @@ local dynamic_cfg = {
> checkpoint_count = private.cfg_set_checkpoint_count,
> checkpoint_interval = private.checkpoint_daemon.set_checkpoint_interval,
> worker_pool_threads = private.cfg_set_worker_pool_threads,
> + feedback_enabled = private.feedback_daemon.set_feedback_params,
> + feedback_host = private.feedback_daemon.set_feedback_params,
> + feedback_interval = private.feedback_daemon.set_feedback_params,
> -- do nothing, affects new replicas, which query this value on start
> wal_dir_rescan_delay = function() end,
> custom_proc_title = function()
> diff --git a/src/box/lua/schema.lua b/src/box/lua/schema.lua
> index 30c6bc6..8d2f11d 100644
> --- a/src/box/lua/schema.lua
> +++ b/src/box/lua/schema.lua
> @@ -5,6 +5,8 @@ local msgpack = require('msgpack')
> local msgpackffi = require('msgpackffi')
> local fun = require('fun')
> local log = require('log')
> +local fio = require('fio')
> +local json = require('json')
> local session = box.session
> local internal = require('box.internal')
> local function setmap(table)
> @@ -2234,4 +2236,16 @@ box.internal.schema.init = function()
> box_sequence_init()
> end
>
> +box.feedback = {}
> +box.feedback.save = function(file_name)
> + local feedback = json.encode(box.internal.feedback_daemon.generate_feedback())
> + local fh, err = fio.open(file_name, {'O_CREAT', 'O_RDWR', 'O_TRUNC'},
> + tonumber('0777', 8))
> + if not fh then
> + error(err)
> + end
> + fh:write(feedback)
> + fh:close()
> +end
Thanks,
--
Konstantin Osipov, Moscow, Russia, +7 903 626 22 32
http://tarantool.org - www.twitter.com/kostja_osipov
More information about the Tarantool-patches
mailing list