11local cartridge = require (' cartridge' )
2+ local config = require (' cartridge.argparse' )
23
34local 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
2360end
3875
3976return {
4077 role_name = ' app.roles.custom' ,
78+ dependencies = { ' cartridge.roles.metrics' },
4179 init = init ,
4280 stop = stop ,
4381 validate_config = validate_config ,
0 commit comments