diff --git a/ChangeLog b/ChangeLog index 0a5e392..0ae069b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +Version 6.2.1 (whalen) + * moved max_metrics constant to mondemand_config so we can tweak at runtime + Version 6.2.0 (molinaro) * added a function to convert from millis since epoch to erlang:now/0 format diff --git a/include/mondemand.hrl b/include/mondemand.hrl index be194ee..fbec297 100644 --- a/include/mondemand.hrl +++ b/include/mondemand.hrl @@ -39,7 +39,6 @@ % related to stats messages -define (MD_STATS_EVENT, <<"MonDemand::StatsMsg">>). --define (MD_MAX_METRICS, 1024). % internal records for MonDemand::StatsMsg -record (md_stats_msg, { send_time, diff --git a/src/mondemand.app.src b/src/mondemand.app.src index 1ad4b00..a17318c 100644 --- a/src/mondemand.app.src +++ b/src/mondemand.app.src @@ -1,7 +1,7 @@ { application, mondemand, [ { description, "Erlang Mondemand Bindings." }, - { vsn, "6.2.0" }, + { vsn, "6.2.1" }, { modules, [] }, { registered, [mondemand,mondemand_sup]}, { applications, [kernel,stdlib,syntax_tools,lwes]}, diff --git a/src/mondemand_config.erl b/src/mondemand_config.erl index b817bbf..687f463 100644 --- a/src/mondemand_config.erl +++ b/src/mondemand_config.erl @@ -23,6 +23,7 @@ default_stats/0, lwes_config/0, minutes_to_keep/0, + max_metrics/0, parse_config/1 ]). @@ -30,6 +31,8 @@ -define (DEFAULT_STATS, [min, max, sum, count]). -define (DEFAULT_MINUTES_TO_KEEP, 10). -define (MOCHI_SENDER_HOST, mondemand_sender_host_global). +-define (MOCHI_MAX_METRICS, mondemand_max_metrics_global). +-define (DEFAULT_MAX_METRICS, 512). % this function is meant to be called before the supervisor and % pulls all those configs which are mostly static. @@ -39,7 +42,13 @@ init () -> undefined -> net_adm:localhost(); {ok, H} -> H end, - mondemand_global:put (?MOCHI_SENDER_HOST, Host). + mondemand_global:put (?MOCHI_SENDER_HOST, Host), + MaxMetrics = + case application:get_env (mondemand, max_metrics) of + undefined -> ?DEFAULT_MAX_METRICS; + {ok, M} -> M + end, + mondemand_global:put (?MOCHI_MAX_METRICS, MaxMetrics). host () -> mondemand_global:get (?MOCHI_SENDER_HOST). @@ -237,6 +246,9 @@ minutes_to_keep () -> {ok, I} when is_integer (I) -> I end. +max_metrics () -> + mondemand_global:get (?MOCHI_MAX_METRICS). + %%-------------------------------------------------------------------- %%% Test functions %%-------------------------------------------------------------------- diff --git a/src/mondemand_statsmsg.erl b/src/mondemand_statsmsg.erl index 05afd38..6c3602e 100644 --- a/src/mondemand_statsmsg.erl +++ b/src/mondemand_statsmsg.erl @@ -217,12 +217,17 @@ from_lwes (#lwes_event { attrs = Data}) -> }. to_lwes (L) when is_list (L) -> - lists:flatten (lists:map (fun to_lwes/1, L) ); + MaxMetrics = mondemand_config:max_metrics (), + lists:flatten (lists:map (fun (X) -> to_lwes (X, MaxMetrics) end, L) ); -% split events into chunks of MD_MAX_METRICS -to_lwes (MondemandStatsMsg = #md_stats_msg { num_metrics = NumMetrics }) - when NumMetrics > ?MD_MAX_METRICS -> - lists:reverse (to_lwes( MondemandStatsMsg, [])); +to_lwes (MondemandStatsMsg = #md_stats_msg {}) -> + MaxMetrics = mondemand_config:max_metrics (), + to_lwes (MondemandStatsMsg, MaxMetrics). + +% split events into chunks of max_metrics +to_lwes (MondemandStatsMsg = #md_stats_msg { num_metrics = NumMetrics }, MaxMetrics) + when NumMetrics > MaxMetrics -> + lists:reverse (to_lwes( MondemandStatsMsg, MaxMetrics, [])); to_lwes (#md_stats_msg { send_time = SendTimeIn, collect_time = CollectTimeIn, @@ -232,7 +237,7 @@ to_lwes (#md_stats_msg { send_time = SendTimeIn, context = Context, num_metrics = NumMetrics, metrics = Metrics - }) -> + }, _) -> NowMillis = mondemand_util:millis_since_epoch(), SendTime = case SendTimeIn of @@ -262,18 +267,19 @@ to_lwes (#md_stats_msg { send_time = SendTimeIn, to_lwes (MondemandStatsMsg = #md_stats_msg { num_metrics = NumMetrics, metrics = Metrics - }, EventList) - when NumMetrics > ?MD_MAX_METRICS -> - { HeadMetrics, TailMetrics } = lists:split (?MD_MAX_METRICS, Metrics), + }, MaxMetrics, EventList) + when NumMetrics > MaxMetrics -> + { HeadMetrics, TailMetrics } = lists:split (MaxMetrics, Metrics), to_lwes (MondemandStatsMsg#md_stats_msg { num_metrics = length (TailMetrics), metrics = TailMetrics }, + MaxMetrics, [ to_lwes (MondemandStatsMsg#md_stats_msg { - num_metrics = ?MD_MAX_METRICS, + num_metrics = MaxMetrics, metrics = HeadMetrics}) | EventList ]); -to_lwes (MondemandStatsMsg = #md_stats_msg {}, EventList) -> +to_lwes (MondemandStatsMsg = #md_stats_msg {}, _, EventList) -> [ to_lwes (MondemandStatsMsg) | EventList ]. metric_to_lwes (MetricIndex, @@ -2035,8 +2041,10 @@ statsmsg_test_ () -> }, { "many metrics", fun() -> + mondemand_config:init(), C = [{<<"foo">>,<<"bar">>}], - MetricsCount = ?MD_MAX_METRICS + 1, + MaxMetrics = mondemand_config:max_metrics (), + MetricsCount = MaxMetrics + 1, E2K0Name = list_to_binary(string:concat("baz", integer_to_list(MetricsCount))), MIn = lists:map(fun(X) -> { @@ -2056,7 +2064,7 @@ statsmsg_test_ () -> % test that to_lwes of long statsmsg returns several events that are correct [E1, E2] = to_lwes(S), % test that the metric counts and first metric in events match expected values - ?assert (lists:member({?LWES_U_INT_16, <<"num">>, ?MD_MAX_METRICS}, E1#lwes_event.attrs)), + ?assert (lists:member({?LWES_U_INT_16, <<"num">>, MaxMetrics}, E1#lwes_event.attrs)), ?assert (lists:member({?LWES_STRING, <<"k0">>, <<"baz1">>}, E1#lwes_event.attrs)), ?assert (lists:member({?LWES_STRING, <<"t0">>, <<"gauge">>}, E1#lwes_event.attrs)), ?assert (lists:member({?LWES_INT_64, <<"v0">>, 1}, E1#lwes_event.attrs)),