7272 unit :: oc_stat_measure :unit (),
7373 subscribed = false :: boolean (),
7474 description = " " :: description () | '_' ,
75- ctags = #{} :: oc_tags :tags () | '_' ,
7675 tags = [] :: [oc_tags :key ()] | '_' ,
7776 aggregation :: aggregation () | '_' ,
7877 aggregation_options = [] :: aggregation_options () | '_' }).
8685-type description () :: binary () | string ().
8786-type view_data () :: #{name := name (),
8887 description := description (),
89- ctags := oc_tags :tags (),
9088 tags := [oc_tags :key ()],
9189 data := oc_stat_aggregation :data ()}.
9290-type view () :: # view {}.
9593% % @doc
9694% % Creates a View from a map.
9795% % @end
96+ -spec new (#{name => name (),
97+ measure => measure_name () | oc_stat_measure :measure (),
98+ description => description (),
99+ unit := oc_stat_measure :unit (),
100+ tags := [oc_tags :key ()],
101+ aggregation => aggregation ()}) -> view ().
98102new (Map ) when is_map (Map ) ->
99103 new (maps :get (name , Map ), maps :get (measure , Map ), maps :get (unit , Map , undefined ),
100104 maps :get (description , Map ), maps :get (tags , Map , []), maps :get (aggregation , Map )).
@@ -103,18 +107,27 @@ new(Map) when is_map(Map) ->
103107% % Creates a View. This view needs to be registered and subscribed to a measure
104108% % in order to start aggregating data.
105109% % @end
110+ -spec new (name (),
111+ measure_name () | oc_stat_measure :measure (),
112+ description (),
113+ [oc_tags :key ()],
114+ aggregation ()) -> view ().
106115new (Name , Measure , Description , Tags , Aggregation ) ->
107116 new (Name , Measure , undefined , Description , Tags , Aggregation ).
108117
118+ -spec new (name (),
119+ measure_name () | oc_stat_measure :measure (),
120+ oc_stat_measure :unit (),
121+ description (),
122+ [oc_tags :key ()],
123+ aggregation ()) -> view ().
109124new (Name , Measure , Unit , Description , Tags , Aggregation ) ->
110- {CTags , Keys } = normalize_tags (Tags ),
111125 {AggregationModule , AggregationOptions } = normalize_aggregation (Aggregation ),
112126 # view {name = Name ,
113127 measure = Measure ,
114128 unit = Unit ,
115129 description = Description ,
116- ctags = CTags ,
117- tags = Keys ,
130+ tags = Tags ,
118131 aggregation = AggregationModule ,
119132 aggregation_options = AggregationOptions }.
120133
@@ -243,15 +256,14 @@ is_subscribed(Name) ->
243256-spec export (view ()) -> view_data ().
244257export (# view {name = Name , description = Description ,
245258 unit = VUnit , measure = Measure ,
246- ctags = CTags , tags = Keys ,
259+ tags = Keys ,
247260 aggregation = AggregationModule ,
248261 aggregation_options = AggregationOptions }) ->
249262 % % TODO: maybe just store multiplier as unit measure??
250263 MUnit = oc_stat_measure :unit (Measure ),
251264 Data = AggregationModule :export (Name , AggregationOptions ),
252265 #{name => Name ,
253266 description => Description ,
254- ctags => CTags ,
255267 tags => lists :reverse (Keys ),
256268 data => oc_stat_aggregation :convert (Data , MUnit , VUnit )}.
257269
@@ -440,15 +452,3 @@ normalize_aggregation({Module, Options}) ->
440452 {Module , Options };
441453normalize_aggregation (Module ) when is_atom (Module ) ->
442454 {Module , []}.
443-
444- normalize_tags ([]) ->
445- {#{}, []};
446- normalize_tags (Tags ) ->
447- normalize_tags (Tags , {#{}, []}).
448-
449- normalize_tags ([], {Map , List }) ->
450- {Map , lists :reverse (List )};
451- normalize_tags ([First |Rest ], {Map , List }) when is_map (First ) ->
452- normalize_tags (Rest , {maps :merge (Map , First ), List });
453- normalize_tags ([First |Rest ], {Map , List }) when is_atom (First ) ->
454- normalize_tags (Rest , {Map , [First | List ]}).
0 commit comments