Skip to content

Commit b2b2026

Browse files
committed
style: actually apply erlfmt formatting
1 parent de96a79 commit b2b2026

8 files changed

+321
-156
lines changed

rebar.config

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44

55
{hex, [{doc, #{provider => ex_doc}}]}.
66

7-
{ex_doc, [{proglang, erlang},
8-
{main, <<"readme">>},
9-
{extras, [<<"README.md">>, <<"LICENSE">>]},
10-
{source_url, <<"https://github.com/novaframework/opentelemetry_nova">>}]}.
7+
{ex_doc, [
8+
{proglang, erlang},
9+
{main, <<"readme">>},
10+
{extras, [<<"README.md">>, <<"LICENSE">>]},
11+
{source_url, <<"https://github.com/novaframework/opentelemetry_nova">>}
12+
]}.
1113

1214
{deps, [
1315
{opentelemetry_api, "~> 1.4"},
@@ -16,21 +18,32 @@
1618
{cowboy, "~> 2.13"}
1719
]}.
1820

19-
{xref_checks, [undefined_function_calls, undefined_functions,
20-
locals_not_used, deprecated_function_calls,
21-
deprecated_functions]}.
21+
{xref_checks, [
22+
undefined_function_calls,
23+
undefined_functions,
24+
locals_not_used,
25+
deprecated_function_calls,
26+
deprecated_functions
27+
]}.
2228

2329
{dialyzer, [
24-
{plt_extra_apps, [cowboy, cowlib, ranch, opentelemetry_experimental,
25-
opentelemetry_api, opentelemetry_api_experimental]},
30+
{plt_extra_apps, [
31+
cowboy,
32+
cowlib,
33+
ranch,
34+
opentelemetry_experimental,
35+
opentelemetry_api,
36+
opentelemetry_api_experimental
37+
]},
2638
{plt_prefix, "rebar3"}
2739
]}.
2840

2941
%% Patch upstream bug: opentelemetry_experimental's otel_metrics.hrl references
3042
%% eqwalizer:dynamic/0 which is a Meta pseudo-type, not a real Erlang module.
3143
%% In OTP 28+ dynamic() is a built-in type, so the eqwalizer: prefix is wrong.
3244
{pre_hooks, [
33-
{compile, "sed -i 's/eqwalizer:dynamic()/dynamic()/g' _build/default/lib/opentelemetry_experimental/include/otel_metrics.hrl 2>/dev/null || true"}
45+
{compile,
46+
"sed -i 's/eqwalizer:dynamic()/dynamic()/g' _build/default/lib/opentelemetry_experimental/include/otel_metrics.hrl 2>/dev/null || true"}
3447
]}.
3548

3649
{ct_compile_opts, [{i, "test/support"}]}.

src/opentelemetry_nova.erl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ setup() ->
1111
description => <<"Duration of HTTP server requests">>,
1212
unit => s,
1313
advisory_params => #{
14-
explicit_bucket_boundaries => [0.005, 0.01, 0.025, 0.05, 0.075, 0.1, 0.25, 0.5, 0.75, 1.0, 2.5, 5.0, 7.5, 10.0]
14+
explicit_bucket_boundaries => [
15+
0.005, 0.01, 0.025, 0.05, 0.075, 0.1, 0.25, 0.5, 0.75, 1.0, 2.5, 5.0, 7.5, 10.0
16+
]
1517
}
1618
}),
1719
?create_updown_counter('http.server.active_requests', #{
@@ -31,7 +33,8 @@ setup() ->
3133
setup(Opts) ->
3234
setup(),
3335
case maps:get(prometheus, Opts, undefined) of
34-
undefined -> ok;
36+
undefined ->
37+
ok;
3538
PromOpts when is_map(PromOpts) ->
3639
{ok, _} = otel_nova_prom_server:start_link(PromOpts),
3740
ok

src/otel_nova_plugin.erl

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,20 @@ plugin_info() ->
4242

4343
reconstruct_route(#{bindings := Bindings, path := Path}) when map_size(Bindings) > 0 ->
4444
Segments = binary:split(Path, <<"/">>, [global]),
45-
InverseBindings = maps:fold(fun(K, V, Acc) ->
46-
Acc#{V => K}
47-
end, #{}, Bindings),
48-
Replaced = [case maps:find(Seg, InverseBindings) of
49-
{ok, Key} -> <<":", Key/binary>>;
50-
error -> Seg
51-
end || Seg <- Segments],
45+
InverseBindings = maps:fold(
46+
fun(K, V, Acc) ->
47+
Acc#{V => K}
48+
end,
49+
#{},
50+
Bindings
51+
),
52+
Replaced = [
53+
case maps:find(Seg, InverseBindings) of
54+
{ok, Key} -> <<":", Key/binary>>;
55+
error -> Seg
56+
end
57+
|| Seg <- Segments
58+
],
5259
iolist_to_binary(lists:join(<<"/">>, Replaced));
5360
reconstruct_route(#{path := Path}) ->
5461
Path.

src/otel_nova_prom_exporter.erl

Lines changed: 68 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ shutdown() ->
3434

3535
get_metrics() ->
3636
case ets:info(?TABLE) of
37-
undefined -> <<>>;
37+
undefined ->
38+
<<>>;
3839
_ ->
3940
case ets:lookup(?TABLE, metrics_output) of
4041
[{metrics_output, Output}] -> Output;
@@ -62,16 +63,20 @@ accumulate_data(PromName, #sum{datapoints = Datapoints, is_monotonic = false}) -
6263
accumulate_data(PromName, #gauge{datapoints = Datapoints}) ->
6364
lists:foreach(fun(DP) -> store_gauge(PromName, DP) end, Datapoints).
6465

65-
accumulate_histogram(PromName, #histogram_datapoint{attributes = Attrs,
66-
count = Count,
67-
sum = Sum,
68-
bucket_counts = BucketCounts,
69-
explicit_bounds = Bounds}) ->
66+
accumulate_histogram(PromName, #histogram_datapoint{
67+
attributes = Attrs,
68+
count = Count,
69+
sum = Sum,
70+
bucket_counts = BucketCounts,
71+
explicit_bounds = Bounds
72+
}) ->
7073
Key = {dp, PromName, normalize_attrs(Attrs)},
7174
case ets:lookup(?TABLE, Key) of
7275
[{Key, {hist, PrevCount, PrevSum, PrevBuckets, B}}] ->
7376
NewBuckets = add_lists(PrevBuckets, BucketCounts),
74-
ets:insert(?TABLE, {Key, {hist, PrevCount + Count, add_num(PrevSum, Sum), NewBuckets, B}});
77+
ets:insert(
78+
?TABLE, {Key, {hist, PrevCount + Count, add_num(PrevSum, Sum), NewBuckets, B}}
79+
);
7580
[] ->
7681
ets:insert(?TABLE, {Key, {hist, Count, Sum, BucketCounts, Bounds}})
7782
end.
@@ -108,21 +113,35 @@ metric_meta(PromName) -> {meta, PromName}.
108113

109114
render_all() ->
110115
Metas = ets:match(?TABLE, {{meta, '$1'}, '$2', '$3', '_', '_'}),
111-
Lines = lists:flatmap(fun([PromName, Desc, Type]) ->
112-
render_metric(PromName, Desc, Type)
113-
end, lists:sort(Metas)),
116+
Lines = lists:flatmap(
117+
fun([PromName, Desc, Type]) ->
118+
render_metric(PromName, Desc, Type)
119+
end,
120+
lists:sort(Metas)
121+
),
114122
iolist_to_binary(Lines).
115123

116124
render_metric(PromName, Desc, Type) ->
117125
Header = [
118-
<<"# HELP ">>, PromName, <<" ">>, to_bin(Desc), <<"\n">>,
119-
<<"# TYPE ">>, PromName, <<" ">>, Type, <<"\n">>
126+
<<"# HELP ">>,
127+
PromName,
128+
<<" ">>,
129+
to_bin(Desc),
130+
<<"\n">>,
131+
<<"# TYPE ">>,
132+
PromName,
133+
<<" ">>,
134+
Type,
135+
<<"\n">>
120136
],
121137
DPs = ets:match(?TABLE, {{dp, PromName, '$1'}, '$2'}),
122-
Body = lists:flatmap(fun([AttrList, Data]) ->
123-
Attrs = maps:from_list(AttrList),
124-
render_datapoint(PromName, Attrs, Data)
125-
end, lists:sort(DPs)),
138+
Body = lists:flatmap(
139+
fun([AttrList, Data]) ->
140+
Attrs = maps:from_list(AttrList),
141+
render_datapoint(PromName, Attrs, Data)
142+
end,
143+
lists:sort(DPs)
144+
),
126145
case Body of
127146
[] -> Header;
128147
_ -> Header ++ Body
@@ -147,11 +166,20 @@ format_buckets(Name, Labels, BucketCounts, Bounds) ->
147166
format_buckets(Name, Labels, [Count | RestCounts], [Bound | RestBounds], Cumulative, Acc) ->
148167
CumCount = Cumulative + Count,
149168
Le = format_number(Bound),
150-
Line = [Name, <<"_bucket">>, insert_le_label(Labels, Le), <<" ">>, format_number(CumCount), <<"\n">>],
169+
Line = [
170+
Name, <<"_bucket">>, insert_le_label(Labels, Le), <<" ">>, format_number(CumCount), <<"\n">>
171+
],
151172
format_buckets(Name, Labels, RestCounts, RestBounds, CumCount, Acc ++ [Line]);
152173
format_buckets(Name, Labels, [Count | _], [], Cumulative, Acc) ->
153174
CumCount = Cumulative + Count,
154-
Line = [Name, <<"_bucket">>, insert_le_label(Labels, <<"+Inf">>), <<" ">>, format_number(CumCount), <<"\n">>],
175+
Line = [
176+
Name,
177+
<<"_bucket">>,
178+
insert_le_label(Labels, <<"+Inf">>),
179+
<<" ">>,
180+
format_number(CumCount),
181+
<<"\n">>
182+
],
155183
Acc ++ [Line];
156184
format_buckets(_Name, _Labels, [], _, _Cumulative, Acc) ->
157185
Acc.
@@ -163,12 +191,16 @@ format_buckets(_Name, _Labels, [], _, _Cumulative, Acc) ->
163191
format_labels(Attrs) when map_size(Attrs) =:= 0 ->
164192
<<>>;
165193
format_labels(Attrs) ->
166-
Pairs = lists:sort(maps:fold(fun(K, V, Acc) ->
167-
[{prom_label_name(K), prom_label_value(V)} | Acc]
168-
end, [], Attrs)),
169-
Inner = lists:join(<<",">>, [
170-
[LK, <<"=\"">>, LV, <<"\"">>] || {LK, LV} <- Pairs
171-
]),
194+
Pairs = lists:sort(
195+
maps:fold(
196+
fun(K, V, Acc) ->
197+
[{prom_label_name(K), prom_label_value(V)} | Acc]
198+
end,
199+
[],
200+
Attrs
201+
)
202+
),
203+
Inner = lists:join(<<",">>, [[LK, <<"=\"">>, LV, <<"\"">>] || {LK, LV} <- Pairs]),
172204
[<<"{">>, Inner, <<"}">>].
173205

174206
insert_le_label(<<>>, Le) ->
@@ -187,8 +219,10 @@ prom_metric_name(Name, Unit, Data) ->
187219
WithUnit = maybe_append_unit(Base, Unit),
188220
maybe_append_total(WithUnit, Data).
189221

190-
maybe_append_unit(Base, undefined) -> Base;
191-
maybe_append_unit(Base, '') -> Base;
222+
maybe_append_unit(Base, undefined) ->
223+
Base;
224+
maybe_append_unit(Base, '') ->
225+
Base;
192226
maybe_append_unit(Base, s) ->
193227
append_if_missing(Base, <<"_seconds">>);
194228
maybe_append_unit(Base, 'By') ->
@@ -242,8 +276,14 @@ escape_label_value(Bin) ->
242276
binary:replace(
243277
binary:replace(
244278
binary:replace(Bin, <<"\\">>, <<"\\\\">>, [global]),
245-
<<"\"">>, <<"\\\"">>, [global]),
246-
<<"\n">>, <<"\\n">>, [global]).
279+
<<"\"">>,
280+
<<"\\\"">>,
281+
[global]
282+
),
283+
<<"\n">>,
284+
<<"\\n">>,
285+
[global]
286+
).
247287

248288
dots_to_underscores(Bin) ->
249289
binary:replace(Bin, <<".">>, <<"_">>, [global]).

src/otel_nova_prom_handler.erl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44

55
init(Req0, State) ->
66
Body = otel_nova_prom_exporter:get_metrics(),
7-
Req = cowboy_req:reply(200, #{
8-
<<"content-type">> => <<"text/plain; version=0.0.4; charset=utf-8">>
9-
}, Body, Req0),
7+
Req = cowboy_req:reply(
8+
200,
9+
#{
10+
<<"content-type">> => <<"text/plain; version=0.0.4; charset=utf-8">>
11+
},
12+
Body,
13+
Req0
14+
),
1015
{ok, Req, State}.

0 commit comments

Comments
 (0)