Skip to content

Commit 3b0543e

Browse files
Merge pull request #42 from relaypro-open/upgrade-cowboy-for-otp-28-build
Changes to support building on OTP 28
2 parents 75d9768 + 74a01b5 commit 3b0543e

5 files changed

Lines changed: 61 additions & 69 deletions

File tree

rebar.config

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
{platform_define, "R16", 'unsupported'}
33
]}.
44
{deps, [
5-
{cowboy, {git, "https://github.com/ninenines/cowboy.git", {tag, "2.8.0"}}},
5+
{cowboy, {git, "https://github.com/ninenines/cowboy.git", {tag, "2.14.2"}}},
66
{recon, {git, "https://github.com/ferd/recon.git", {tag, "2.5.6"}}}
77
]}.
88
{shell, [{apps, [imetrics]}]}.
9-
{extra_src_dirs, ["benchmarks"]}.
9+
{extra_src_dirs, ["benchmarks"]}.

rebar.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
[{<<"cowboy">>,
22
{git,"https://github.com/ninenines/cowboy.git",
3-
{ref,"3eec447960eb03cde48f0f04cd72fd4d1e548ca0"}},
3+
{ref,"495e74ada88d0876d7e438d53f11af767a9cdcc4"}},
44
0},
55
{<<"cowlib">>,
66
{git,"https://github.com/ninenines/cowlib",
7-
{ref,"1b5539a1da1d39b110d81b118000f00bbedaf4b4"}},
7+
{ref,"aca0ad953417b29bab2c41eeb4c37c98606c848b"}},
88
1},
99
{<<"ranch">>,
1010
{git,"https://github.com/ninenines/ranch",
11-
{ref,"3190aef88aea04d6dce8545fe9b4574288903f44"}},
11+
{ref,"10b51304b26062e0dbfd5e74824324e9a911e269"}},
1212
1},
1313
{<<"recon">>,
1414
{git,"https://github.com/ferd/recon.git",

src/openmetrics.erl

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ get_exemplar_string(Name, Tags) ->
7979
true ->
8080
EStr = strnum(EValue),
8181
TStr = strnum(Timestamp),
82-
" # {" ++ create_label_string(Labels) ++ "} " ++ EStr ++ " " ++ TStr;
82+
[" # {", create_label_string(Labels), "} ", EStr, " ", TStr];
8383
false ->
8484
""
8585
end;
@@ -88,14 +88,11 @@ get_exemplar_string(Name, Tags) ->
8888
end.
8989

9090
create_label_string(Labels) ->
91-
Result = maps:fold(fun(Label, Value, Acc) -> ("," ++ binary:bin_to_list(imetrics_utils:bin(Label)) ++ "=\"" ++ binary:bin_to_list(Value) ++ "\"" ++ Acc) end, "", Labels),
92-
case length(Result) of
93-
R when R < 3 ->
94-
Result;
95-
_ ->
96-
[_| Result2] = Result,
97-
Result2
98-
end.
91+
EncLabels = lists:map(
92+
fun({Label, Value}) ->
93+
[binary:bin_to_list(imetrics_utils:bin(Label)), "=\"", binary:bin_to_list(Value), "\""]
94+
end, lists:sort(maps:to_list(Labels))),
95+
lists:join(",", EncLabels).
9996

10097
is_valid_labels(Labels) ->
10198
maps:fold(fun(Label, Value, Valid) -> Valid and is_valid_label_name(Label) and is_valid_label_value(Value) end, true, Labels).
@@ -146,14 +143,13 @@ deliver_mapped_metric(_Req, _Type, _Name, []) ->
146143
ok.
147144

148145
create_tag_string(Tags) ->
149-
TagPairs = lists:foldl(
150-
fun({TagName, TagValue}, Acc) ->
151-
[[list_to_binary(atom_to_list(TagName)), "=\"", TagValue, "\""] | Acc]
146+
TagPairs = lists:map(
147+
fun({TagName, TagValue}) ->
148+
[list_to_binary(atom_to_list(TagName)), "=\"", TagValue, "\""]
152149
end,
153-
[],
154-
maps:to_list(Tags)
150+
lists:sort(maps:to_list(Tags))
155151
),
156-
["{", lists:join(",", lists:reverse(TagPairs)), "}"].
152+
["{", lists:join(",", TagPairs), "}"].
157153

158154
strnum('NaN') -> "NaN";
159155
strnum(N) when is_integer(N) -> integer_to_list(N);

test/imetrics_slo_tests.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ slo_test(_Fixture) ->
2626
?_assertMatch([{<<"uid">>,[{<<"$ms">>,_},{<<"test_metric">>,1}]}], imetrics_slo:dump(eunit, <<"uid">>)),
2727
?_assertMatch(#{keys := 1, memory := 1064, uids := 1}, imetrics_slo:info(eunit)),
2828
?_assertMatch(#{eunit := #{keys := 1, memory := 1064, uids := 1}}, imetrics_sup:slo_info()),
29-
?_assertMatch(_, [ imetrics_slo:add(eunit, X, <<"test_metric">>) || X <- lists:seq(1, 1000)]),
29+
?_assertMatch([_|_], [ imetrics_slo:add(eunit, X, <<"test_metric">>) || X <- lists:seq(1, 1000)]),
3030
?_assertMatch(#{keys := 1, memory := 97888, uids := 92}, imetrics_slo:info(eunit)),
3131
?_assertMatch(ok, imetrics_slo:put(eunit, <<"uid">>, <<"test_put_metric">>, 10)),
3232
?_assertMatch(10, imetrics_slo:get(eunit, <<"uid">>, <<"test_put_metric">>)),

test/imetrics_tests.erl

Lines changed: 44 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -130,46 +130,36 @@ exemplar_test_() ->
130130
fun exemplar_test/1}.
131131

132132
exemplar_test(_Fixture) ->
133-
?_assertEqual(true, imetrics:set_exemplar(a, 1)),
134-
?_assertEqual(true, imetrics:set_exemplar(b, #{c => 1}, 2)),
135-
?_assertEqual(true, imetrics:set_exemplar(c, 2, #{d => 2, e => "aa"})),
136-
?_assertEqual(true, imetrics:set_exemplar(f, 3, 946684800)),
137-
?_assertEqual(true, imetrics:set_exemplar(g, #{h => 1, i=> 2}, 3, #{j => k})),
138-
?_assertEqual(true, imetrics:set_exemplar(g, #{h => 2}, 4, 978307200)),
139-
?_assertEqual(true, imetrics:set_exemplar(i, 5, #{j => "bb"}, 1009843200)),
140-
?_assertEqual(true, imetrics:set_exemplar(k, #{l => 3}, 6, #{m => "cc"}, 1577836800)),
141-
142-
143-
imetrics:set_exemplar(a, 1),
144-
imetrics:set_exemplar(b, #{c => 1}, 2),
145-
imetrics:set_exemplar(c, 2, #{d => 2, e => "aa"}),
146-
imetrics:set_exemplar(f, 3, 946684800),
147-
imetrics:set_exemplar(g, #{h => 1, i=> 2}, 3, #{j => k}),
148-
imetrics:set_exemplar(g, #{h => 2}, 4, 978307200),
149-
imetrics:set_exemplar(i, 5, #{j => "bb"}, 1009843200),
150-
imetrics:set_exemplar(k, #{l => 3}, 6, #{m => "cc"}, 1577836800),
151-
imetrics:set_exemplar(l, #{name => "test1"}, 1),
152-
imetrics:set_exemplar(l, #{name => "test2"}, 2),
153-
154-
?_assertMatch({1, #{}, _}, imetrics:get_exemplar(#{'__name__' => <<"a">>})),
155-
?_assertMatch({2, #{}, _}, imetrics:get_exemplar(#{'__name__' => <<"b">>, c => <<"1">>})),
156-
Test3Map = #{d => <<"2">>, e => <<"aa">>},
157-
?_assertMatch({2, Test3Map, _}, imetrics:get_exemplar(#{'__name__' => <<"c">>})),
158-
?_assertMatch({3, #{}, 946684800}, imetrics:get_exemplar(#{'__name__' => <<"f">>})),
159-
Test5Map = #{j => <<"k">>},
160-
?_assertMatch({3, Test5Map, _}, imetrics:get_exemplar(#{'__name__' => <<"g">>, h => <<"1">>, i => <<"2">>})),
161-
?_assertMatch({4, #{}, 978307200}, imetrics:get_exemplar(#{'__name__' => <<"g">>, h => <<"2">>})),
162-
Test7Map = #{j => <<"bb">>},
163-
?_assertMatch({5, Test7Map, 1009843200}, imetrics:get_exemplar(#{'__name__' => <<"i">>})),
164-
Test8Map = #{m => <<"cc">>},
165-
?_assertMatch({6, Test8Map, 1577836800}, imetrics:get_exemplar(#{'__name__' => <<"k">>, l => <<"3">>})),
166-
167-
?_assertEqual(true, imetrics:set_exemplar(k, #{l => 3}, 0.1, 1893456000)),
168-
imetrics:set_exemplar(k, #{l => 3}, 0.1, 1893456000),
169-
?_assertMatch({0.1, #{}, 1893456000}, imetrics:get_exemplar(#{'__name__' => <<"k">>, l => <<"3">>})),
170-
171-
?_assertMatch({1, #{}, _}, imetrics:get_exemplar(#{name => <<"test1">>, '__name__' => <<"l">>})),
172-
?_assertMatch({2, #{}, _}, imetrics:get_exemplar(#{name => <<"test2">>, '__name__' => <<"l">>})).
133+
[
134+
?_assertEqual(true, imetrics:set_exemplar(a, 1)),
135+
?_assertEqual(true, imetrics:set_exemplar(b, #{c => 1}, 2)),
136+
?_assertEqual(true, imetrics:set_exemplar(c, 2, #{d => 2, e => "aa"})),
137+
?_assertEqual(true, imetrics:set_exemplar(f, 3, 946684800)),
138+
?_assertEqual(true, imetrics:set_exemplar(g, #{h => 1, i=> 2}, 3, #{j => k})),
139+
?_assertEqual(true, imetrics:set_exemplar(g, #{h => 2}, 4, 978307200)),
140+
?_assertEqual(true, imetrics:set_exemplar(i, 5, #{j => "bb"}, 1009843200)),
141+
?_assertEqual(true, imetrics:set_exemplar(k, #{l => 3}, 6, #{m => "cc"}, 1577836800)),
142+
?_assertEqual(true, imetrics:set_exemplar(l, #{name => "test1"}, 1)),
143+
?_assertEqual(true, imetrics:set_exemplar(l, #{name => "test2"}, 2)),
144+
145+
?_assertMatch({1, #{}, _}, imetrics:get_exemplar(#{'__name__' => <<"a">>})),
146+
?_assertMatch({2, #{}, _}, imetrics:get_exemplar(#{'__name__' => <<"b">>, c => <<"1">>})),
147+
?_assertMatch({2, #{d := <<"2">>, e := <<"aa">>}, _}, imetrics:get_exemplar(#{'__name__' => <<"c">>})),
148+
?_assertMatch({3, #{}, 946684800}, imetrics:get_exemplar(#{'__name__' => <<"f">>})),
149+
?_assertMatch({3, #{j := <<"k">>}, _}, imetrics:get_exemplar(#{'__name__' => <<"g">>, h => <<"1">>, i => <<"2">>})),
150+
?_assertMatch({4, #{}, 978307200}, imetrics:get_exemplar(#{'__name__' => <<"g">>, h => <<"2">>})),
151+
?_assertMatch({5, #{j := <<"bb">>}, 1009843200}, imetrics:get_exemplar(#{'__name__' => <<"i">>})),
152+
?_assertMatch({6, #{m := <<"cc">>}, 1577836800}, imetrics:get_exemplar(#{'__name__' => <<"k">>, l => <<"3">>})),
153+
154+
?_assertEqual(true, imetrics:set_exemplar(k, #{l => 3}, 0.1, 1893456000)),
155+
?_assertMatch({0.1, #{}, 1893456000}, begin
156+
imetrics:set_exemplar(k, #{l => 3}, 0.1, 1893456000),
157+
imetrics:get_exemplar(#{'__name__' => <<"k">>, l => <<"3">>})
158+
end),
159+
160+
?_assertMatch({1, #{}, _}, imetrics:get_exemplar(#{name => <<"test1">>, '__name__' => <<"l">>})),
161+
?_assertMatch({2, #{}, _}, imetrics:get_exemplar(#{name => <<"test2">>, '__name__' => <<"l">>}))
162+
].
173163

174164
init_counter_test_() ->
175165
{setup,
@@ -178,14 +168,20 @@ init_counter_test_() ->
178168
fun init_counter_test/1}.
179169

180170
init_counter_test(_Fixture) ->
181-
Data1 = imetrics:get_with_types(),
182-
?_assertEqual(undefined, proplists:get_value(<<"empty_counter">>, Data1)),
183-
?_assertEqual(undefined, proplists:get_value(<<"empty_counter_mapped">>, Data1)),
184-
imetrics:init_counter(empty_counter),
185-
imetrics:init_counter(empty_counter_mapped, #{key => "abc"}),
186-
Data2 = imetrics:get_with_types(),
187-
?_assertEqual({counter, [{#{}, 0}]}, proplists:get_value(<<"empty_counter">>, Data2)),
188-
?_assertEqual({counter, [{#{key => <<"abc">>}, 0}]}, proplists:get_value(<<"empty_counter_mapped">>, Data2)).
171+
[
172+
?_assertEqual(undefined, proplists:get_value(<<"empty_counter">>, imetrics:get_with_types())),
173+
?_assertEqual(undefined, proplists:get_value(<<"empty_counter_mapped">>, imetrics:get_with_types())),
174+
?_assertEqual({counter, [{#{}, 0}]}, proplists:get_value(<<"empty_counter">>, begin
175+
imetrics:init_counter(empty_counter),
176+
imetrics:get_with_types()
177+
end
178+
)),
179+
?_assertEqual({counter, [{#{key => <<"abc">>}, 0}]}, proplists:get_value(<<"empty_counter_mapped">>, begin
180+
imetrics:init_counter(empty_counter_mapped, #{key => "abc"}),
181+
imetrics:get_with_types()
182+
end
183+
))
184+
].
189185

190186
%% get tests
191187
get_test_() ->

0 commit comments

Comments
 (0)