Feuerlabs/exometer — pull request #32 by uwiger (2014-03-11 07:44:12+00:00)
Title: Uw extended setopts

exometer:setopts/2 calls optional callback M:preprocess_setopts/5

This is initially to allow dynamic modification of function entries.
In order to change a function entry, the 'ref' value must be updated.
For consistency, 'arg' should change correspondingly, but none of
these things supported in a good way. Also, the setopts/4 callback
did not really have a proper chance to vet the changes.

An optional callback, M:preprocess_setopts(Name,Opts,Type,Ref,OldOpts)
was introduced, which - if exported - is called and is expected to
return a new Options list. This is then processed as before, with the
exception that 'ref' can now also be changed.

The exometer_function:preprocess_setopts/5 callback ensures that
'ref' and 'arg' are consistent. However, a user modifying a
function entry should use change only the 'arg' option, as it is
part of the interface, whereas the representation of 'ref' should
be considered opaque.

Even so, it is now possible to change 'ref' via setopts/2.

Example:
```erlang
Eshell V5.9.2 (abort with ^G)
1> exometer:start().
08:19:41.254 [info] Application lager started on node nonode@nohost
08:19:41.280 [info] Starting reporter with []
08:19:41.301 [info] Application exometer started on node nonode@nohost
ok
2> exometer:new([mem], {function,erlang,memory,[],proplist,[total,processes]}).
ok
3> exometer:get_value([mem]).
{ok,[{total,12514376},{processes,1855604}]}
4> Arg = proplists:get_value(arg, exometer:info([mem], options)).
{erlang,memory,[],proplist,[total,processes]}
5> exometer:setopts([mem], [{arg,{erlang,memory,[],proplist,[total]}}]).
ok
6> exometer:get_value([mem]).
{ok,[{total,12499672}]}
7> Ref = exometer:info([mem], ref).
{erlang,memory,once,[],proplist,[total]}
8> exometer:setopts([mem], [{ref,{erlang,memory,once,[],proplist,[total,processes]}}]).
ok
9> exometer:get_value([mem]).
{ok,[{total,12514568},{processes,1855232}]}
10> proplists:get_value(arg, exometer:info([mem], options)).
{erlang,memory,[],proplist,[total,processes]}
```