MSPF-579: Prometheus metrics (#494)

* Add Prometheus to dependencies

* Update build images

* Add MetricsRoute to config building

* Provide sample config

* Squash health and metrics routes in one argument

* Delete forgotten argument from spec

* Do not include src to release
This commit is contained in:
Toporkov Igor 2020-10-23 16:48:22 +03:00 committed by GitHub
parent ac236aedbc
commit ef87be9180
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 57 additions and 13 deletions

View File

@ -17,9 +17,10 @@ SERVICE_IMAGE_PUSH_TAG ?= $(SERVICE_IMAGE_TAG)
# Base image for the service # Base image for the service
BASE_IMAGE_NAME := service-erlang BASE_IMAGE_NAME := service-erlang
BASE_IMAGE_TAG := da0ab769f01b650b389d18fc85e7418e727cbe96 BASE_IMAGE_TAG := b7873e38b777322bbb1ce5d73507c26e6280c144
BUILD_IMAGE_TAG := 0c638a682f4735a65ef232b81ed872ba494574c3 BUILD_IMAGE_NAME := build-erlang
BUILD_IMAGE_TAG := 491bc06c745a07c6fe9e8b5dbbe958e8e0b82c4c
CALL_ANYWHERE := \ CALL_ANYWHERE := \
submodules \ submodules \

View File

@ -28,7 +28,9 @@
woody_user_identity, woody_user_identity,
payproc_errors, payproc_errors,
erl_health, erl_health,
uac uac,
prometheus,
prometheus_cowboy
]}, ]},
{env, []} {env, []}
]}. ]}.

View File

