yabeda-prometheus icon indicating copy to clipboard operation
yabeda-prometheus copied to clipboard

Support for pushgateway groupping keys

Open josegomezr opened this issue 7 months ago • 0 comments

Yabeda doesn't offer a way to pass the the grouping_key param to the Prometheus PushGateway client.

See the parameter here:

https://github.com/prometheus/client_ruby/blob/main/lib/prometheus/client/push.rb#L31-L35

It allows for more granularity when pushing metrics to the push gateway.

Maybe something along the lines of:

# in lib/yabeda/prometheus.rb
def push_gateway(grouping_key: {})
  @push_gateway ||= ::Prometheus::Client::Push.new(
      job: ENV.fetch("PROMETHEUS_JOB_NAME", "yabeda"),
      gateway: ENV.fetch("PROMETHEUS_PUSH_GATEWAY", "http://localhost:9091"),
      grouping_key: grouping_key,
      open_timeout: 5, read_timeout: 30,
    )
end

so as the caller I could do:

Yabeda::Prometheus.push_gateway(grouping_key: { "key" => "value" }).add(Yabeda::Prometheus.registry)

Although it may be "surprising" that the groupping key persist throughout the lifecycle of the class, but given the volatile nature of the scenario using a push gateway it may be good enough (?)

josegomezr avatar Jul 23 '24 08:07 josegomezr