Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/formats/prometheus_text_format.erl
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ format_into_create_mf_callback_fn(Fmt) ->
"\n"
>>,
Bin = render_metrics(Prologue, Name, Metrics),
put(?MODULE, Fmt(Bin, erase(?MODULE)))
put(?MODULE, Fmt(erase(?MODULE), Bin))
end.

?DOC("""
Expand Down
32 changes: 31 additions & 1 deletion test/eunit/format/prometheus_text_format_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ prometheus_format_test_() ->
fun test_quantile_dsummary/1,
fun test_histogram/1,
fun test_histogram_float/1,
fun test_dhistogram/1
fun test_dhistogram/1,
fun test_format_into/1
]}.

content_type_test() ->
Expand Down Expand Up @@ -302,3 +303,32 @@ test_dhistogram(_) ->
>>,
prometheus_text_format:format()
).

test_format_into(_) ->
prometheus_gauge:new([{name, pool_size}, {help, "MongoDB Connections pool size"}]),
prometheus_gauge:set(pool_size, 365),
prometheus_counter:new([{name, http_requests_total}, {help, "Http request count"}]),
prometheus_counter:inc(http_requests_total),

{ok, Fd} = ram_file:open("", [write, read, binary]),
Fmt = fun(Size, Data) ->
file:write(Fd, Data),
Size + byte_size(Data)
end,
Size = prometheus_text_format:format_into(default, Fmt, 0),
?assertEqual({ok, Size}, ram_file:get_size(Fd)),
{ok, Buf} = file:pread(Fd, 0, Size),
ok = file:close(Fd),

?_assertEqual(
<<
"# TYPE pool_size gauge\n"
"# HELP pool_size MongoDB Connections pool size\n"
"pool_size 365\n"
"# TYPE http_requests_total counter\n"
"# HELP http_requests_total Http request count\n"
"http_requests_total 1\n"
"\n"
>>,
Buf
).
Loading