Skip to content

Commit

Permalink
Prevent prometheus_quantile_summary crash without datapoints
Browse files Browse the repository at this point in the history
Quantile evaluation for metrics prior to observe/_ is not a valid operation.
Any metric without observation will now be skipped until data are
provided.
  • Loading branch information
Umberto Corponi committed Aug 18, 2021
1 parent d3a0fdf commit d12c22d
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/metrics/prometheus_quantile_summary.erl
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,12 @@ values(Registry, Name) ->

MFValues = load_all_values(Registry, Name),
ReducedMap = lists:foldl(
fun([L, C, S, QE], ResAcc) ->
{PrevCount, PrevSum, PrevQE} = maps:get(L, ResAcc, {0, 0, quantile(Configuration)}),
ResAcc#{L => {PrevCount + C, PrevSum + S, quantile_merge(PrevQE, QE)}}
fun
([_, 0, _, _], ResAcc) ->
ResAcc; %% Ignore quantile evaluation if no data are provided
([L, C, S, QE], ResAcc) ->
{PrevCount, PrevSum, PrevQE} = maps:get(L, ResAcc, {0, 0, quantile(Configuration)}),
ResAcc#{L => {PrevCount + C, PrevSum + S, quantile_merge(PrevQE, QE)}}
end,
#{},
MFValues),
Expand Down

0 comments on commit d12c22d

Please sign in to comment.