From 5479ffa917ce20bf07d2a1150e1babd314bbad85 Mon Sep 17 00:00:00 2001 From: ndiezel0 Date: Wed, 16 Feb 2022 11:27:13 +0300 Subject: [PATCH] TD-178: Add Prometheus (#6) --- Makefile | 1 - config/sys.config | 4 ++++ rebar.config | 8 ++++++++ src/token_keeper.erl | 10 +++++++++- 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 49188c1..0666a70 100644 --- a/Makefile +++ b/Makefile @@ -50,7 +50,6 @@ wc-shell: dev-image wc-%: dev-image $(DOCKER_RUN) $(DEV_IMAGE_TAG) make $* -# TODO docker compose down doesn't work yet wdeps-shell: dev-image $(DOCKERCOMPOSE_RUN) $(TEST_CONTAINER_NAME) su; \ $(DOCKERCOMPOSE_W_ENV) down diff --git a/config/sys.config b/config/sys.config index 2f3513a..e7884e8 100644 --- a/config/sys.config +++ b/config/sys.config @@ -203,5 +203,9 @@ % 1 second {max_backward_clock_moving, 1000} % {machine_id, hostname_hash} + ]}, + + {prometheus, [ + {collectors, [default]} ]} ]. diff --git a/rebar.config b/rebar.config index 12bff62..9fa0e13 100644 --- a/rebar.config +++ b/rebar.config @@ -81,6 +81,12 @@ {profiles, [ {prod, [ {deps, [ + %% NOTE + %% Because of a dependency conflict, prometheus libs are only included in production build for now + %% https://github.com/project-fifo/rebar3_lint/issues/42 + %% https://github.com/valitydev/hellgate/pull/2/commits/884724c1799703cee4d1033850fe32c17f986d9e + {prometheus, "4.8.1"}, + {prometheus_cowboy, "0.1.8"}, % Introspect a node running in production {recon, "2.5.2"}, {logger_logstash_formatter, @@ -99,6 +105,8 @@ {tools, load}, % logger formatter {logger_logstash_formatter, load}, + prometheus, + prometheus_cowboy, token_keeper ]}, {sys_config, "./config/sys.config"}, diff --git a/src/token_keeper.erl b/src/token_keeper.erl index d9fced6..df2515d 100644 --- a/src/token_keeper.erl +++ b/src/token_keeper.erl @@ -43,6 +43,10 @@ init([]) -> TokenBlacklistSpec = tk_blacklist:child_spec(genlib_app:env(?MODULE, blacklist, #{})), TokensSpecs = tk_token:child_specs(genlib_app:env(?MODULE, tokens, #{})), StoragesSpecs = tk_storage:child_specs(genlib_app:env(?MODULE, storages, #{})), + AdditionalRoutes = [ + get_prometheus_route(), + get_health_route() + ], HandlerChildSpec = woody_server:child_spec( ?MODULE, #{ @@ -53,7 +57,7 @@ init([]) -> shutdown_timeout => get_shutdown_timeout(), event_handler => EventHandlers, handlers => get_woody_handlers(AuditPulse), - additional_routes => [get_health_route() | get_machinegun_processor_routes(EventHandlers)] + additional_routes => AdditionalRoutes ++ get_machinegun_processor_routes(EventHandlers) } ), {ok, { @@ -147,3 +151,7 @@ get_audit_specs() -> disable -> {[], []} end. + +-spec get_prometheus_route() -> {iodata(), module(), _Opts :: any()}. +get_prometheus_route() -> + {"/metrics/[:registry]", prometheus_cowboy2_handler, []}.