Avoid recreating all metrics on reload
This commit fixes a bug in the comparison of the loaded metrics
and all application metrics. Because the Props for each metric
differ in the output of couch_stats:list/0 and
load_metrics_for_application/0 the set subtraction operations
in reload_metrics/0 would always leave a full set, so all metrics
would be deleted and created on every reload.
This is fixed by ensuring the sets for existing and current
metrics consist of {Name, Type} only.
diff --git a/src/couch_stats_aggregator.erl b/src/couch_stats_aggregator.erl
index 456af76..64e7fa9 100644
--- a/src/couch_stats_aggregator.erl
+++ b/src/couch_stats_aggregator.erl
@@ -79,10 +79,14 @@
code_change(_OldVsn, State, _Extra) ->
{ok, State}.
+props_to_type({Name, Props}) ->
+ {Name, proplists:get_value(type, Props)}.
+
reload_metrics() ->
- Current = load_metrics_for_applications(),
+ Current = lists:map(fun props_to_type/1, load_metrics_for_applications()),
CurrentSet = sets:from_list(Current),
- ExistingSet = sets:from_list(couch_stats:list()),
+ Existing = lists:map(fun props_to_type/1, couch_stats:list()),
+ ExistingSet = sets:from_list(Existing),
ToDelete = sets:subtract(ExistingSet, CurrentSet),
ToCreate = sets:subtract(CurrentSet, ExistingSet),
sets:fold(
@@ -91,8 +95,7 @@
ToDelete
),
sets:fold(
- fun({Name, Props}, _) ->
- Type = proplists:get_value(type, Props),
+ fun({Name, Type}, _) ->
couch_stats:new(Type, Name),
nil
end,