Skip to content

Commit

Permalink
mod_prometheus: use 'declare' rather than 'new' for histogram and cou…
Browse files Browse the repository at this point in the history
…nter (#339)

If a node crashes metrics might already be defined in prometheus and thus 'new'
would crash.
  • Loading branch information
sstrigler committed Oct 30, 2024
1 parent 4e58ae9 commit 25d8f4f
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions mod_prometheus/src/mod_prometheus.erl
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ handle_histogram(Name, HName, HistogramOpts, Host, Action, State) ->
InitArg = State#{name => HName, labels => LabelNames},
case Action of
subscribe ->
prometheus_histogram:new(
prometheus_histogram:declare(
[
{name, HName},
{buckets, maps:get(buckets, HistogramOpts, [1, 10, 100, 500, 750, 1000, 3000, 5000])},
Expand All @@ -377,7 +377,7 @@ handle_counter(Name, HName, CounterOpts, Host, Action, State) ->
InitArg = State#{name => HName, labels => LabelNames},
case Action of
subscribe ->
prometheus_counter:new(
prometheus_counter:declare(
[{name, HName}, {help, maps:get(help, CounterOpts, "No help")}, {labels, LabelNames}]
),
?INFO_MSG("Created new Prometheus counter for ~p with labels ~p", [HName, LabelNames]),
Expand Down Expand Up @@ -441,4 +441,4 @@ find_stanza_type([Arg | Args]) when is_tuple(Arg) ->
find_stanza_type([_ | Args]) ->
find_stanza_type(Args);
find_stanza_type([]) ->
unknown.
unknown.

0 comments on commit 25d8f4f

Please sign in to comment.