Current section

Files

Jump to
prometheus src prometheus_metric_spec.erl
Raw

src/prometheus_metric_spec.erl

-module(prometheus_metric_spec).
-export([get_value/2,
get_value/3,
fetch_value/2]).
-export_type([spec/0]).
%%====================================================================
%% Types
%%====================================================================
-type spec() :: proplists:proplist().
%%====================================================================
%% Public API
%%====================================================================
-spec get_value(Key :: atom(), Spec :: spec()) -> any().
%% @private
%% @equiv get_value(Key, Spec, undefined)
get_value(Key, Spec) ->
get_value(Key, Spec, undefined).
-spec get_value(Key :: atom(), Spec :: spec(), Default :: any()) -> any().
%% @private
get_value(Key, Spec, Default) ->
proplists:get_value(Key, Spec, Default).
-spec fetch_value(Key :: atom(), Spec :: spec()) -> any() | no_return().
%% @private
fetch_value(Key, Spec) ->
case proplists:get_value(Key, Spec) of
undefined ->
erlang:error({missing_metric_spec_key, Key, Spec});
Value ->
Value
end.