Skip to content

Commit 8f72fc9

Browse files
Add traffic to generate data for all dashboard panels
Add endpoints responding with 4xx/5xx codes and HTTP traffic on them with luatest. Add space on every instance and run space operations of each type with luatest.
1 parent f25d4d8 commit 8f72fc9

File tree

4 files changed

+193
-36
lines changed

4 files changed

+193
-36
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77
## [Unreleased]
88
### Added
99
- Publish dashboard on Grafana official and community built dashboards
10+
- Generate HTTP and space operations traffic for example cluster with luatest
1011

1112
### Changed
1213
- Update metrics version to 0.3.0 in experimental cluster
1314
- Rework example Tarantool instance on "cartridge.roles.metrics"
15+
- Rework example Tarantool docker to start multiple instances with luatest
1416
- Documentation improvements and fixes
1517

1618
## [0.1.0] - 2020-06-30

example/project/.luacheckrc

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1-
include_files = {'**/*.lua', '*.luacheckrc', '*.rockspec'}
2-
exclude_files = {'.rocks/', 'tmp/'}
3-
max_line_length = 120
1+
std = {
2+
read_globals = {'require', 'debug', 'pcall', 'xpcall', 'tostring',
3+
'tonumber', 'type', 'assert', 'ipairs', 'math', 'error', 'string',
4+
'table', 'pairs', 'os', 'io', 'select', 'unpack', 'dofile', 'next',
5+
'loadstring', 'setfenv',
6+
'rawget', 'rawset', '_G',
7+
'getmetatable', 'setmetatable',
8+
'print', 'tonumber64', 'arg'
9+
10+
},
11+
globals = {'box', 'vshard', 'package',
12+
'applier'
13+
}
14+
}
15+
redefined = false

example/project/app/roles/custom.lua

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
local cartridge = require('cartridge')
2+
local config = require('cartridge.argparse')
23

34
local function init(opts) -- luacheck: no unused args
4-
-- if opts.is_master then
5-
-- end
5+
local local_cfg = config.get_opts({
6+
user = 'string',
7+
password = 'string'
8+
})
9+
610
local metrics = cartridge.service_get('metrics')
711
local http_middleware = metrics.http_middleware
812

@@ -13,11 +17,44 @@ local function init(opts) -- luacheck: no unused args
1317
{ method = 'GET', path = '/hello' },
1418
http_middleware.v1(
1519
function()
16-
return { body = 'Hello world!' }
20+
return { status = 200, body = 'Hello world!' }
21+
end,
22+
http_collector
23+
)
24+
)
25+
httpd:route(
26+
{ method = 'GET', path = '/hell0' },
27+
http_middleware.v1(
28+
function()
29+
return { status = 400, body = 'Hell0 world!' }
1730
end,
1831
http_collector
1932
)
2033
)
34+
httpd:route(
35+
{ method = 'POST', path = '/goodbye' },
36+
http_middleware.v1(
37+
function()
38+
return { status = 500, body = 'Goodbye cruel world!' }
39+
end,
40+
http_collector
41+
)
42+
)
43+
44+
if opts.is_master then
45+
local sp = box.schema.space.create('MY_SPACE', { if_not_exists = true })
46+
sp:format({
47+
{ name = 'key', type = 'number', is_nullable = false },
48+
{ name = 'value', type = 'string', is_nullable = false },
49+
})
50+
sp:create_index('pk', { parts = { 'key' }, if_not_exists = true })
51+
52+
if local_cfg.user and local_cfg.password then
53+
-- cluster-wide user privileges
54+
box.schema.user.create(local_cfg.user, { password = local_cfg.password, if_not_exists = true })
55+
box.schema.user.grant(local_cfg.user, 'read,write,execute', 'universe', nil, { if_not_exists = true })
56+
end
57+
end
2158

2259
return true
2360
end

example/project/cluster/integration/bootstrap_test.lua

Lines changed: 136 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,31 @@
11
local test = require('luatest')
22
local group = test.group('cluster')
3-
local fiber = require('fiber')
43

54
local helper = require('test.helper')
65
local cluster_helpers = require('cartridge.test-helpers')
76

