-
Notifications
You must be signed in to change notification settings - Fork 437
Open
Description
I am thinking of adding prometheus metrics in hackney wherever we are using erlang-metrics (metrics) lib.
do_connect(Host, Port, Transport, #client{mod_metrics=Metrics,
options=ClientOptions}=Client0, Type) ->
Begin = os:timestamp(),
{_RequestRef, Client} = case Type of
pool ->
{Client0#client.request_ref, Client0};
direct ->
hackney_manager:new_request(Client0)
end,
ConnectTimeout = connect_timeout(Client),
ConnectOpts = hackney_connection:connect_options(Transport, Host, ClientOptions),
case Transport:connect(Host, Port, ConnectOpts, ConnectTimeout) of
{ok, Skt} ->
?report_trace("new connection", []),
ConnectTime = timer:now_diff(os:timestamp(), Begin)/1000,
_ = metrics:update_histogram(Metrics, [hackney, Host, connect_time], ConnectTime),
_ = metrics:increment_counter(Metrics, [hackney_pool, Host, new_connection]),
Client1 = Client#client{socket=Skt,
state = connected},
hackney_manager:update_state(Client1),
{ok, Client1};
{error, timeout} ->
?report_trace("connect timeout", []),
_ = metrics:increment_counter(Metrics, [hackney, Host, connect_timeout]),
hackney_manager:cancel_request(Client),
{error, connect_timeout};
Error ->
?report_trace("connect error", []),
_ = metrics:increment_counter(Metrics, [hackney, Host, connect_error]),
hackney_manager:cancel_request(Client),
Error
end.
Any thoughts or things i need to consider while doing this change, I can raise PR for this if there are no challenges/concerns...
Metadata
Metadata
Assignees
Labels
No labels