-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Metric `sharded_queue_api_role_stats` is a summary of `sharded_queue.api` role API calls. The metric includes a counter of API calls and errors[1]. The metric contains labels in the following format: `{name = "tube_name", method = "api_call_method", status = "ok" or "error"}` * Metric `sharded_queue_storage_role_stats` is a summary of `sharded_queue.storage` role API calls. The metric includes a counter of API calls and errors[1]. The metric contains labels in the following format: `{name = "tube_name", method = "api_call_method", status = "ok" or "error"}` * Metric `sharded_queue_storage_calls` as an equivalent of `sharded_queue_calls` for the `sharded_queue.storage` role. Values have the same meaning as the `queue` statistics `calls` table[2]. The metric contains labels in the following format: `{name = "tube_name", status = "call_name"}` * Metric `sharded_queue_storage_tasks` as an equivalent of `sharded_queue_tasks` for the `sharded_queue.storage` role. Values have the same meaning as the `queue` statistics `tasks` table[2]. The metric contains labels in the following format: `{name = "tube_name", status = "task_status"}` 1. https://github.com/tarantool/metrics/?tab=readme-ov-file#summary 2. https://github.com/tarantool/queue?tab=readme-ov-file#getting-statistics Closes #69 Closes #71
- Loading branch information
1 parent
5e5fd9f
commit 9e8b9ef
Showing
7 changed files
with
522 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
---- Module with metrics helper code. | ||
local is_metrics_package, metrics = pcall(require, "metrics") | ||
|
||
local function create_collectors(self, role) | ||
local role_full = "sharded_queue." .. role | ||
local collectors = {} | ||
|
||
-- Unique names help to avoid clashes on instances with both roles. | ||
collectors.api_stats = { | ||
collector = metrics.summary( | ||
string.format("sharded_queue_%s_role_stats", role), | ||
string.format("sharded_queue's number of %s API calls", role_full), | ||
{[0.5]=0.01, [0.95]=0.01, [0.99]=0.01}, | ||
{max_age_time = 60, age_buckets_count = 5} | ||
), | ||
values = {}, | ||
} | ||
|
||
if role == "api" then | ||
-- Backward compatibility for the sharded_queue.api role. | ||
collectors.calls = { | ||
collector = metrics.counter( | ||
"sharded_queue_calls", | ||
"sharded_queue's number of calls" | ||
), | ||
values = {}, | ||
} | ||
collectors.tasks = { | ||
collector = metrics.gauge( | ||
"sharded_queue_tasks", | ||
"sharded_queue's number of tasks" | ||
), | ||
} | ||
else | ||
-- But for other roles we need another names to avoid clashes on | ||
-- instances with both roles. | ||
collectors.calls = { | ||
collector = metrics.counter( | ||
string.format("sharded_queue_%s_calls", role), | ||
string.format("sharded_queue's number of calls on %s", role_full) | ||
), | ||
values = {}, | ||
} | ||
collectors.tasks = { | ||
collector = metrics.gauge( | ||
string.format("sharded_queue_%s_tasks", role), | ||
string.format("sharded_queue's number of tasks on %s", role_full) | ||
), | ||
} | ||
end | ||
self.collectors = collectors | ||
end | ||
|
||
local function enable(self, role, tubes, get_statistic_callback) | ||
-- Drop all collectors and a callback. | ||
self:disable(self) | ||
|
||
-- Set all collectors and the callback. | ||
create_collectors(self, role) | ||
local callback = function() | ||
for tube_name, _ in pairs(tubes) do | ||
local statistics = get_statistic_callback(tube_name) | ||
|
||
if statistics ~= nil then | ||
local collectors = self.collectors | ||
if collectors.calls.values[tube_name] == nil then | ||
collectors.calls.values[tube_name] = {} | ||
end | ||
|
||
for k, v in pairs(statistics.calls) do | ||
local prev = collectors.calls.values[tube_name][k] or 0 | ||
local inc = v - prev | ||
collectors.calls.collector:inc(inc, { | ||
name = tube_name, | ||
status = k, | ||
}) | ||
collectors.calls.values[tube_name][k] = v | ||
end | ||
for k, v in pairs(statistics.tasks) do | ||
collectors.tasks.collector:set(v, { | ||
name = tube_name, | ||
status = k, | ||
}) | ||
end | ||
end | ||
end | ||
end | ||
|
||
metrics.register_callback(callback) | ||
self.callback = callback | ||
return true | ||
end | ||
|
||
local function disable(self) | ||
if self.callback then | ||
metrics.unregister_callback(self.callback) | ||
end | ||
self.callback = nil | ||
|
||
if self.collectors then | ||
for _, c in pairs(self.collectors) do | ||
metrics.registry:unregister(c.collector) | ||
end | ||
end | ||
self.collectors = nil | ||
end | ||
|
||
local function observe(self, latency, tube, method, ok) | ||
if self.collectors ~= nil then | ||
local status = ok and 'ok' or 'error' | ||
self.collectors.api_stats.collector:observe( | ||
latency, {name = tube, method = method, status = status}) | ||
end | ||
end | ||
|
||
local mt = { | ||
__index = { | ||
enable = enable, | ||
disable = disable, | ||
observe = observe, | ||
} | ||
} | ||
|
||
local function is_v_0_11_installed() | ||
if not is_metrics_package or metrics.unregister_callback == nil then | ||
return false | ||
end | ||
local counter = require('metrics.collectors.counter') | ||
return counter.remove and true or false | ||
end | ||
|
||
local function init(stash) | ||
setmetatable(stash, mt) | ||
return stash | ||
end | ||
|
||
return { | ||
is_supported = is_v_0_11_installed, | ||
init = init, | ||
} |
Oops, something went wrong.