You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by da...@apache.org on 2014/07/31 23:25:11 UTC

[23/50] folsom commit: updated refs/heads/import-master to 4824aec

Add ability to pass tags to notify


Project: http://git-wip-us.apache.org/repos/asf/couchdb-folsom/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-folsom/commit/091ccfd7
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-folsom/tree/091ccfd7
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-folsom/diff/091ccfd7

Branch: refs/heads/import-master
Commit: 091ccfd7e547cecff9ee522b8e79702166c3a9c9
Parents: a5bb8fc
Author: Andrey Vasenin <va...@aboutecho.com>
Authored: Thu Oct 31 16:06:44 2013 +0400
Committer: Andrey Vasenin <va...@aboutecho.com>
Committed: Fri Nov 1 11:36:01 2013 +0400

----------------------------------------------------------------------
 src/folsom_ets.erl            | 33 ++++++++++++++++++++++++---------
 src/folsom_metrics.erl        | 12 ++++++++++++
 test/folsom_erlang_checks.erl | 11 ++++++++++-
 3 files changed, 46 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-folsom/blob/091ccfd7/src/folsom_ets.erl
----------------------------------------------------------------------
diff --git a/src/folsom_ets.erl b/src/folsom_ets.erl
index a7dfaf1..a59f130 100644
--- a/src/folsom_ets.erl
+++ b/src/folsom_ets.erl
@@ -36,6 +36,7 @@
          notify/1,
          notify/2,
          notify/3,
+         tagged_notify/4,
          notify_existing_metric/3,
          get_handlers/0,
          get_handlers_info/0,
@@ -43,7 +44,8 @@
          get_values/1,
          get_history_values/2,
          get_group_values/1,
