From 0c4e0edc90823e027539f8d492b189184e68fcc4 Mon Sep 17 00:00:00 2001 From: Martin Sumner Date: Mon, 20 Jan 2025 21:29:05 +0000 Subject: [PATCH] Update following review --- src/riak_kv_http_cache.erl | 6 ++++-- src/riak_kv_wm_stats.erl | 11 ++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/riak_kv_http_cache.erl b/src/riak_kv_http_cache.erl index 98e0279b2..4e003dab6 100644 --- a/src/riak_kv_http_cache.erl +++ b/src/riak_kv_http_cache.erl @@ -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). @@ -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 -> diff --git a/src/riak_kv_wm_stats.erl b/src/riak_kv_wm_stats.erl index 468bcbdf6..dbff12a10 100644 --- a/src/riak_kv_wm_stats.erl +++ b/src/riak_kv_wm_stats.erl @@ -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"). @@ -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)), @@ -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.