Continuous event sampler for Erlang/OTP and Elixir.
deigma samples reported events within continuous one-second windows, steadily
adjusting the sampling percentage so the events that seep through stay
representative of what's happening in the system while honouring rate limits.
The sampling percentage is exposed alongside each event so downstream consumers
can reason about the original population. See the README for an
overview, configuration and examples.
Summary
Functions
Asks Category to sample an EventType event.
Asks Category to sample an EventType event using a custom function or
overridden options.
Asks Category to sample an EventType event using a custom function and
overridden options.
Returns a child spec for a deigma instance named Category, for launching it
under your own supervisor.
Starts a deigma instance named Category under the deigma application.
Starts a deigma instance named Category under your own supervisor.
Stops the deigma instance named Category running under the deigma
application.
Types
-type ask_opt() :: {max_rate, non_neg_integer() | infinity}.
Functions
-spec ask(Category, EventType) -> {Decision, SamplingPercentage} when Category :: atom(), EventType :: term(), Decision :: sample | drop, SamplingPercentage :: float().
Asks Category to sample an EventType event.
Categorymust be an atom and correspond to an existing deigma instance.EventTypecan be any term.
Returns:
{sample, SamplingPercentage}if the event was sampled;{drop, SamplingPercentage}if the event was dropped.
SamplingPercentage is a floating point number between 0.0 and 1.0 representing
the percentage of events that were sampled during the last 1000 milliseconds,
including the event reported just now.
-spec ask(Category, EventType, EventFun | Opts) -> {Decision, SamplingPercentage} | EventFunResult when Category :: atom(), EventType :: term(), EventFun :: fun((Timestamp, Decision, SamplingPercentage) -> EventFunResult), Timestamp :: integer(), SamplingPercentage :: float(), Decision :: sample | drop, EventFunResult :: term(), Opts :: [ask_opt()].
Asks Category to sample an EventType event using a custom function or
overridden options.
Categorymust be an atom and correspond to an existing deigma instance.EventTypecan be any term.EventFunis a function called with(Timestamp, Decision, SamplingPercentage):Timestampis the monotonic timestamp, in native units, at which the event was registered;Decisionis eithersampleordrop;SamplingPercentageis a float between 0.0 and 1.0 (seeask/2).
It runs from within the event window for
EventType, so it can be used to fulfil serialisation constraints — at the expense of possibly turning the event window into a bottleneck.Optsis a list ofask_opt/0values:{max_rate, MaxRate}: don't sample more thanMaxRateEventTypeevents per second (defaults to100).
When called with EventFun, returns (or throws) whatever EventFun returns (or
throws). When called with Opts, returns the same as ask/2.
-spec ask(Category, EventType, EventFun, Opts) -> EventFunResult when Category :: atom(), EventType :: term(), EventFun :: fun((Timestamp, Decision, SamplingPercentage) -> EventFunResult), Timestamp :: integer(), SamplingPercentage :: float(), Decision :: sample | drop, EventFunResult :: term(), Opts :: [ask_opt()].
Asks Category to sample an EventType event using a custom function and
overridden options.
The arguments are as described in ask/3. Returns (or throws) whatever
EventFun returns (or throws).
-spec child_spec(Category) -> supervisor:child_spec() when Category :: atom().
Returns a child spec for a deigma instance named Category, for launching it
under your own supervisor.
Categorymust be an atom.
See also start_link/1 and start/1.
Starts a deigma instance named Category under the deigma application.
Categorymust be an atom.
See also stop/1, start_link/1 and child_spec/1.
Starts a deigma instance named Category under your own supervisor.
Categorymust be an atom.
See also child_spec/1 and start/1.
-spec stop(Category) -> ok | {error, not_started} when Category :: atom().
Stops the deigma instance named Category running under the deigma
application.
Categorymust be an atom.
See also start/1.