[Tarantool-patches] [PATCH v2 5/5] feedback_daemon: count and report some events

Serge Petrenko sergepetrenko at tarantool.org
Thu Apr 8 16:38:41 MSK 2021


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       | 31 ++++++++++++++++++++++++---
 src/box/lua/schema.lua                | 14 ++++++++++++
 test/box-tap/feedback_daemon.test.lua | 23 +++++++++++++++++++-
 3 files changed, 64 insertions(+), 4 deletions(-)

diff --git a/src/box/lua/feedback_daemon.lua b/src/box/lua/feedback_daemon.lua
index 93bbb2a11..660ef8403 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
@@ -368,12 +373,29 @@ 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
+    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()
+        -- There may be up to 5 fibers triggering a send during bootstrap or
+        -- shortly after it. And maybe more to come. Do not make anyone wait for
+        -- feedback daemon to process the incoming events, and set channel size
+        -- to 10 just in case.
+        self.control = fiber.channel(10)
         self.shutdown = fiber.channel()
+        self.cached_events = {}
         self.guard = fiber.create(guard_loop, self)
     end
     log.verbose("%s started", PREFIX)
@@ -412,7 +434,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)
@@ -423,6 +445,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..93ecf7440 100644
--- a/src/box/lua/schema.lua
+++ b/src/box/lua/schema.lua
@@ -321,6 +321,12 @@ local function update_param_table(table, defaults)
     return new_table
 end
 
+local function feedback_save_event(event)
+    if internal.feedback_daemon ~= nil then
+        internal.feedback_daemon.save_event(event)
+    end
+end
+
 box.begin = function()
     if builtin.box_txn_begin() == -1 then
         box.error()
@@ -462,6 +468,8 @@ box.schema.space.create = function(name, options)
     })
     _space:insert{id, uid, name, options.engine, options.field_count,
         space_options, format}
+
+    feedback_save_event('create_space')
     return box.space[id], "created"
 end
 
@@ -531,6 +539,8 @@ box.schema.space.drop = function(space_id, space_name, opts)
             box.error(box.error.NO_SUCH_SPACE, space_name)
         end
     end
+
+    feedback_save_event('drop_space')
 end
 
 box.schema.space.rename = function(space_id, space_name)
@@ -1237,6 +1247,8 @@ 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
+
+    feedback_save_event('create_index')
     return space.index[name]
 end
 
@@ -1257,6 +1269,8 @@ 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}
+
+    feedback_save_event('drop_index')
 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)



More information about the Tarantool-patches mailing list