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

Commit 197929d

Browse files
committed
BREAKING CHANGE! remove common tags
Removes common tags and instead forces user to use regular tags with properly set values.
1 parent b73a12f commit 197929d

File tree

3 files changed

+31
-39
lines changed

3 files changed

+31
-39
lines changed

src/oc_stat_view.erl

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@
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() | '_'}).
@@ -86,7 +85,6 @@
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{}.
@@ -95,6 +93,12 @@
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().
98102
new(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().
106115
new(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().
109124
new(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().
244257
export(#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};
441453
normalize_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]}).

test/oc_stat_SUITE.erl

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,13 @@
99

1010
-define(VD, [#{name := "last_video_size",
1111
description := "last processed video size",
12-
ctags := #{ctag := value},
1312
tags := [],
1413
data := #{type := latest,
1514
rows := [#{tags := [],
1615
value := 1024}]}},
1716
#{name := "video_size",
1817
description :=
1918
"number of videos processed processed over time",
20-
ctags := #{ctag := value},
2119
tags := [],
2220
data := #{type := distribution,
2321
rows :=
@@ -29,23 +27,21 @@
2927
count := 6,
3028
mean := 1024.5,
3129
sum := 6147}}]}},
32-
#{name := "video_count",
33-
description :=
34-
"number of videos processed processed over time",
35-
ctags := #{ctag := value},
36-
tags := [type],
37-
data := #{type := count,
38-
rows := [#{tags := ["mpeg"],
39-
value := 6}]}},
4030
#{name := "video_sum",
4131
description := "video_size_sum",
42-
ctags := #{sum_tag := value},
4332
tags := [category, type],
4433
data := #{type := sum,
4534
rows := [#{tags := ["category1", "mpeg"],
4635
value := #{count := 6,
4736
mean := 1024.5,
48-
sum := 6147}}]}}]).
37+
sum := 6147}}]}},
38+
#{name := "video_count",
39+
description :=
40+
"number of videos processed processed over time",
41+
tags := [type],
42+
data := #{type := count,
43+
rows := [#{tags := ["mpeg"],
44+
value := 6}]}}]).
4945

5046
all() ->
5147
[
@@ -199,7 +195,7 @@ full(_Config) ->
199195
#{
200196
name => "video_size",
201197
description => "number of videos processed processed over time",
202-
tags => [#{ctag => value}],
198+
tags => [],
203199
measure => 'my.org/measures/video_size',
204200
aggregation => {oc_stat_aggregation_distribution, [{buckets, [0, 1 bsl 16, 1 bsl 32]}]}
205201
}),
@@ -208,23 +204,21 @@ full(_Config) ->
208204
"video_count",
209205
'my.org/measures/video_size',
210206
"number of videos processed processed over time",
211-
[#{ctag => value},
212-
type],
207+
[type],
213208
oc_stat_aggregation_count),
214209

215210
{ok, _} = oc_stat_view:subscribe(
216211
"video_sum",
217212
'my.org/measures/video_size',
218213
"video_size_sum",
219-
[#{sum_tag => value},
220-
type, category],
214+
[type, category],
221215
oc_stat_aggregation_sum),
222216

223217
{ok, _} = oc_stat_view:subscribe(
224218
"last_video_size",
225219
'my.org/measures/video_size',
226220
"last processed video size",
227-
[#{ctag => value}],
221+
[],
228222
oc_stat_aggregation_latest),
229223

230224
Tags = #{type => "mpeg",

test/oc_stat_unit_SUITE.erl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ conversion(_Config) ->
3636
?assertMatch([#{name := http_request_duration_seconds,
3737
description := "desc",
3838
tags := [],
39-
ctags := #{},
4039
data := #{rows := [#{tags := [],
4140
value := #{count := 2,
4241
mean := 0.6006,
@@ -54,7 +53,6 @@ no_conversion(_Config) ->
5453
?assertMatch([#{name := http_request_duration_microsecond,
5554
description := "desc",
5655
tags := [],
57-
ctags := #{},
5856
data := #{rows := [#{tags := [],
5957
value := #{count := 2,
6058
mean := 6.006e8,

0 commit comments

Comments
 (0)