7+
local app = 'example-app'
8+
local log_level = 6
9+
10+
local cluster_alias = {
11+
tnt_router = 'tnt_router',
12+
tnt_storage_1_master = 'tnt_storage_1_master',
13+
tnt_storage_1_replica = 'tnt_storage_1_replica',
14+
tnt_storage_2_master = 'tnt_storage_2_master',
15+
tnt_storage_2_replica = 'tnt_storage_2_replica',
16+
}
17+
818
local replicasets = {
919
{
1020
uuid = cluster_helpers.uuid('a'),
1121
roles = { 'vshard-router', 'app.roles.custom' },
1222
servers = {
1323
{
1424
instance_uuid = cluster_helpers.uuid('a', 1),
15-
alias = 'tnt-router',
25+
alias = cluster_alias.tnt_router,
1626
env = {
17-
['TARANTOOL_APP_NAME'] = 'example-app',
18-
['TARANTOOL_LOG_LEVEL'] = 6,
27+
['TARANTOOL_APP_NAME'] = app,
28+
['TARANTOOL_LOG_LEVEL'] = log_level,
1929
}
2030
}
2131
},
@@ -26,18 +36,18 @@ local replicasets = {
2636
servers = {
2737
{
2838
instance_uuid = cluster_helpers.uuid('b', 1),
29-
alias = 'tnt-storage-1-master',
39+
alias = cluster_alias.tnt_storage_1_master,
3040
env = {
31-
['TARANTOOL_APP_NAME'] = 'example-app',
32-
['TARANTOOL_LOG_LEVEL'] = 6,
41+
['TARANTOOL_APP_NAME'] = app,
42+
['TARANTOOL_LOG_LEVEL'] = log_level,
3343
}
3444
},
3545
{
3646
instance_uuid = cluster_helpers.uuid('b', 2),
37-
alias = 'tnt-storage-1-replica',
47+
alias = cluster_alias.tnt_storage_1_replica,
3848
env = {
39-
['TARANTOOL_APP_NAME'] = 'example-app',
40-
['TARANTOOL_LOG_LEVEL'] = 6,
49+
['TARANTOOL_APP_NAME'] = app,
50+
['TARANTOOL_LOG_LEVEL'] = log_level,
4151
}
4252
},
4353
}
@@ -48,31 +58,24 @@ local replicasets = {
4858
servers = {
4959
{
5060
instance_uuid = cluster_helpers.uuid('c', 1),
51-
alias = 'tnt-storage-2-master',
61+
alias = cluster_alias.tnt_storage_2_master,
5262
env = {
53-
['TARANTOOL_APP_NAME'] = 'example-app',
54-
['TARANTOOL_LOG_LEVEL'] = 6,
63+
['TARANTOOL_APP_NAME'] = app,
64+
['TARANTOOL_LOG_LEVEL'] = log_level,
5565
}
5666
},
5767
{
5868
instance_uuid = cluster_helpers.uuid('c', 2),
59-
alias = 'tnt-storage-2-replica',
69+
alias = cluster_alias.tnt_storage_2_replica,
6070
env = {
61-
['TARANTOOL_APP_NAME'] = 'example-app',
62-
['TARANTOOL_LOG_LEVEL'] = 6,
71+
['TARANTOOL_APP_NAME'] = app,
72+
['TARANTOOL_LOG_LEVEL'] = log_level,
6373
}
6474
}
6575
},
6676
}
6777
}
6878

69-
local instances = {}
70-
for _, replicaset in ipairs(replicasets) do
71-
for _, server in ipairs(replicaset.servers) do
72-
table.insert(instances, server.alias)
73-
end
74-
end
75-
7679
test.before_suite(function()
7780
group.cluster = cluster_helpers.Cluster:new({
7881
datadir = helper.datadir,
@@ -102,25 +105,128 @@ test.after_suite(function()
102105
group.cluster:stop()
103106
end)
104107

105-
local function http_request(alias, count)
108+
local tnt_router = group.cluster:server(cluster_alias.tnt_router)
109+
local tnt_storage_1_master = group.cluster:server(cluster_alias.tnt_storage_1_master)
110+
local tnt_storage_1_replica = group.cluster:server(cluster_alias.tnt_storage_1_replica)
111+
local tnt_storage_2_master = group.cluster:server(cluster_alias.tnt_storage_2_master)
112+
local tnt_storage_2_replica = group.cluster:server(cluster_alias.tnt_storage_2_replica)
113+
114+
-- Space operations constants
115+
local SELECT = 'select'
116+
local INSERT = 'insert'
117+
local UPDATE = 'update'
118+
local UPSERT = 'upsert'
119+
local REPLACE = 'replace'
120+
local DELETE = 'delete'
121+
122+
-- HTTP methods constants
123+
local GET = 'get'
124+
local POST = 'post'
125+
126+
local function http_request(server, method, endpoint, count)
106127
if count <= 0 then
107128
return
108129
end
109130

110131
for _ = 1, count do
111-
group.cluster:server(alias):http_request('get', '/hello')
132+
server:http_request(method, endpoint, { raise = false })
133+
end
134+
end
135+
136+
local last_key = 1
137+
138+
local charset = {} -- [0-9a-zA-Z]
139+
for c = 48, 57 do table.insert(charset, string.char(c)) end
140+
for c = 65, 90 do table.insert(charset, string.char(c)) end
141+
for c = 97, 122 do table.insert(charset, string.char(c)) end
142+
143+
local function random_string(length)
144+
if not length or length <= 0 then return '' end
145+
math.randomseed(os.clock()^5)
146+
return random_string(length - 1) .. charset[math.random(1, #charset)]
147+
end
148+
149+
local function space_operations(server, operation, count)
150+
if count <= 0 then
151+
return
152+
end
153+
154+
local space = server.net_box.space.MY_SPACE
155+
156+
if operation == SELECT then
157+
for _ = 1, count do
158+
space:select({}, { limit = 1 })
159+
end
160+
161+
elseif operation == INSERT then
162+
for _ = 1, count do
163+
space:insert{ last_key, random_string(5) }
164+
last_key = last_key + 1
165+
end
166+
167+
elseif operation == UPDATE then
168+
for _ = 1, count do
169+
local key = space:select({}, { limit = 1 })[1][1]
170+
space:update(key, {{ '=', 2, random_string(5) }})
171+
end
172+
173+
elseif operation == UPSERT then
174+
for _ = 1, count do
175+
local tuple = space:select({}, { limit = 1 })[1]
176+
space:upsert(tuple, {{ '=', 2, random_string(5) }})
177+
end
178+
179+
elseif operation == REPLACE then
180+
for _ = 1, count do
181+
local key = space:select({}, { limit = 1 })[1][1]
182+
space:replace{ key, random_string(5) }
183+
end
184+
185+
elseif operation == DELETE then
186+
for _ = 1, count do
187+
local key = space:select({}, { limit = 1 })[1][1]
188+
space:delete{ key }
189+
end
112190
end
113191
end
114192

115193
group.test_cluster = function()
116194
test.helpers.retrying({ timeout = math.huge },
117195
function()
118-
fiber.sleep(10)
196+
-- Generate some HTTP traffic
197+
http_request(tnt_router, GET, '/hello', math.random(5, 10))
198+
http_request(tnt_router, GET, '/hell0', math.random(1, 2))
199+
http_request(tnt_router, POST, '/goodbye', math.random(0, 1))
200+
http_request(tnt_storage_1_master, GET, '/hello', math.random(2, 5))
201+
http_request(tnt_storage_1_master, GET, '/hell0', math.random(0, 1))
202+
http_request(tnt_storage_1_master, POST, '/goodbye', math.random(0, 1))
203+
http_request(tnt_storage_1_replica, GET, '/hello', math.random(1, 3))
204+
http_request(tnt_storage_1_replica, GET, '/hell0', math.random(0, 1))
205+
http_request(tnt_storage_1_replica, POST, '/goodbye', math.random(0, 1))
206+
http_request(tnt_storage_2_master, GET, '/hello', math.random(2, 5))
207+
http_request(tnt_storage_2_master, GET, '/hell0', math.random(0, 1))
208+
http_request(tnt_storage_2_master, POST, '/goodbye', math.random(0, 1))
209+
http_request(tnt_storage_2_replica, GET, '/hello', math.random(1, 3))
210+
http_request(tnt_storage_2_replica, GET, '/hell0', math.random(0, 1))
211+
http_request(tnt_storage_2_replica, POST, '/goodbye', math.random(0, 1))
119212

120-
-- Generate some traffic
121-
for _, alias in ipairs(instances) do
122-
http_request(alias, math.random(0, 5))
123-
end
213+
-- Generate some space traffic
214+
space_operations(tnt_router, INSERT, math.random(1, 3))
215+
space_operations(tnt_router, UPDATE, math.random(1, 3))
216+
space_operations(tnt_storage_1_master, INSERT, math.random(5, 10))
217+
space_operations(tnt_storage_1_master, SELECT, math.random(10, 20))
218+
space_operations(tnt_storage_1_master, UPDATE, math.random(5, 10))
219+
space_operations(tnt_storage_1_master, UPSERT, math.random(5, 10))
220+
space_operations(tnt_storage_1_master, REPLACE, math.random(5, 10))
221+
space_operations(tnt_storage_1_master, DELETE, math.random(1, 2))
222+
space_operations(tnt_storage_1_replica, SELECT, math.random(3, 5))
223+
space_operations(tnt_storage_2_master, INSERT, math.random(5, 10))
224+
space_operations(tnt_storage_2_master, SELECT, math.random(10, 20))
225+
space_operations(tnt_storage_2_master, UPDATE, math.random(5, 10))
226+
space_operations(tnt_storage_2_master, UPSERT, math.random(5, 10))
227+
space_operations(tnt_storage_2_master, REPLACE, math.random(5, 10))
228+
space_operations(tnt_storage_2_master, DELETE, math.random(1, 2))
229+
space_operations(tnt_storage_2_replica, SELECT, math.random(3, 5))
124230

125231
-- Fail this function so cluster don't stop
126232
error('running cluster')

0 commit comments

Comments
 (0)