deadtrickster / prometheus.erl

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

Support global and prerendered labels together #147

Closed mkuratczyk closed 6 months ago

mkuratczyk commented 1 year ago

Without this change, a collector that pre-renders labels (like RabbitMQ) will return <<>> in case there are no labels at all. That will create an an improper list when an empty binary is appended to a list of global labels. Rather than dealing with improper list later, let's just avoid them.

binarin commented 1 year ago

It's better to pre-render global labels once to a single binary, outside the callback function - otherwise relatively large set of global labels can crash performance even if the app pre-renders labels itself.

binarin commented 1 year ago

Pre-rendered metrics are only compatible with text collector (protobuf is probably not being used by anyone, but the source code still exists here). So just to keep that working, maybe something like

          Metrics = [case ML of
                                 <<>> -> M#'Metric'{label = GlobalPrerendered};
                                 <<_>> -> M#'Metric'{label = <<GlobalPrerendered/binary, ",", ML/binary>>;
                                 _ -> M#'Metric'{label = Labels ++ ML}
                     end

prometheus_text_format:render_labels/1 is what can be used for pre-rendering, but it's currently not exported.

mkuratczyk commented 6 months ago

superseded by https://github.com/deadtrickster/prometheus.erl/pull/149