@ -27,9 +27,9 @@ init([]) ->
LechiffreSpec = lechiffre:child_spec(lechiffre, LechiffreOpts), LechiffreSpec = lechiffre:child_spec(lechiffre, LechiffreOpts),
{LogicHandler, LogicHandlerSpecs} = get_logic_handler_info(), {LogicHandler, LogicHandlerSpecs} = get_logic_handler_info(),
HealthCheck = enable_health_logging(genlib_app:env(?APP, health_check, #{})), HealthCheck = enable_health_logging(genlib_app:env(?APP, health_check, #{})),
HealthRoutes = [{'_', [erl_health_handle:get_route(HealthCheck)]}], AdditionalRoutes = [{'_', [erl_health_handle:get_route(HealthCheck), get_prometheus_route()]}],
SwaggerHandlerOpts = genlib_app:env(?APP, swagger_handler_opts, #{}), SwaggerHandlerOpts = genlib_app:env(?APP, swagger_handler_opts, #{}),
SwaggerSpec = capi_swagger_server:child_spec({HealthRoutes, LogicHandler, SwaggerHandlerOpts}), SwaggerSpec = capi_swagger_server:child_spec({AdditionalRoutes, LogicHandler, SwaggerHandlerOpts}),
BlacklistSpecs = capi_api_key_blacklist:child_spec(), BlacklistSpecs = capi_api_key_blacklist:child_spec(),
UacConf = get_uac_config(), UacConf = get_uac_config(),
ok = uac:configure(UacConf), ok = uac:configure(UacConf),
@ -57,3 +57,7 @@ get_uac_config() ->
genlib_app:env(capi, access_conf), genlib_app:env(capi, access_conf),
#{access => capi_auth:get_access_config()} #{access => capi_auth:get_access_config()}
). ).
-spec get_prometheus_route() -> {iodata(), module(), _Opts :: any()}.
get_prometheus_route() ->
{"/metrics/[:registry]", prometheus_cowboy2_handler, []}.

View File

@ -13,9 +13,9 @@
-type params() :: {cowboy_router:routes(), module(), swag_server_router:swagger_handler_opts()}. -type params() :: {cowboy_router:routes(), module(), swag_server_router:swagger_handler_opts()}.
-spec child_spec(params()) -> supervisor:child_spec(). -spec child_spec(params()) -> supervisor:child_spec().
child_spec({HealthRoutes, LogicHandler, SwaggerHandlerOpts}) -> child_spec({AdditionalRoutes, LogicHandler, SwaggerHandlerOpts}) ->
{Transport, TransportOpts} = get_socket_transport(), {Transport, TransportOpts} = get_socket_transport(),
CowboyOpts = get_cowboy_config(HealthRoutes, LogicHandler, SwaggerHandlerOpts), CowboyOpts = get_cowboy_config(AdditionalRoutes, LogicHandler, SwaggerHandlerOpts),
GsTimeout = genlib_app:env(?APP, graceful_shutdown_timeout, 5000), GsTimeout = genlib_app:env(?APP, graceful_shutdown_timeout, 5000),
Protocol = cowboy_clear, Protocol = cowboy_clear,
cowboy_draining_server:child_spec( cowboy_draining_server:child_spec(
@ -33,11 +33,11 @@ get_socket_transport() ->
AcceptorsPool = genlib_app:env(?APP, acceptors_poolsize, ?DEFAULT_ACCEPTORS_POOLSIZE), AcceptorsPool = genlib_app:env(?APP, acceptors_poolsize, ?DEFAULT_ACCEPTORS_POOLSIZE),
{ranch_tcp, #{socket_opts => [{ip, IP}, {port, Port}], num_acceptors => AcceptorsPool}}. {ranch_tcp, #{socket_opts => [{ip, IP}, {port, Port}], num_acceptors => AcceptorsPool}}.
get_cowboy_config(HealthRoutes, LogicHandler, SwaggerHandlerOpts) -> get_cowboy_config(AdditionalRoutes, LogicHandler, SwaggerHandlerOpts) ->
Dispatch = Dispatch =
cowboy_router:compile( cowboy_router:compile(
squash_routes( squash_routes(
HealthRoutes ++ AdditionalRoutes ++
swag_server_router:get_paths(LogicHandler, SwaggerHandlerOpts) swag_server_router:get_paths(LogicHandler, SwaggerHandlerOpts)
) )
), ),

View File

@ -141,5 +141,9 @@
{snowflake, [ {snowflake, [
% {machine_id, 42} % {machine_id, 42}
]},
{prometheus, [
{collectors, [default]}
]} ]}
]. ].

View File

@ -119,7 +119,9 @@
{git, "git@github.com:rbkmoney/lechiffre.git", {git, "git@github.com:rbkmoney/lechiffre.git",
{branch, master} {branch, master}
} }
} },
{prometheus, "4.6.0"},
{prometheus_cowboy, "0.1.8"}
]}. ]}.
%% XRef checks %% XRef checks
@ -147,6 +149,7 @@
{sys_config, "./config/sys.config"}, {sys_config, "./config/sys.config"},
{vm_args, "./config/vm.args"}, {vm_args, "./config/vm.args"},
{dev_mode, true}, {dev_mode, true},
{include_src, false},
{include_erts, false}, {include_erts, false},
{extended_start_script, true} {extended_start_script, true}
]}. ]}.

View File

