deadtrickster / prometheus.erl

Prometheus.io client in Erlang
MIT License
341 stars 117 forks source link

Prevent prometheus_quantile_summary crash without datapoints #132

Open umbec opened 3 years ago

umbec commented 3 years ago

quantile_estimator:quantile fails before prometheus_quantile_summary:observe/_ is performed.

prometheus_quantile_summary:declare([{name, test}, {labels, []}, {help, ""}]).
prometheus_text_format:format().

causes an exception:

** exception error: no function clause matching quantile_estimator:quantile(0.5,#Fun<quantile_estimator.1.111378939>,[],0,0,undefined) (/home/umberto/repos/prometheus.erl/_build/default/lib/quantile_estimator/src/quantile_estimator.erl, line 152)
     in function  prometheus_quantile_summary:'-quantile_values/2-lc$^0/1-0-'/2 (/home/umberto/repos/prometheus.erl/src/metrics/prometheus_quantile_summary.erl, line 476)
     in call from prometheus_quantile_summary:'-collect_metrics/2-fun-1-'/6 (/home/umberto/repos/prometheus.erl/src/metrics/prometheus_quantile_summary.erl, line 358)
     in call from prometheus_model_helpers:create_mf/5 (/home/umberto/repos/prometheus.erl/src/model/prometheus_model_helpers.erl, line 128)
     in call from prometheus_quantile_summary:'-collect_mf/2-lc$^0/1-0-'/3 (/home/umberto/repos/prometheus.erl/src/metrics/prometheus_quantile_summary.erl, line 336)
     in call from prometheus_quantile_summary:collect_mf/2 (/home/umberto/repos/prometheus.erl/src/metrics/prometheus_quantile_summary.erl, line 337)
     in call from prometheus_collector:collect_mf/3 (/home/umberto/repos/prometheus.erl/src/prometheus_collector.erl, line 156)
     in call from prometheus_registry:'-collect/2-lc$^0/1-0-'/3 (/home/umberto/repos/prometheus.erl/src/prometheus_registry.erl, line 86)

The suggested patch ignores the format operation for any quantile_summary metric without observations.