|
50 | 50 | -type label_name() :: term().
|
51 | 51 | -type label_value() :: term().
|
52 | 52 | -type label() :: {label_name(), label_value()}.
|
53 |
| --type labels() :: [label()]. |
| 53 | +-type pre_rendered_labels() :: binary(). |
| 54 | +-type labels() :: [label()] | pre_rendered_labels(). |
54 | 55 | -type value() :: float() | integer() | undefined | infinity.
|
55 | 56 | -type prometheus_boolean() :: boolean() | number() | list() | undefined.
|
56 | 57 | -type gauge() :: value() | {value()} | {labels(), value()}.
|
@@ -328,6 +329,18 @@ histogram_metric(Labels, Buckets, Count, Sum) ->
|
328 | 329 | %% @doc Equivalent to
|
329 | 330 | %% {@link label_pair/1. `lists:map(fun label_pair/1, Labels)'}.
|
330 | 331 | %% @end
|
| 332 | +%% |
| 333 | +%% NB `is_binary' clause here is for a special optimization for text |
| 334 | +%% format only: client code can pre-generate final labels string, |
| 335 | +%% e.g. when it knows when character escaping is not needed. This |
| 336 | +%% avoids direct performance cost of character escaping, and also |
| 337 | +%% reduces garabage collection pressure, as intermediate lists of |
| 338 | +%% tuples/records are not created at all. This optimization is used by |
| 339 | +%% RabbitMQ prometheus plugin (which calls `create_mf/5', and it ends |
| 340 | +%% here). |
| 341 | +%% WARNING Works only for text format, protobuf format export will |
| 342 | +%% fail with an error. |
| 343 | +label_pairs(B) when is_binary(B) -> B; |
331 | 344 | label_pairs(Labels) -> lists:map(fun label_pair/1, Labels).
|
332 | 345 |
|
333 | 346 | %% @doc
|
|
0 commit comments