diff --git a/src/oc_stat_view.erl b/src/oc_stat_view.erl index fb88a2d..2220a0f 100644 --- a/src/oc_stat_view.erl +++ b/src/oc_stat_view.erl @@ -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() | '_'}). @@ -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{}. @@ -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)). @@ -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}. @@ -243,7 +256,7 @@ 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?? @@ -251,7 +264,6 @@ export(#view{name=Name, description=Description, Data = AggregationModule:export(Name, AggregationOptions), #{name => Name, description => Description, - ctags => CTags, tags => lists:reverse(Keys), data => oc_stat_aggregation:convert(Data, MUnit, VUnit)}. @@ -440,15 +452,3 @@ normalize_aggregation({Module, Options}) -> {Module, Options}; normalize_aggregation(Module) when is_atom(Module) -> {Module, []}. - -normalize_tags([]) -> - {#{}, []}; -normalize_tags(Tags) -> - normalize_tags(Tags, {#{}, []}). - -normalize_tags([], {Map, List}) -> - {Map, lists:reverse(List)}; -normalize_tags([First|Rest], {Map, List}) when is_map(First) -> - normalize_tags(Rest, {maps:merge(Map, First), List}); -normalize_tags([First|Rest], {Map, List}) when is_atom(First) -> - normalize_tags(Rest, {Map, [First | List]}). diff --git a/test/oc_stat_SUITE.erl b/test/oc_stat_SUITE.erl index 5192178..b1d37dc 100644 --- a/test/oc_stat_SUITE.erl +++ b/test/oc_stat_SUITE.erl @@ -9,7 +9,6 @@ -define(VD, [#{name := "last_video_size", description := "last processed video size", - ctags := #{ctag := value}, tags := [], data := #{type := latest, rows := [#{tags := [], @@ -17,7 +16,6 @@ #{name := "video_size", description := "number of videos processed processed over time", - ctags := #{ctag := value}, tags := [], data := #{type := distribution, rows := @@ -29,23 +27,21 @@ count := 6, mean := 1024.5, sum := 6147}}]}}, - #{name := "video_count", - description := - "number of videos processed processed over time", - ctags := #{ctag := value}, - tags := [type], - data := #{type := count, - rows := [#{tags := ["mpeg"], - value := 6}]}}, #{name := "video_sum", description := "video_size_sum", - ctags := #{sum_tag := value}, tags := [category, type], data := #{type := sum, rows := [#{tags := ["category1", "mpeg"], value := #{count := 6, mean := 1024.5, - sum := 6147}}]}}]). + sum := 6147}}]}}, + #{name := "video_count", + description := + "number of videos processed processed over time", + tags := [type], + data := #{type := count, + rows := [#{tags := ["mpeg"], + value := 6}]}}]). all() -> [ @@ -199,7 +195,7 @@ full(_Config) -> #{ name => "video_size", description => "number of videos processed processed over time", - tags => [#{ctag => value}], + tags => [], measure => 'my.org/measures/video_size', aggregation => {oc_stat_aggregation_distribution, [{buckets, [0, 1 bsl 16, 1 bsl 32]}]} }), @@ -208,23 +204,21 @@ full(_Config) -> "video_count", 'my.org/measures/video_size', "number of videos processed processed over time", - [#{ctag => value}, - type], + [type], oc_stat_aggregation_count), {ok, _} = oc_stat_view:subscribe( "video_sum", 'my.org/measures/video_size', "video_size_sum", - [#{sum_tag => value}, - type, category], + [type, category], oc_stat_aggregation_sum), {ok, _} = oc_stat_view:subscribe( "last_video_size", 'my.org/measures/video_size', "last processed video size", - [#{ctag => value}], + [], oc_stat_aggregation_latest), Tags = #{type => "mpeg", diff --git a/test/oc_stat_unit_SUITE.erl b/test/oc_stat_unit_SUITE.erl index e20c2ed..7d90c9a 100644 --- a/test/oc_stat_unit_SUITE.erl +++ b/test/oc_stat_unit_SUITE.erl @@ -36,7 +36,6 @@ conversion(_Config) -> ?assertMatch([#{name := http_request_duration_seconds, description := "desc", tags := [], - ctags := #{}, data := #{rows := [#{tags := [], value := #{count := 2, mean := 0.6006, @@ -54,7 +53,6 @@ no_conversion(_Config) -> ?assertMatch([#{name := http_request_duration_microsecond, description := "desc", tags := [], - ctags := #{}, data := #{rows := [#{tags := [], value := #{count := 2, mean := 6.006e8,