-         get_group_values/2
+         get_group_values/2,
+         get_tags/1
         ]).
 
 -record(metric, {
@@ -111,12 +113,16 @@ notify(Name, Event) ->
 
 %% notify/3, makes sure metric exist, if not creates metric
 notify(Name, Event, Type) ->
-    case handler_exists(Name) of
-        true ->
-            notify(Name, Event, Type, true);
-        false ->
-            notify(Name, Event, Type, false)
-    end.
+    notify(Name, Event, Type, handler_exists(Name)).
+
+tagged_notify(Name, Event, Type, Tags) ->
+    R = notify(Name, Event, Type),
+    case get_tags(Name) of
+        {error, _, _} -> skip;
+        CurrentTags ->
+            [add_tag(Name, T) || T <- Tags, not sets:is_element(T, CurrentTags)]
+    end,
+    R.
 
 %% assumes metric already exists, bypasses above checks
 notify_existing_metric(Name, Event, Type) ->
@@ -131,8 +137,8 @@ get_handlers_info() ->
 get_info(Name) ->
     case handler_exists(Name) of
         true ->
-            [{_, #metric{type = Type}}] = ets:lookup(?FOLSOM_TABLE, Name),
-            {Name, [{type, Type}]};
+            [{_, #metric{type = Type, tags = Tags}}] = ets:lookup(?FOLSOM_TABLE, Name),
+            {Name, [{type, Type}, {tags, Tags}]};
         false ->
             {error, Name, nonexistent_metric}
     end.
@@ -175,6 +181,15 @@ get_group_values(Tag, Type) ->
     Metrics = ets:match(?FOLSOM_TABLE, {'$1', {metric, '$2', Type, '_'}}),
     [{Name, get_values(Name)} || [Name, Tags] <- Metrics, sets:is_element(Tag, Tags)].
 
+get_tags(Name) ->
+    case handler_exists(Name) of
+        true ->
+            {_, Info} = get_info(Name),
+            proplists:get_value(tags, Info);
+        false ->
+            {error, Name, nonexistent_metric}
+    end.
+
 %%%===================================================================
 %%% Internal functions
 %%%===================================================================

http://git-wip-us.apache.org/repos/asf/couchdb-folsom/blob/091ccfd7/src/folsom_metrics.erl
----------------------------------------------------------------------
diff --git a/src/folsom_metrics.erl b/src/folsom_metrics.erl
index f844d1f..428f7fd 100644
--- a/src/folsom_metrics.erl
+++ b/src/folsom_metrics.erl
@@ -46,9 +46,11 @@
          notify/1,
          notify/2,
          notify/3,
+         notify/4,
          safely_notify/1,
          safely_notify/2,
          safely_notify/3,
+         safely_notify/4,
          notify_existing_metric/3,
          get_metrics/0,
          metric_exists/1,
@@ -60,6 +62,7 @@
          get_histogram_statistics/1,
          get_histogram_statistics/2,
          get_history_values/2,
+         get_tags/1,
          histogram_timed_update/2,
          histogram_timed_update/3,
          histogram_timed_update/4,
@@ -140,6 +143,9 @@ notify(Name, Event) ->
 notify(Name, Event, Type) ->
     folsom_ets:notify(Name, Event, Type).
 
+notify(Name, Event, Type, Tags) ->
+    folsom_ets:tagged_notify(Name, Event, Type, Tags).
+
 safely_notify(Event) ->
   catch notify(Event).
 
@@ -149,6 +155,9 @@ safely_notify(Name, Event) ->
 safely_notify(Name, Event, Type) ->
   catch notify(Name, Event, Type).
 
+safely_notify(Name, Event, Type, Tags) ->
+  catch notify(Name, Event, Type, Tags).
+
 notify_existing_metric(Name, Event, Type) ->
     folsom_ets:notify_existing_metric(Name, Event, Type).
 
@@ -185,6 +194,9 @@ get_histogram_statistics(Name1, Name2) ->
 get_history_values(Name, Count) ->
     folsom_ets:get_history_values(Name, Count).
 
+get_tags(Name) ->
+    folsom_ets:get_tags(Name).
+
 histogram_timed_update(Name, Fun) ->
     {Time, Value} = timer:tc(Fun),
     ok = notify({Name, Time}),

http://git-wip-us.apache.org/repos/asf/couchdb-folsom/blob/091ccfd7/test/folsom_erlang_checks.erl
----------------------------------------------------------------------
diff --git a/test/folsom_erlang_checks.erl b/test/folsom_erlang_checks.erl
index 743a405..820b79e 100644
--- a/test/folsom_erlang_checks.erl
+++ b/test/folsom_erlang_checks.erl
@@ -140,6 +140,11 @@ populate_metrics() ->
 
     [ok = folsom_metrics:notify({slide_sorted_a, Value}) || Value <- ?DATA2],
 
+    ok = folsom_metrics:notify(tagged_metric, 1, meter, [a, b]),
+    ok = folsom_metrics:notify(tagged_metric, 1, meter, [c]),
+
+    {error, _, unsupported_metric_type} = folsom_metrics:notify(tagged_unknown_metric, 1, unknown_metric, [tag]),
+
     3.141592653589793 = folsom_metrics:histogram_timed_update(timed, math, pi, []),
 
     Begin = folsom_metrics:histogram_timed_begin(timed2),
@@ -192,6 +197,8 @@ check_metrics() ->
 
     2 = folsom_metrics:get_metric_value(<<"gauge">>),
 
+    true = sets:is_subset(sets:from_list([a,b,c]), folsom_metrics:get_tags(tagged_metric)),
+
     [11,12,13,14,15,6,7,8,9,10] = folsom_metrics:get_metric_value(noneb),
 
     [11,12,13,14,15] = folsom_metrics:get_metric_value(nonec),
@@ -302,7 +309,7 @@ check_group_metrics() ->
     {counter, 0} = lists:keyfind(counter,1,Metrics).
 
 delete_metrics() ->
-    20 = length(ets:tab2list(?FOLSOM_TABLE)),
+    21 = length(ets:tab2list(?FOLSOM_TABLE)),
 
     ok = folsom_metrics:delete_metric(counter),
     ok = folsom_metrics:delete_metric(counter2),
@@ -320,6 +327,8 @@ delete_metrics() ->
     ok = folsom_metrics:delete_metric(noneb),
     ok = folsom_metrics:delete_metric(nonec),
 
+    ok = folsom_metrics:delete_metric(tagged_metric),
+
     ok = folsom_metrics:delete_metric(slide_sorted_a),
 
     ok = folsom_metrics:delete_metric(timed),