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 b47c3d5
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 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 Expand Up @@ -343,9 +346,12 @@ collect_metrics(Name, {CLabels, Labels, Registry, DU, Configuration}) ->
#{quantiles := QNs} = Configuration,
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 b47c3d5

Please sign in to comment.