mirror of
https://github.com/valitydev/url-shortener.git
synced 2024-11-06 01:55:19 +00:00
add "health" handle (#4)
This commit is contained in:
parent
3350b50d6d
commit
0f68121437
@ -17,7 +17,8 @@
|
||||
swag_server,
|
||||
mg_proto,
|
||||
woody,
|
||||
woody_user_identity
|
||||
woody_user_identity,
|
||||
erl_health
|
||||
]},
|
||||
{env, []},
|
||||
{modules, []},
|
||||
|
@ -38,14 +38,15 @@ start_link() ->
|
||||
-spec init([]) -> {ok, {supervisor:sup_flags(), [supervisor:child_spec()]}}.
|
||||
|
||||
init([]) ->
|
||||
HealthCheckers = genlib_app:env(?MODULE, health_checkers, []),
|
||||
{ok, {
|
||||
{one_for_all, 0, 1},
|
||||
% TODO
|
||||
get_processor_childspecs(genlib_app:env(?MODULE, processor)) ++
|
||||
get_api_childspecs(genlib_app:env(?MODULE, api))
|
||||
get_processor_childspecs(genlib_app:env(?MODULE, processor), HealthCheckers) ++
|
||||
get_api_childspecs(genlib_app:env(?MODULE, api), HealthCheckers)
|
||||
}}.
|
||||
|
||||
get_processor_childspecs(Opts) ->
|
||||
get_processor_childspecs(Opts, HealthCheckers) ->
|
||||
{ok, IP} = inet:parse_address(maps:get(ip, Opts, "::")),
|
||||
[woody_server:child_spec(
|
||||
?MODULE,
|
||||
@ -59,11 +60,13 @@ get_processor_childspecs(Opts) ->
|
||||
{mg_proto_state_processing_thrift, 'Processor'},
|
||||
shortener_slug
|
||||
}}
|
||||
]
|
||||
],
|
||||
additional_routes => [erl_health_handle:get_route(HealthCheckers)]
|
||||
}
|
||||
)].
|
||||
|
||||
get_api_childspecs(Opts) ->
|
||||
get_api_childspecs(Opts, HealthCheckers) ->
|
||||
AuthorizerSpec = shortener_authorizer_jwt:get_child_spec(maps:get(authorizer, Opts)),
|
||||
SwaggerServerSpec = shortener_swagger_server:child_spec(shortener_handler, Opts),
|
||||
HealthRoutes = [{'_', [erl_health_handle:get_route(HealthCheckers)]}],
|
||||
SwaggerServerSpec = shortener_swagger_server:child_spec(shortener_handler, Opts, HealthRoutes),
|
||||
[AuthorizerSpec, SwaggerServerSpec].
|
||||
|
@ -1,17 +1,17 @@
|
||||
-module(shortener_swagger_server).
|
||||
|
||||
-export([child_spec/2]).
|
||||
-export([child_spec/3]).
|
||||
|
||||
-define(APP, shortener).
|
||||
-define(DEFAULT_ACCEPTORS_POOLSIZE, 10).
|
||||
-define(DEFAULT_IP_ADDR, "::").
|
||||
-define(DEFAULT_PORT, 8080).
|
||||
|
||||
-spec child_spec(module(), map()) -> supervisor:child_spec().
|
||||
-spec child_spec(module(), map(), cowboy_router:routes()) -> supervisor:child_spec().
|
||||
|
||||
child_spec(LogicHandler, Opts) ->
|
||||
child_spec(LogicHandler, Opts, AdditionalRoutes) ->
|
||||
{Transport, TransportOpts} = get_socket_transport(Opts),
|
||||
CowboyOpts = get_cowboy_config(LogicHandler, Opts),
|
||||
CowboyOpts = get_cowboy_config(LogicHandler, AdditionalRoutes, Opts),
|
||||
ranch:child_spec(
|
||||
?MODULE,
|
||||
Transport,
|
||||
@ -26,10 +26,11 @@ get_socket_transport(Opts) ->
|
||||
Acceptors = maps:get(acceptors, Opts, ?DEFAULT_ACCEPTORS_POOLSIZE),
|
||||
{ranch_tcp, [{ip, IP}, {port, Port}, {num_acceptors, Acceptors}]}.
|
||||
|
||||
get_cowboy_config(LogicHandler, Opts) ->
|
||||
get_cowboy_config(LogicHandler, AdditionalRoutes, Opts) ->
|
||||
ShortUrlTemplate = maps:get(short_url_template, Opts),
|
||||
ShortUrlPath = maps:get(path, ShortUrlTemplate),
|
||||
Routes = squash_routes(
|
||||
AdditionalRoutes ++
|
||||
swag_server_router:get_paths(LogicHandler) ++
|
||||
[{'_', [{genlib:to_list(ShortUrlPath) ++ ":shortenedUrlID", shortener_handler, #{}}]}]
|
||||
),
|
||||
|
@ -57,7 +57,12 @@
|
||||
}},
|
||||
{service_clients, #{
|
||||
automaton => #{url => <<"http://machinegun:8022/v1/automaton">>}
|
||||
}}
|
||||
}},
|
||||
{health_checkers, [
|
||||
{erl_health, disk , ["/", 99] },
|
||||
{erl_health, cg_memory, [99] },
|
||||
{erl_health, service , [<<"shortener">>]}
|
||||
]}
|
||||
]}
|
||||
|
||||
].
|
||||
|
@ -70,6 +70,11 @@
|
||||
{git, "git@github.com:rbkmoney/machinegun_proto.git",
|
||||
{branch, "master"}
|
||||
}
|
||||
},
|
||||
{erl_health,
|
||||
{git, "https://github.com/rbkmoney/erlang-health.git",
|
||||
{branch, master}
|
||||
}
|
||||
}
|
||||
]}.
|
||||
|
||||
|
10
rebar.lock
10
rebar.lock
@ -1,6 +1,10 @@
|
||||
{"1.1.0",
|
||||
[{<<"base64url">>,{pkg,<<"base64url">>,<<"0.0.1">>},1},
|
||||
{<<"certifi">>,{pkg,<<"certifi">>,<<"0.7.0">>},1},
|
||||
{<<"cg_mon">>,
|
||||
{git,"https://github.com/rbkmoney/cg_mon.git",
|
||||
{ref,"5a87a37694e42b6592d3b4164ae54e0e87e24e18"}},
|
||||
1},
|
||||
{<<"cowboy">>,{pkg,<<"cowboy">>,<<"1.0.4">>},0},
|
||||
{<<"cowboy_access_log">>,
|
||||
{git,"git@github.com:rbkmoney/cowboy_access_log.git",
|
||||
@ -11,6 +15,10 @@
|
||||
{ref,"392f5804b63fff2bd0fda67671d5b2fbe0badd37"}},
|
||||
0},
|
||||
{<<"cowlib">>,{pkg,<<"cowlib">>,<<"1.0.2">>},1},
|
||||
{<<"erl_health">>,
|
||||
{git,"https://github.com/rbkmoney/erlang-health.git",
|
||||
{ref,"0398b5c6cf276732cb5d2170f247f04207cb9ebb"}},
|
||||
0},
|
||||
{<<"genlib">>,
|
||||
{git,"https://github.com/rbkmoney/genlib.git",
|
||||
{ref,"7fc1ca1a57dbe2b8b837951095e314c32afd6c9a"}},
|
||||
@ -57,7 +65,7 @@
|
||||
1},
|
||||
{<<"woody">>,
|
||||
{git,"git@github.com:rbkmoney/woody_erlang.git",
|
||||
{ref,"ad1e91050c36d8de15f1c7d8dd8a2c682d2d158c"}},
|
||||
{ref,"d9362a5f8128c031300958da09c237ca27076cc5"}},
|
||||
0},
|
||||
{<<"woody_user_identity">>,
|
||||
{git,"git@github.com:rbkmoney/woody_erlang_user_identity.git",
|
||||
|
Loading…
Reference in New Issue
Block a user