Skip to content

Graphite plugin kills previous workers on init #138

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- metrics.clear() disables default metrics
- cartridge role is permanent
- cartridge role configuration without clusterwide config
- graphite plugin kills previous workers on init

### Added
- Luajit platform metrics
Expand Down
5 changes: 5 additions & 0 deletions metrics/plugins/graphite/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ local fiber = require('fiber')
local metrics = require('metrics')
local checks = require('checks')
local log = require('log')
local fun = require('fun')

local graphite = {}

Expand Down Expand Up @@ -70,6 +71,10 @@ function graphite.init(opts)
local port = opts.port or DEFAULT_PORT
local send_interval = opts.send_interval or DEFAULT_SEND_INTERVAL

fun.iter(fiber.info()):
filter(function(_, x) return x.name == 'metrics_graphite_worker' end):
each(function(x) fiber.kill(x) end)

fiber.create(graphite_worker, {
prefix = prefix,
sock = sock,
Expand Down
65 changes: 65 additions & 0 deletions test/plugins/graphite_test.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env tarantool

require('strict').on()

local t = require('luatest')
local g = t.group()

local metrics = require('metrics')
local fiber = require('fiber')
local fun = require('fun')
local graphite = require('metrics.plugins.graphite')

g.before_all(function()
box.cfg{}
box.schema.user.grant(
'guest', 'read,write,execute', 'universe', nil, {if_not_exists = true}
)
local s = box.schema.space.create(
'random_space_for_graphite',
{if_not_exists = true})
s:create_index('pk', {if_not_exists = true})

local s_vinyl = box.schema.space.create(
'random_vinyl_space_for_graphite',
{if_not_exists = true, engine = 'vinyl'})
s_vinyl:create_index('pk', {if_not_exists = true})

-- Delete all previous collectors and global labels
metrics.clear()

-- Enable default metrics collections
metrics.enable_default_metrics();
end)

g.after_each(function()
-- Delete all collectors and global labels
metrics.clear()
end)

local function mock_graphite_worker()
fiber.create(function()
fiber.name('metrics_graphite_worker')
while true do fiber.sleep(0.01) end
end)
end

local function count_workers()
return fun.iter(fiber.info()):
filter(function(_, x) return x.name == 'metrics_graphite_worker' end):
length()
end

g.test_graphite_kills_previous_fibers_on_init = function()
mock_graphite_worker()
mock_graphite_worker()
local workers_cnt = count_workers()
t.assert_equals(workers_cnt, 2)

graphite.init({})

fiber.sleep(0.5)
workers_cnt = count_workers()
t.assert_equals(workers_cnt, 1)
end