Skip to content
This repository has been archived by the owner on Sep 27, 2023. It is now read-only.

Commit

Permalink
Merge pull request #57 from heroku/no_tail_warning
Browse files Browse the repository at this point in the history
Adds L20 - tail session forbidden message.
  • Loading branch information
archaelus committed Oct 8, 2013
2 parents d1ae444 + f4e301c commit e23d653
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
3 changes: 3 additions & 0 deletions src/logplex.app.src
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
,{logplex_shard_urls, "redis://localhost:6379"}
,{max_drains_per_channel, 5} % #channels
,{metrics_namespace, "dev"} % string, no spaces
,{no_tail_warning,
"Error L20 (Tail sessions forbidden) "
"Tail sessions for this app are forbidden due to log volume."} % string
,{pagerduty, "0"} % "0" = disabled
,{queue_length, 2000}
,{redgrid_redis_url, "redis://localhost:6379"}
Expand Down
7 changes: 7 additions & 0 deletions src/logplex_api.erl
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ handlers() ->
{tail_not_requested, _} ->
end_chunked_response(Socket);
{_, no_tail} ->
gen_tcp:send(Socket, no_tail_warning()),
end_chunked_response(Socket);
_ ->
?INFO("at=tail_start channel_id=~p filters=~100p",
Expand Down Expand Up @@ -547,6 +548,12 @@ filter_and_send_chunked_logs(Resp, [Msg|Tail], Filters, Num, Acc) ->
end.


no_tail_warning() ->
logplex_utils:format(undefined,
logplex_utils:formatted_utc_date(),
<<"Logplex">>,
logplex_app:config(no_tail_warning)).

tail_init(Socket, Buffer, Filters, ChannelId) ->
inet:setopts(Socket, [{active, once}]),
tail_loop(Socket, Buffer, Filters, ChannelId, 0).
Expand Down
19 changes: 11 additions & 8 deletions src/logplex_utils.erl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
-module(logplex_utils).
-export([rpc/4, set_weight/1, resolve_host/1,
parse_msg/1, filter/2, formatted_utc_date/0, format/1, field_val/2, field_val/3,
format/4,
parse_redis_url/1, nl/1, to_int/1]).

-include("logplex.hrl").
Expand Down Expand Up @@ -78,17 +79,19 @@ formatted_utc_date() ->
DateFormat = fun(Int) -> string:right(integer_to_list(Int), 2, $0) end,
io_lib:format("~w-~s-~sT~s:~s:~s-~s:00", [Year, DateFormat(Month), DateFormat(Day), DateFormat(Hour), DateFormat(Min), DateFormat(Sec), DateFormat(Offset)]).

format(Msg) when is_record(Msg, msg) ->
Ps =
case Msg#msg.ps of
format(#msg{ps = Ps, time = Time, source = Source, content = Content}) ->
format(Ps, Time, Source, Content);
format(_Msg) ->
"".

format(Ps, Time, Source, Content) ->
Ps1 =
case Ps of
undefined -> <<>>;
_ -> [<<"[">>, Msg#msg.ps, <<"]">>]
_ -> [<<"[">>, Ps, <<"]">>]
end,
iolist_to_binary([Msg#msg.time, <<" ">>, Msg#msg.source, Ps, <<": ">>,
nl(Msg#msg.content)]);
iolist_to_binary([Time, <<" ">>, Source, Ps1, <<": ">>, nl(Content)]).

format(_Msg) ->
"".

-spec nl(iolist() | binary()) -> iolist().
nl(<<>>) -> <<"\n">>;
Expand Down

0 comments on commit e23d653

Please sign in to comment.