diff options
author | Will Holley <will.holley@uk.ibm.com> | 2023-04-14 14:32:01 +0000 |
---|---|---|
committer | Will Holley <will.holley@uk.ibm.com> | 2023-04-14 14:32:01 +0000 |
commit | daecd3f50cefffa6b883edb569197fc8732080eb (patch) | |
tree | 3a43b525de3470848e9be80ed0c0e5708e2e74dc | |
parent | 16a350b9764343fabbffa22abcbe1ccd54096fe7 (diff) | |
download | couchdb-daecd3f50cefffa6b883edb569197fc8732080eb.tar.gz |
fix (prometheus): do not emit ophaned HELP/TYPE lines
In cases where metrics are optional, prevent `# HELP` and `# TYPE`
lines from being emitted if there is no corresponding metric series.
-rw-r--r-- | src/couch_prometheus/src/couch_prometheus_util.erl | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/src/couch_prometheus/src/couch_prometheus_util.erl b/src/couch_prometheus/src/couch_prometheus_util.erl index 4665ba7f9..51a902163 100644 --- a/src/couch_prometheus/src/couch_prometheus_util.erl +++ b/src/couch_prometheus/src/couch_prometheus_util.erl @@ -125,6 +125,8 @@ type_def(Metric, Type, Desc) -> % support creating a metric series with multiple label/values. % Instances is of the form [{[{LabelName, LabelValue}], Value}, ...] +to_prom(_Metric, _Type, _Desc, []) -> + []; to_prom(Metric, Type, Desc, Instances) when is_list(Instances) -> TypeStr = type_def(Metric, Type, Desc), [TypeStr] ++ lists:flatmap(fun(Inst) -> to_prom(Metric, Inst) end, Instances); |