Skip to content

Commit 1bba8b2

Browse files
yngvar-antonssonvasiliy-t
authored andcommitted
graphite plugin kills previous workers on init
1 parent 84be519 commit 1bba8b2

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99
- metrics.clear() disables default metrics
1010
- cartridge role is permanent
1111
- cartridge role configuration without clusterwide config
12+
- graphite plugin kills previous workers on init
1213

1314
### Added
1415
- Luajit platform metrics

metrics/plugins/graphite/init.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ local fiber = require('fiber')
33
local metrics = require('metrics')
44
local checks = require('checks')
55
local log = require('log')
6+
local fun = require('fun')
67

78
local graphite = {}
89

@@ -70,6 +71,10 @@ function graphite.init(opts)
7071
local port = opts.port or DEFAULT_PORT
7172
local send_interval = opts.send_interval or DEFAULT_SEND_INTERVAL
7273

74+
fun.iter(fiber.info()):
75+
filter(function(_, x) return x.name == 'metrics_graphite_worker' end):
76+
each(function(x) fiber.kill(x) end)
77+
7378
fiber.create(graphite_worker, {
7479
prefix = prefix,
7580
sock = sock,

test/plugins/graphite_test.lua

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/usr/bin/env tarantool
2+
3+
require('strict').on()
4+
5+
local t = require('luatest')
6+
local g = t.group()
7+
8+
local metrics = require('metrics')
9+
local fiber = require('fiber')
10+
local fun = require('fun')
11+
local graphite = require('metrics.plugins.graphite')
12+
13+
g.before_all(function()
14+
box.cfg{}
15+
box.schema.user.grant(
16+
'guest', 'read,write,execute', 'universe', nil, {if_not_exists = true}
17+
)
18+
local s = box.schema.space.create(
19+
'random_space_for_graphite',
20+
{if_not_exists = true})
21+
s:create_index('pk', {if_not_exists = true})
22+
23+
local s_vinyl = box.schema.space.create(
24+
'random_vinyl_space_for_graphite',
25+
{if_not_exists = true, engine = 'vinyl'})
26+
s_vinyl:create_index('pk', {if_not_exists = true})
27+
28+
-- Delete all previous collectors and global labels
29+
metrics.clear()
30+
31+
-- Enable default metrics collections
32+
metrics.enable_default_metrics();
33+
end)
34+
35+
g.after_each(function()
36+
-- Delete all collectors and global labels
37+
metrics.clear()
38+
end)
39+
40+
local function mock_graphite_worker()
41+
fiber.create(function()
42+
fiber.name('metrics_graphite_worker')
43+
while true do fiber.sleep(0.01) end
44+
end)
45+
end
46+
47+
local function count_workers()
48+
return fun.iter(fiber.info()):
49+
filter(function(_, x) return x.name == 'metrics_graphite_worker' end):
50+
length()
51+
end
52+
53+
g.test_graphite_kills_previous_fibers_on_init = function()
54+
mock_graphite_worker()
55+
mock_graphite_worker()
56+
local workers_cnt = count_workers()
57+
t.assert_equals(workers_cnt, 2)
58+
59+
graphite.init({})
60+
61+
fiber.sleep(0.5)
62+
workers_cnt = count_workers()
63+
t.assert_equals(workers_cnt, 1)
64+
end
65+

0 commit comments

Comments
 (0)