Skip to content

Commit 8de56e7

Browse files
authored
Merge pull request #5793 from apache/wh/fix-prometheus
fix: prometheus metrics annotations
2 parents f06c3ec + e7be0ad commit 8de56e7

2 files changed

Lines changed: 23 additions & 6 deletions

File tree

src/couch_prometheus/src/couch_prometheus_util.erl

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ couch_to_prom(Path, Info, _All) ->
116116
type_def(Metric, Type, Desc) ->
117117
Name = to_prom_name(Metric),
118118
[
119-
to_bin(io_lib:format("\n# HELP ~s ~s\r", [Name, Desc])),
119+
to_bin(io_lib:format("\n# HELP ~s ~s", [Name, Desc])),
120120
to_bin(io_lib:format("# TYPE ~s ~s", [Name, Type]))
121121
].
122122

@@ -126,7 +126,7 @@ to_prom(_Metric, _Type, _Desc, []) ->
126126
[];
127127
to_prom(Metric, Type, Desc, Instances) when is_list(Instances) ->
128128
TypeStr = type_def(Metric, Type, Desc),
129-
[TypeStr] ++ lists:flatmap(fun(Inst) -> to_prom(Metric, Inst) end, Instances);
129+
TypeStr ++ lists:flatmap(fun(Inst) -> to_prom(Metric, Inst) end, Instances);
130130
to_prom(Metric, Type, Desc, Data) ->
131131
to_prom(Metric, Type, Desc, [Data]).
132132

@@ -221,6 +221,23 @@ desc(Info) ->
221221
-ifdef(TEST).
222222
-include_lib("couch/include/couch_eunit.hrl").
223223

224+
to_prom_annotations_test() ->
225+
Out = to_prom(couchdb_bt_engine_cache_size, gauge, "number of entries in the btree cache", 9),
226+
[
227+
?assertEqual(
228+
<<"\n# HELP couchdb_couchdb_bt_engine_cache_size number of entries in the btree cache">>,
229+
lists:nth(1, Out)
230+
),
231+
?assertEqual(
232+
<<"# TYPE couchdb_couchdb_bt_engine_cache_size gauge">>,
233+
lists:nth(2, Out)
234+
),
235+
?assertEqual(
236+
<<"couchdb_couchdb_bt_engine_cache_size 9">>,
237+
lists:nth(3, Out)
238+
)
239+
].
240+
224241
to_prom_counter_test() ->
225242
[
226243
?assertEqual(
@@ -288,10 +305,10 @@ counter_metric_test_() ->
288305

289306
test_to_prom_output(Metric, Type, Desc, Val) ->
290307
Out = to_prom(Metric, Type, Desc, Val),
291-
lists:nth(2, Out).
308+
lists:nth(3, Out).
292309

293310
test_to_prom_summary_output(Metric, Info) ->
294311
Out = to_prom_summary(Metric, Info),
295-
lists:nth(3, Out).
312+
lists:nth(4, Out).
296313

297314
-endif.

src/couch_prometheus/test/eunit/couch_prometheus_e2e_tests.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,12 @@ t_survives_mem3_sync_termination(_) ->
177177
ok = supervisor:terminate_child(mem3_sup, mem3_sync),
178178
?assertEqual(undefined, whereis(mem3_sync)),
179179
?assertMatch(
180-
[[_, _], <<"couchdb_internal_replication_jobs 0">>],
180+
[_, _, <<"couchdb_internal_replication_jobs 0">>],
181181
couch_prometheus:get_internal_replication_jobs_stat()
182182
),
183183
{ok, _} = supervisor:restart_child(mem3_sup, mem3_sync),
184184
?assertMatch(
185-
[[_, _], <<"couchdb_internal_replication_jobs", _/binary>>],
185+
[_, _, <<"couchdb_internal_replication_jobs", _/binary>>],
186186
couch_prometheus:get_internal_replication_jobs_stat()
187187
).
188188

0 commit comments

Comments
 (0)