mirror of
https://github.com/valitydev/woody_erlang.git
synced 2024-11-06 02:15:19 +00:00
ED-204: Move woody_api_hay to separate repo (#153)
* ED-204: Move woody_api_hay to separate repo * Move woody_client_metrics to woody_api_hay repo * proper 1.4.0 * Fix proper
This commit is contained in:
parent
4fab3f64af
commit
330bdcf71e
@ -69,8 +69,8 @@
|
||||
]},
|
||||
{deps, [
|
||||
{cth_readable, "1.4.9"},
|
||||
{proper, "1.3.0"},
|
||||
{how_are_you , {git, "https://github.com/rbkmoney/how_are_you.git", {branch, "master"}}},
|
||||
{proper, "1.4.0"},
|
||||
{woody_api_hay,{git, "https://github.com/rbkmoney/woody_api_hay.git", {branch, "master"}}},
|
||||
{damsel , {git, "https://github.com/rbkmoney/damsel.git", {ref, "8911ac3"}}},
|
||||
{mg_proto , {git, "https://github.com/rbkmoney/machinegun_proto.git", {ref, "ebae56f"}}}
|
||||
]},
|
||||
|
17
rebar.lock
17
rebar.lock
@ -1,27 +1,14 @@
|
||||
{"1.2.0",
|
||||
[{<<"bear">>,{pkg,<<"bear">>,<<"0.8.7">>},2},
|
||||
{<<"cache">>,{pkg,<<"cache">>,<<"2.3.3">>},0},
|
||||
[{<<"cache">>,{pkg,<<"cache">>,<<"2.3.3">>},0},
|
||||
{<<"certifi">>,{pkg,<<"certifi">>,<<"2.6.1">>},1},
|
||||
{<<"cg_mon">>,
|
||||
{git,"https://github.com/rbkmoney/cg_mon.git",
|
||||
{ref,"5a87a37694e42b6592d3b4164ae54e0e87e24e18"}},
|
||||
1},
|
||||
{<<"cowboy">>,{pkg,<<"cowboy">>,<<"2.9.0">>},0},
|
||||
{<<"cowlib">>,{pkg,<<"cowlib">>,<<"2.11.0">>},1},
|
||||
{<<"folsom">>,
|
||||
{git,"https://github.com/folsom-project/folsom.git",
|
||||
{ref,"9309bad9ffadeebbefe97521577c7480c7cfcd8a"}},
|
||||
1},
|
||||
{<<"genlib">>,
|
||||
{git,"https://github.com/rbkmoney/genlib.git",
|
||||
{ref,"4565a8d73f34a0b78cca32c9cd2b97d298bdadf8"}},
|
||||
0},
|
||||
{<<"gproc">>,{pkg,<<"gproc">>,<<"0.9.0">>},0},
|
||||
{<<"hackney">>,{pkg,<<"hackney">>,<<"1.17.4">>},0},
|
||||
{<<"how_are_you">>,
|
||||
{git,"https://github.com/rbkmoney/how_are_you.git",
|
||||
{ref,"8f11d17eeb6eb74096da7363a9df272fd3099718"}},
|
||||
0},
|
||||
{<<"idna">>,{pkg,<<"idna">>,<<"6.1.1">>},1},
|
||||
{<<"metrics">>,{pkg,<<"metrics">>,<<"1.0.1">>},1},
|
||||
{<<"mimerl">>,{pkg,<<"mimerl">>,<<"1.2.0">>},1},
|
||||
@ -39,7 +26,6 @@
|
||||
{<<"unicode_util_compat">>,{pkg,<<"unicode_util_compat">>,<<"0.7.0">>},1}]}.
|
||||
[
|
||||
{pkg_hash,[
|
||||
{<<"bear">>, <<"16264309AE5D005D03718A5C82641FCC259C9E8F09ADEB6FD79CA4271168656F">>},
|
||||
{<<"cache">>, <<"B23A5FE7095445A88412A6E614C933377E0137B44FFED77C9B3FEF1A731A20B2">>},
|
||||
{<<"certifi">>, <<"DBAB8E5E155A0763EEA978C913CA280A6B544BFA115633FA20249C3D396D9493">>},
|
||||
{<<"cowboy">>, <<"865DD8B6607E14CF03282E10E934023A1BD8BE6F6BACF921A7E2A96D800CD452">>},
|
||||
@ -54,7 +40,6 @@
|
||||
{<<"ssl_verify_fun">>, <<"CF344F5692C82D2CD7554F5EC8FD961548D4FD09E7D22F5B62482E5AEAEBD4B0">>},
|
||||
{<<"unicode_util_compat">>, <<"BC84380C9AB48177092F43AC89E4DFA2C6D62B40B8BD132B1059ECC7232F9A78">>}]},
|
||||
{pkg_hash_ext,[
|
||||
{<<"bear">>, <<"534217DCE6A719D59E54FB0EB7A367900DBFC5F85757E8C1F94269DF383F6D9B">>},
|
||||
{<<"cache">>, <<"44516CE6FA03594D3A2AF025DD3A87BFE711000EB730219E1DDEFC816E0AA2F4">>},
|
||||
{<<"certifi">>, <<"524C97B4991B3849DD5C17A631223896272C6B0AF446778BA4675A1DFF53BB7E">>},
|
||||
{<<"cowboy">>, <<"2C729F934B4E1AA149AFF882F57C6372C15399A20D54F65C8D67BEF583021BDE">>},
|
||||
|
@ -1,81 +0,0 @@
|
||||
%%%
|
||||
%%% Copyright 2018 RBKmoney
|
||||
%%%
|
||||
%%% Licensed under the Apache License, Version 2.0 (the "License");
|
||||
%%% you may not use this file except in compliance with the License.
|
||||
%%% You may obtain a copy of the License at
|
||||
%%%
|
||||
%%% http://www.apache.org/licenses/LICENSE-2.0
|
||||
%%%
|
||||
%%% Unless required by applicable law or agreed to in writing, software
|
||||
%%% distributed under the License is distributed on an "AS IS" BASIS,
|
||||
%%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
%%% See the License for the specific language governing permissions and
|
||||
%%% limitations under the License.
|
||||
%%%
|
||||
|
||||
-module(woody_api_hay).
|
||||
|
||||
-behaviour(hay_metrics_handler).
|
||||
|
||||
%% how_are_you callbacks
|
||||
-export([init/1]).
|
||||
-export([get_interval/1]).
|
||||
-export([gather_metrics/1]).
|
||||
|
||||
%% Types
|
||||
|
||||
-type options() :: #{
|
||||
interval := timeout()
|
||||
}.
|
||||
|
||||
-export_type([options/0]).
|
||||
|
||||
%% Internal types
|
||||
|
||||
-type state() :: options().
|
||||
-type metric() :: how_are_you:metric().
|
||||
-type metric_key() :: how_are_you:metric_key().
|
||||
-type metric_value() :: how_are_you:metric_value().
|
||||
-type nested_metrics() :: [metric() | nested_metrics()].
|
||||
|
||||
%% API
|
||||
|
||||
-spec init(options()) -> {ok, state()}.
|
||||
init(Options) ->
|
||||
{ok, #{
|
||||
interval => maps:get(interval, Options, 10 * 1000)
|
||||
}}.
|
||||
|
||||
-spec get_interval(state()) -> timeout().
|
||||
get_interval(#{interval := Interval}) ->
|
||||
Interval.
|
||||
|
||||
-spec gather_metrics(state()) -> [hay_metrics:metric()].
|
||||
gather_metrics(_) ->
|
||||
lists:map(fun create_server_metrics/1, get_active_connections()).
|
||||
|
||||
%% Internals
|
||||
|
||||
create_server_metrics({Ref, Nconns}) when is_tuple(Ref) ->
|
||||
create_server_metrics({tuple_to_list(Ref), Nconns});
|
||||
create_server_metrics({Ref, Nconns}) ->
|
||||
gauge([woody, server, Ref, active_connections], Nconns).
|
||||
|
||||
get_ranch_info() ->
|
||||
ranch:info().
|
||||
|
||||
get_active_connections() ->
|
||||
F = fun({Ref, Info}) ->
|
||||
Nconns =
|
||||
case lists:keyfind(active_connections, 1, Info) of
|
||||
false -> 0;
|
||||
{_, N} -> N
|
||||
end,
|
||||
{Ref, Nconns}
|
||||
end,
|
||||
lists:map(F, get_ranch_info()).
|
||||
|
||||
-spec gauge(metric_key(), metric_value()) -> metric().
|
||||
gauge(Key, Value) ->
|
||||
how_are_you:metric_construct(gauge, Key, Value).
|
@ -1,104 +0,0 @@
|
||||
-module(woody_client_metrics).
|
||||
|
||||
% api
|
||||
-export([new/2]).
|
||||
-export([delete/1]).
|
||||
-export([increment_counter/1]).
|
||||
-export([increment_counter/2]).
|
||||
-export([decrement_counter/1]).
|
||||
-export([decrement_counter/2]).
|
||||
-export([update_histogram/2]).
|
||||
-export([update_gauge/2]).
|
||||
-export([update_meter/2]).
|
||||
|
||||
% -type metric() :: metrics:metric().
|
||||
-type metric() :: counter | histogram | gauge | meter.
|
||||
|
||||
-spec new(metric(), any()) -> ok | {error, term()}.
|
||||
new(_, _) ->
|
||||
ok.
|
||||
|
||||
-spec delete(any()) -> ok.
|
||||
delete(_) ->
|
||||
ok.
|
||||
|
||||
-spec increment_counter(any()) -> ok | {error, term()}.
|
||||
increment_counter(Key) ->
|
||||
increment_counter(Key, 1).
|
||||
|
||||
-spec increment_counter(any(), number()) -> ok | {error, term()}.
|
||||
increment_counter([hackney, _Host, _], _) ->
|
||||
% we don't need per host metrics
|
||||
ok;
|
||||
increment_counter(Key, Value) ->
|
||||
update_metric(counter, Key, Value).
|
||||
|
||||
-spec decrement_counter(any()) -> ok | {error, term()}.
|
||||
decrement_counter(Key) ->
|
||||
decrement_counter(Key, 1).
|
||||
|
||||
-spec decrement_counter(any(), number()) -> ok | {error, term()}.
|
||||
decrement_counter(Key, Value) ->
|
||||
increment_counter(Key, -Value).
|
||||
|
||||
-spec update_histogram(any(), number() | function()) -> ok | {error, term()}.
|
||||
update_histogram(Key, Value) ->
|
||||
update_metric(histogram, Key, Value).
|
||||
|
||||
-spec update_gauge(any(), number()) -> ok | {error, term()}.
|
||||
update_gauge(Key, Value) ->
|
||||
update_metric(gauge, Key, Value).
|
||||
|
||||
-spec update_meter(any(), number()) -> ok | {error, term()}.
|
||||
update_meter(Key, Value) ->
|
||||
update_metric(meter, Key, Value).
|
||||
|
||||
%% internals
|
||||
update_metric(meter, _, _) ->
|
||||
{error, not_allowed};
|
||||
update_metric(histogram, _, Value) when is_function(Value) ->
|
||||
{error, not_allowed};
|
||||
update_metric(histogram, Key, Value) ->
|
||||
update_metric(gauge, Key, Value);
|
||||
update_metric(Type, Key0, Value) ->
|
||||
case is_allowed_metric(Key0) of
|
||||
true ->
|
||||
Key = map_key(Key0),
|
||||
hay_metrics:push(hay_metrics:construct(Type, tag_key(Key), Value));
|
||||
false ->
|
||||
{error, not_allowed}
|
||||
end.
|
||||
|
||||
tag_key(Key) when is_list(Key) ->
|
||||
[woody, client | Key].
|
||||
|
||||
is_allowed_metric([hackney_pool, _, Metric]) ->
|
||||
lists:member(Metric, get_allowed_pool_metrics());
|
||||
is_allowed_metric(Key) ->
|
||||
lists:member(Key, get_allowed_request_metrics()).
|
||||
|
||||
map_key(Key) ->
|
||||
case maps:get(Key, get_key_mapping(), undefined) of
|
||||
undefined ->
|
||||
Key;
|
||||
MappedKey ->
|
||||
MappedKey
|
||||
end.
|
||||
|
||||
% gets
|
||||
|
||||
get_key_mapping() ->
|
||||
maps:get(metric_key_mapping, get_options(), #{}).
|
||||
|
||||
get_allowed_request_metrics() ->
|
||||
[
|
||||
[hackney, total_requests],
|
||||
[hackney, finished_requests],
|
||||
[hackney, nb_requests]
|
||||
].
|
||||
|
||||
get_allowed_pool_metrics() ->
|
||||
[free_count, no_socket, in_use_count, queue_counter].
|
||||
|
||||
get_options() ->
|
||||
genlib_app:env(woody, woody_client_metrics_options, #{}).
|
@ -34,6 +34,9 @@
|
||||
|
||||
%% проверяет работоспособность в условиях параллельных запросов,
|
||||
%% но по факту не может проверить, что запросы действительно соединяются
|
||||
|
||||
%% Suppress proper's internal type mismatch for setup generator
|
||||
-dialyzer([no_return, no_opaque]).
|
||||
prop_test() ->
|
||||
?FORALL(
|
||||
Commands,
|
||||
|
@ -42,6 +42,9 @@ end_per_suite(C) ->
|
||||
%%
|
||||
%% tests
|
||||
%%
|
||||
|
||||
%% Suppress proper's internal type mismatch for setup generator
|
||||
-dialyzer([no_return, no_opaque]).
|
||||
prop_test(_C) ->
|
||||
R = proper:quickcheck(
|
||||
woody_joint_workers_pt:prop_test(),
|
||||
|
Loading…
Reference in New Issue
Block a user