Tags: prometheus-erl/prometheus.erl
Tags
prometheus_text_format: Fix argument order for `format_into/3` fun The formatting function should take the state as the first argument and new data as the second. See `format/1` which passes in the trailing linefeed as the second argument. This doesn't make much difference when calling `format/1` because the swapped arguments only caused the metrics to be concatenated in reverse. But this fix is important for using `format_into/3` correctly, for example with `cowboy_req:stream_body/3`.
prometheus_text_format: Eliminate `ram_file`, add `format_into/3` Building on the work in the parent commit, now that the data being passed to the `ram_file` is a binary, we can instead build the entire output gradually within the process. We pay in terms of I/O overhead from writing and then reading from the `ram_file` since `ram_file` is a port - all data is passed between the VM and the port driver. The memory consumed by a port driver is also invisible to the VM's allocator, so large port driver resource usage should be avoided where possible. Instead this change refactors the `registry_collect_callback` to fold over collectors and build an accumulator. The `create_mf` callback's return of `ok` forces us to store this rather than pass and return it. So it's a little less hygienic but is more efficient than passing data in/out of a port. This also introduces a function `format_into/3` which can use this folding function directly. This can be used to avoid collecting the entire response in one binary. Instead the response can be streamed with `cowboy_req:stream_body/3` for example.
PreviousNext