From: Serge Petrenko via Tarantool-patches <tarantool-patches@dev.tarantool.org> To: v.shpilevoy@tarantool.org, alexander.turenko@tarantool.org Cc: tarantool-patches@dev.tarantool.org Subject: Re: [Tarantool-patches] [PATCH 4/4] feedback_daemon: generate report right before sending Date: Mon, 5 Apr 2021 17:03:23 +0300 [thread overview] Message-ID: <6216debc-5807-ede1-df21-823d60a1e70b@tarantool.org> (raw) In-Reply-To: <44f4b260e0ac435fe78282c1f6f4607159914935.1617375300.git.sergepetrenko@tarantool.org> 02.04.2021 17:58, Serge Petrenko пишет: > Feedback daemon used to generate report before waiting (for an hour by > default) until it's time to send it. Better actualize the reports and > generate them right when it's time to send them. > > Follow-up #5750 > --- > src/box/lua/feedback_daemon.lua | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/src/box/lua/feedback_daemon.lua b/src/box/lua/feedback_daemon.lua > index 2ce768642..0aab189b6 100644 > --- a/src/box/lua/feedback_daemon.lua > +++ b/src/box/lua/feedback_daemon.lua > @@ -327,12 +327,13 @@ local function feedback_loop(self) > fiber.name(PREFIX, { truncate = true }) > > while true do > - local feedback = self:generate_feedback() > local msg = self.control:get(self.interval) > -- if msg == "send" then we simply send feedback > if msg == "stop" then > break > - elseif feedback ~= nil then > + end > + local feedback = self:generate_feedback() > + if feedback ~= nil then > pcall(http.post, self.host, json.encode(feedback), {timeout=1}) > end > end Pushed a new commit on top: ===================================== Bump `feedback_version` to 7 and introduce a new field: `feedback.events`. It holds a counter for every event we may choose to register later on. Currently the possible events are "create_space", "drop_space", "create_index", "drop_index". All the registered events and corresponding counters are sent in a report in `feedback.events` field. Also, the first registered event triggers the report sending right away. So, we may follow such events like "first space/index created/dropped" Closes #5750 --- src/box/lua/feedback_daemon.lua | 26 ++++++++++++++++++++++++-- src/box/lua/schema.lua | 16 ++++++++++++++++ test/box-tap/feedback_daemon.test.lua | 23 ++++++++++++++++++++++- 3 files changed, 62 insertions(+), 3 deletions(-) diff --git a/src/box/lua/feedback_daemon.lua b/src/box/lua/feedback_daemon.lua index 0aab189b6..ca93b7574 100644 --- a/src/box/lua/feedback_daemon.lua +++ b/src/box/lua/feedback_daemon.lua @@ -312,13 +312,18 @@ local function fill_in_stats(feedback) feedback.stats = stats end -local function fill_in_feedback(feedback) +local function fill_in_events(self, feedback) + feedback.events = self.cached_events +end + +local function fill_in_feedback(self, feedback) fill_in_base_info(feedback) fill_in_platform_info(feedback) fill_in_repo_url(feedback) fill_in_features(feedback) fill_in_options(feedback) fill_in_stats(feedback) + fill_in_events(self, feedback) return feedback end @@ -358,12 +363,26 @@ local function guard_loop(self) self.shutdown:put("stopped") end +local function save_event(self, event) + if type(event) ~= 'string' then + error("Usage: box.internal.feedback_daemon.save_event(string)") + end + local cnt = self.cached_events[event] or 0 + self.cached_events[event] = (self.cached_events[event] or 0) + 1 + if self.cached_events[event] == 1 then + -- The first occurred event of this type triggers report dispatch + -- immediately. + self.send() + end +end + -- these functions are used for test purposes only local function start(self) self:stop() if self.enabled then self.control = fiber.channel() self.shutdown = fiber.channel() + self.cached_events = {} self.guard = fiber.create(guard_loop, self) end log.verbose("%s started", PREFIX) @@ -402,7 +421,7 @@ setmetatable(daemon, { end, -- this function is used in saving feedback in file generate_feedback = function() - return fill_in_feedback({ feedback_version = 6 }) + return fill_in_feedback(daemon, { feedback_version = 7 }) end, start = function() start(daemon) @@ -413,6 +432,9 @@ setmetatable(daemon, { reload = function() reload(daemon) end, + save_event = function(event) + save_event(daemon, event) + end, send = function() if daemon.control ~= nil then daemon.control:put("send") diff --git a/src/box/lua/schema.lua b/src/box/lua/schema.lua index 96503a50e..cf1b070af 100644 --- a/src/box/lua/schema.lua +++ b/src/box/lua/schema.lua @@ -462,6 +462,10 @@ box.schema.space.create = function(name, options) }) _space:insert{id, uid, name, options.engine, options.field_count, space_options, format} + + if internal.feedback_daemon ~= nil then + internal.feedback_daemon.save_event("create_space") + end return box.space[id], "created" end @@ -531,6 +535,9 @@ box.schema.space.drop = function(space_id, space_name, opts) box.error(box.error.NO_SUCH_SPACE, space_name) end end + if internal.feedback_daemon ~= nil then + internal.feedback_daemon.save_event("drop_space") + end end box.schema.space.rename = function(space_id, space_name) @@ -1237,6 +1244,11 @@ box.schema.index.create = function(space_id, name, options) local _func_index = box.space[box.schema.FUNC_INDEX_ID] _func_index:insert{space_id, iid, index_opts.func} end + + if internal.feedback_daemon ~= nil then + internal.feedback_daemon.save_event("create_index") + end + return space.index[name] end @@ -1257,6 +1269,10 @@ box.schema.index.drop = function(space_id, index_id) _func_index:delete({v.space_id, v.index_id}) end _index:delete{space_id, index_id} + + if internal.feedback_daemon ~= nil then + internal.feedback_daemon.save_event("drop_index") + end end box.schema.index.rename = function(space_id, index_id, name) diff --git a/test/box-tap/feedback_daemon.test.lua b/test/box-tap/feedback_daemon.test.lua index 3d6bf1d9b..a2e041649 100755 --- a/test/box-tap/feedback_daemon.test.lua +++ b/test/box-tap/feedback_daemon.test.lua @@ -70,7 +70,7 @@ if not ok then os.exit(0) end -test:plan(28) +test:plan(30) local function check(message) while feedback_count < 1 do @@ -293,5 +293,26 @@ check_stats(actual.stats) actual = daemon.generate_feedback() test:is(box.info.uptime, actual.uptime, "Server uptime is reported and is correct.") +daemon.reload() +actual = daemon.generate_feedback() + +local events_expected = {} +test:is_deeply(actual.events, events_expected, "Events are empty initially.") + +box.schema.space.create('test') +box.space.test:create_index('pk') +box.space.test.index.pk:drop() +box.space.test:drop() + +actual = daemon.generate_feedback() +events_expected = { + create_space = 1, + create_index = 1, + drop_space = 1, + drop_index = 1, +} + +test:is_deeply(actual.events, events_expected, "Events are counted correctly") + test:check() os.exit(0) -- 2.24.3 (Apple Git-128) -- Serge Petrenko
next prev parent reply other threads:[~2021-04-05 14:03 UTC|newest] Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-04-02 14:57 [Tarantool-patches] [PATCH 0/4] send feedback on tarantool start Serge Petrenko via Tarantool-patches 2021-04-02 14:58 ` [Tarantool-patches] [PATCH 1/4] feedback_daemon: include server uptime in the report Serge Petrenko via Tarantool-patches 2021-04-02 14:58 ` [Tarantool-patches] [PATCH 2/4] feedback_daemon: rename `send_test` to `send` Serge Petrenko via Tarantool-patches 2021-04-02 14:58 ` [Tarantool-patches] [PATCH 3/4] feedback_daemon: send feedback on server start Serge Petrenko via Tarantool-patches 2021-04-05 13:18 ` Vladislav Shpilevoy via Tarantool-patches 2021-04-05 14:05 ` Serge Petrenko via Tarantool-patches 2021-04-05 16:11 ` Vladislav Shpilevoy via Tarantool-patches 2021-04-08 13:41 ` Serge Petrenko via Tarantool-patches 2021-04-02 14:58 ` [Tarantool-patches] [PATCH 4/4] feedback_daemon: generate report right before sending Serge Petrenko via Tarantool-patches 2021-04-05 14:03 ` Serge Petrenko via Tarantool-patches [this message] 2021-04-05 16:23 ` Vladislav Shpilevoy via Tarantool-patches 2021-04-06 8:18 ` Serge Petrenko via Tarantool-patches
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=6216debc-5807-ede1-df21-823d60a1e70b@tarantool.org \ --to=tarantool-patches@dev.tarantool.org \ --cc=alexander.turenko@tarantool.org \ --cc=sergepetrenko@tarantool.org \ --cc=v.shpilevoy@tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH 4/4] feedback_daemon: generate report right before sending' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox