[Tarantool-patches] [PATCH 4/4] feedback_daemon: generate report right before sending

Serge Petrenko sergepetrenko at tarantool.org
Mon Apr 5 17:03:23 MSK 2021



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



More information about the Tarantool-patches mailing list