Skip to content
This repository has been archived by the owner on Jul 31, 2023. It is now read-only.

Commit

Permalink
BREAKING CHANGE! remove common tags
Browse files Browse the repository at this point in the history
Removes common tags and instead forces user to use regular tags with
properly set values.
  • Loading branch information
hauleth committed Feb 13, 2019
1 parent b73a12f commit d690a63
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions src/oc_stat_view.erl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
deregister/1,
is_registered/1,
subscribe/1,
subscribe/5,
subscribename(), /5,
subscribe/6,
unsubscribe/1,
is_subscribed/1,
Expand Down Expand Up @@ -72,7 +72,6 @@
unit :: oc_stat_measure:unit(),
subscribed = false :: boolean(),
description = "" :: description() | '_',
ctags = #{} :: oc_tags:tags() | '_',
tags = [] :: [oc_tags:key()] | '_',
aggregation :: aggregation() | '_',
aggregation_options = [] :: aggregation_options() | '_'}).
Expand All @@ -86,7 +85,6 @@
-type description() :: binary() | string().
-type view_data() :: #{name := name(),
description := description(),
ctags := oc_tags:tags(),
tags := [oc_tags:key()],
data := oc_stat_aggregation:data()}.
-type view() :: #view{}.
Expand All @@ -95,6 +93,12 @@
%% @doc
%% Creates a View from a map.
%% @end
-spec new(#{name => name(),
measure => measure_name() | oc_stat_measure:measure(),
description => description(),
unit := oc_stat_measure:unit(),
tags := [oc_tags:key()],
aggregation => aggregation()}) -> view().
new(Map) when is_map(Map) ->
new(maps:get(name, Map), maps:get(measure, Map), maps:get(unit, Map, undefined),
maps:get(description, Map), maps:get(tags, Map, []), maps:get(aggregation, Map)).
Expand All @@ -103,18 +107,27 @@ new(Map) when is_map(Map) ->
%% Creates a View. This view needs to be registered and subscribed to a measure
%% in order to start aggregating data.
%% @end
-spec new(name(),
measure_name() | oc_stat_measure:measure(),
description(),
[oc_tags:key()],
aggregation()) -> view().
new(Name, Measure, Description, Tags, Aggregation) ->
new(Name, Measure, undefined, Description, Tags, Aggregation).

-spec new(name(),
measure_name() | oc_stat_measure:measure(),
oc_stat_measure:unit(),
description(),
[oc_tags:key()],
aggregation()) -> view().
new(Name, Measure, Unit, Description, Tags, Aggregation) ->
{CTags, Keys} = normalize_tags(Tags),
{AggregationModule, AggregationOptions} = normalize_aggregation(Aggregation),
#view{name=Name,
measure=Measure,
unit=Unit,
description=Description,
ctags=CTags,
tags=Keys,
tags=Tags,
aggregation=AggregationModule,
aggregation_options=AggregationOptions}.

Expand Down Expand Up @@ -243,15 +256,14 @@ is_subscribed(Name) ->
-spec export(view()) -> view_data().
export(#view{name=Name, description=Description,
unit=VUnit, measure=Measure,
ctags=CTags, tags=Keys,
tags=Keys,
aggregation=AggregationModule,
aggregation_options=AggregationOptions}) ->
%% TODO: maybe just store multiplier as unit measure??
MUnit = oc_stat_measure:unit(Measure),
Data = AggregationModule:export(Name, AggregationOptions),
#{name => Name,
description => Description,
ctags => CTags,
tags => lists:reverse(Keys),
data => oc_stat_aggregation:convert(Data, MUnit, VUnit)}.

Expand Down

0 comments on commit d690a63

Please sign in to comment.