Skip to content

Commit

Permalink
Update following review
Browse files Browse the repository at this point in the history
  • Loading branch information
martinsumner committed Jan 20, 2025
1 parent efacd05 commit ea794ea
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/riak_kv_http_cache.erl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
start_link() ->
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).

-spec get_stats(Milliseconds :: pos_integer()) -> list({atom(), term()}).
get_stats(Timeout) ->
gen_server:call(?MODULE, get_stats, Timeout).

Expand All @@ -47,9 +48,10 @@ check_cache(#st{ts = undefined} = S) ->
Stats = riak_kv_status:get_stats(web),
S#st{ts = os:timestamp(), stats = Stats};
check_cache(#st{ts = Then} = S) ->
CacheTime = application:get_env(riak_kv, http_stats_cache_seconds, 1),
CacheTime =
application:get_env(riak_kv, http_stats_cache_milliseconds, 1000),
Now = os:timestamp(),
case timer:now_diff(Now, Then) < (CacheTime * 1000000) of
case timer:now_diff(Now, Then) < (CacheTime * 1000) of
true ->
S;
false ->
Expand Down
11 changes: 8 additions & 3 deletions src/riak_kv_wm_stats.erl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
pretty_print/2
]).

-define(TIMEOUT, 30000).
-define(TIMEOUT, 30000). %% In milliseconds

-include_lib("webmachine/include/webmachine.hrl").
-include("riak_kv_wm_raw.hrl").
Expand Down Expand Up @@ -87,7 +87,8 @@ malformed_request(RD, Ctx) ->
{true,
wrq:append_to_resp_body(
io_lib:format(
"Bad timeout value ~0p",
"Bad timeout value ~0p "
"expected milliseconds > 0",
[TimeoutStr]
),
wrq:set_resp_header(?HEAD_CTYPE, "text/plain", RD)),
Expand Down Expand Up @@ -130,6 +131,10 @@ pretty_print(RD, Ctx) ->
{{halt, RepsonseCode}, UpdRD, UpdCtx} ->
{{halt, RepsonseCode}, UpdRD, UpdCtx};
{Json, UpdRD, UpdCtx} ->
{json_pp:print(Json), UpdRD, UpdCtx}
{
json_pp:print(binary_to_list(list_to_binary(Json))),
UpdRD,
UpdCtx
}
end.

0 comments on commit ea794ea

Please sign in to comment.