From 297a6e6c1607807e5773552ebc7160828594f4ee Mon Sep 17 00:00:00 2001 From: Aaron Kyungmin Seo Date: Thu, 16 Nov 2023 14:39:18 -0800 Subject: [PATCH] Move export prometheus_text_format:escape_label_value outside of TEST def (#158) * Move export prometheus_text_format:escape_label_value outside of TEST def * update escape_label_value spec --- src/formats/prometheus_text_format.erl | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/formats/prometheus_text_format.erl b/src/formats/prometheus_text_format.erl index d8fec36d..da407d15 100644 --- a/src/formats/prometheus_text_format.erl +++ b/src/formats/prometheus_text_format.erl @@ -22,11 +22,12 @@ -export([content_type/0, format/0, format/1, - render_labels/1]). + render_labels/1, + escape_label_value/1 + ]). -ifdef(TEST). -export([escape_metric_help/1, - escape_label_value/1, emit_mf_prologue/2, emit_mf_metrics/2 ]). @@ -76,6 +77,16 @@ format(Registry) -> ok = file:close(Fd), Str. +-spec escape_label_value(binary() | iolist()) -> binary() + ; (undefined) -> no_return(). +%% @doc +%% Escapes the backslash (\), double-quote ("), and line feed (\n) characters +%% @end +escape_label_value(LValue) when is_list(LValue); is_binary(LValue) -> + escape_string(fun escape_label_char/1, LValue); +escape_label_value(Value) -> + erlang:error({wtf, Value}). + %%==================================================================== %% Private Parts %%==================================================================== @@ -227,13 +238,6 @@ bound_to_label_value(Bound) when is_float(Bound) -> bound_to_label_value(infinity) -> "+Inf". --spec escape_label_value(binary() | iolist() | undefined) -> binary(). -%% @private -escape_label_value(LValue) when is_list(LValue); is_binary(LValue) -> - escape_string(fun escape_label_char/1, LValue); -escape_label_value(Value) -> - erlang:error({wtf, Value}). - %% @private escape_label_char($\\ = X) -> <>;