@ -1,5 +1,6 @@
{"1.1.0", {"1.2.0",
[{<<"base64url">>,{pkg,<<"base64url">>,<<"0.0.1">>},0}, [{<<"accept">>,{pkg,<<"accept">>,<<"0.3.5">>},2},
{<<"base64url">>,{pkg,<<"base64url">>,<<"0.0.1">>},0},
{<<"bear">>,{pkg,<<"bear">>,<<"0.8.7">>},2}, {<<"bear">>,{pkg,<<"bear">>,<<"0.8.7">>},2},
{<<"bender_client">>, {<<"bender_client">>,
{git,"git@github.com:rbkmoney/bender_client_erlang.git", {git,"git@github.com:rbkmoney/bender_client_erlang.git",
@ -96,6 +97,9 @@
{git,"git@github.com:rbkmoney/payproc-errors-erlang.git", {git,"git@github.com:rbkmoney/payproc-errors-erlang.git",
{ref,"77cc445a4bb1496854586853646e543579ac1212"}}, {ref,"77cc445a4bb1496854586853646e543579ac1212"}},
0}, 0},
{<<"prometheus">>,{pkg,<<"prometheus">>,<<"4.6.0">>},0},
{<<"prometheus_cowboy">>,{pkg,<<"prometheus_cowboy">>,<<"0.1.8">>},0},
{<<"prometheus_httpd">>,{pkg,<<"prometheus_httpd">>,<<"2.1.11">>},1},
{<<"ranch">>,{pkg,<<"ranch">>,<<"1.7.1">>},1}, {<<"ranch">>,{pkg,<<"ranch">>,<<"1.7.1">>},1},
{<<"reporter_proto">>, {<<"reporter_proto">>,
{git,"git@github.com:rbkmoney/reporter-proto.git", {git,"git@github.com:rbkmoney/reporter-proto.git",
@ -130,6 +134,7 @@
0}]}. 0}]}.
[ [
{pkg_hash,[ {pkg_hash,[
{<<"accept">>, <<"B33B127ABCA7CC948BBE6CAA4C263369ABF1347CFA9D8E699C6D214660F10CD1">>},
{<<"base64url">>, <<"36A90125F5948E3AFD7BE97662A1504B934DD5DAC78451CA6E9ABF85A10286BE">>}, {<<"base64url">>, <<"36A90125F5948E3AFD7BE97662A1504B934DD5DAC78451CA6E9ABF85A10286BE">>},
{<<"bear">>, <<"16264309AE5D005D03718A5C82641FCC259C9E8F09ADEB6FD79CA4271168656F">>}, {<<"bear">>, <<"16264309AE5D005D03718A5C82641FCC259C9E8F09ADEB6FD79CA4271168656F">>},
{<<"cache">>, <<"3C11DBF4CD8FCD5787C95A5FB2A04038E3729CFCA0386016EEA8C953AB48A5AB">>}, {<<"cache">>, <<"3C11DBF4CD8FCD5787C95A5FB2A04038E3729CFCA0386016EEA8C953AB48A5AB">>},
@ -143,8 +148,33 @@
{<<"jsx">>, <<"7ACC7D785B5ABE8A6E9ADBDE926A24E481F29956DD8B4DF49E3E4E7BCC92A018">>}, {<<"jsx">>, <<"7ACC7D785B5ABE8A6E9ADBDE926A24E481F29956DD8B4DF49E3E4E7BCC92A018">>},
{<<"metrics">>, <<"25F094DEA2CDA98213CECC3AEFF09E940299D950904393B2A29D191C346A8486">>}, {<<"metrics">>, <<"25F094DEA2CDA98213CECC3AEFF09E940299D950904393B2A29D191C346A8486">>},
{<<"mimerl">>, <<"67E2D3F571088D5CFD3E550C383094B47159F3EEE8FFA08E64106CDF5E981BE3">>}, {<<"mimerl">>, <<"67E2D3F571088D5CFD3E550C383094B47159F3EEE8FFA08E64106CDF5E981BE3">>},
{<<"prometheus">>, <<"20510F381DB1CCAB818B4CF2FAC5FA6AB5CC91BC364A154399901C001465F46F">>},
{<<"prometheus_cowboy">>, <<"CFCE0BC7B668C5096639084FCD873826E6220EA714BF60A716F5BD080EF2A99C">>},
{<<"prometheus_httpd">>, <<"F616ED9B85B536B195D94104063025A91F904A4CFC20255363F49A197D96C896">>},
{<<"ranch">>, <<"6B1FAB51B49196860B733A49C07604465A47BDB78AA10C1C16A3D199F7F8C881">>}, {<<"ranch">>, <<"6B1FAB51B49196860B733A49C07604465A47BDB78AA10C1C16A3D199F7F8C881">>},
{<<"rfc3339">>, <<"1552DF616ACA368D982E9F085A0E933B6688A3F4938A671798978EC2C0C58730">>}, {<<"rfc3339">>, <<"1552DF616ACA368D982E9F085A0E933B6688A3F4938A671798978EC2C0C58730">>},
{<<"ssl_verify_fun">>, <<"F0EAFFF810D2041E93F915EF59899C923F4568F4585904D010387ED74988E77B">>}, {<<"ssl_verify_fun">>, <<"F0EAFFF810D2041E93F915EF59899C923F4568F4585904D010387ED74988E77B">>},
{<<"unicode_util_compat">>, <<"D869E4C68901DD9531385BB0C8C40444EBF624E60B6962D95952775CAC5E90CD">>}]} {<<"unicode_util_compat">>, <<"D869E4C68901DD9531385BB0C8C40444EBF624E60B6962D95952775CAC5E90CD">>}]},
{pkg_hash_ext,[
{<<"accept">>, <<"11B18C220BCC2EAB63B5470C038EF10EB6783BCB1FCDB11AA4137DEFA5AC1BB8">>},
{<<"base64url">>, <<"FAB09B20E3F5DB886725544CBCF875B8E73EC93363954EB8A1A9ED834AA8C1F9">>},
{<<"bear">>, <<"534217DCE6A719D59E54FB0EB7A367900DBFC5F85757E8C1F94269DF383F6D9B">>},
{<<"cache">>, <<"3E7D6706DE5DF76C4D71C895B4BE62B01C3DE6EDB63197035E465C3BCE63F19B">>},
{<<"certifi">>, <<"805ABD97539CAF89EC6D4732C91E62BA9DA0CDA51AC462380BBD28EE697A8C42">>},
{<<"cowboy">>, <<"04FD8C6A39EDC6AAA9C26123009200FC61F92A3A94F3178C527B70B767C6E605">>},
{<<"cowlib">>, <<"79F954A7021B302186A950A32869DBC185523D99D3E44CE430CD1F3289F41ED4">>},
{<<"gproc">>, <<"580ADAFA56463B75263EF5A5DF4C86AF321F68694E7786CB057FD805D1E2A7DE">>},
{<<"hackney">>, <<"C2790C9F0F7205F4A362512192DEE8179097394400E745E4D20BAB7226A8EAAD">>},
{<<"idna">>, <<"4BDD305EB64E18B0273864920695CB18D7A2021F31A11B9C5FBCD9A253F936E2">>},
{<<"jose">>, <<"0EFAAC15223E7CD29773296214AB3B85700D2CD1354C931342750AA1AFAF6146">>},
{<<"jsx">>, <<"B4C5D3230B397C8D95579E4A3D72826BB6463160130CCF4182F5BE8579B5F44C">>},
{<<"metrics">>, <<"69B09ADDDC4F74A40716AE54D140F93BEB0FB8978D8636EADED0C31B6F099F16">>},
{<<"mimerl">>, <<"F278585650AA581986264638EBF698F8BB19DF297F66AD91B18910DFC6E19323">>},
{<<"prometheus">>, <<"4905FD2992F8038ECCD7AA0CD22F40637ED618C0BED1F75C05AACEC15B7545DE">>},
{<<"prometheus_cowboy">>, <<"BA286BECA9302618418892D37BCD5DC669A6CC001F4EB6D6AF85FF81F3F4F34C">>},
{<<"prometheus_httpd">>, <<"0BBE831452CFDF9588538EB2F570B26F30C348ADAE5E95A7D87F35A5910BCF92">>},
{<<"ranch">>, <<"451D8527787DF716D99DC36162FCA05934915DB0B6141BBDAC2EA8D3C7AFC7D7">>},
{<<"rfc3339">>, <<"986D7F9BAC6891AA4D5051690058DE4E623245620BBEADA7F239F85C4DF8F23C">>},
{<<"ssl_verify_fun">>, <<"603561DC0FD62F4F2EA9B890F4E20E1A0D388746D6E20557CAFB1B16950DE88C">>},
{<<"unicode_util_compat">>, <<"1D1848C40487CDB0B30E8ED975E34E025860C02E419CB615D255849F3427439D">>}]}
]. ].