iilyak commented on a change in pull request #1432: Support callback module 
data provider
URL: https://github.com/apache/couchdb/pull/1432#discussion_r202649851
 
 

 ##########
 File path: src/couch_epi/src/couch_epi_data.erl
 ##########
 @@ -102,12 +102,15 @@ definitions({file, FilePath}) ->
         {error, Reason} ->
             {error, {FilePath, Reason}}
     end;
-definitions({module, Module}) when is_atom(Module) ->
-    definitions({module, [Module]});
-definitions({module, Modules}) ->
+definitions({static_module, Module}) when is_atom(Module) ->
+    definitions({static_module, [Module]});
+definitions({static_module, Modules}) ->
     Data = lists:append([M:data() || M <- Modules]),
     Hash = couch_epi_functions_gen:hash(Modules),
-    {ok, Hash, Data}.
+    {ok, Hash, Data};
+definitions({callback_module, Module}) ->
+    Data = Module:data(),
 
 Review comment:
   There is one use case when `static_module` is useful. That's why after 
thinking some more I think we should keep it. 
   You can define same data provider in multiple applications. This is helpful 
for cases similar to use of `stats`. Currently stats definitions are loaded 
from plain configuration files in priv directory of every application. It can 
be rewritten using couch_epi as follows:
   ```
   cat dreyfus_epi.erl
   data_providers() ->
       [
           {{couch_stats, descriptions}, {static_module, dreyfus_stats}}
       ].
   ```
   ```
   cat global_changes_epi.erl
   data_providers() ->
       [
           {{couch_stats, descriptions}, {static_module, global_changes_stats}}
       ].
   ```
   
   ```
   cat dreyfus_stats.erl
   -module(dreyfus_stats).
   -export([data/0]).
   data() -> [
       {[dreyfus, httpd, search], [
           {type, histogram},
           {desc, <<"Distribution of overall search request latency as 
experienced by the end user">>}
       ]},
       {[dreyfus, rpc, search], [
           {type, histogram},
           {desc, <<"length of a search RPC worker">>}
       ]}
   ].
   ```
   
   ```
   cat global_changes_stats.erl
   -module(global_changes_stats).
   -export([data/0]).
   
   data() ->
      [
         {[global_changes, db_writes], [
             {type, counter},
             {desc, <<"number of db writes performed by global changes">>}
         ]},
         {[global_changes, event_doc_conflict], [
              {type, counter},
              {desc, <<"number of conflicted event docs encountered by global 
changes">>}
          ]}
      ].
   
   ```
   
   In this case one single module would be generated which would include data 
from all applications. It would be more efficient to detect changes using `vsn` 
attribute of a module.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to