-
Notifications
You must be signed in to change notification settings - Fork 151
Open
Description
Hi 👋
I’m seeing an incompatibility when using prometheus-client with Ruby 4.x, specifically when using Prometheus::Client::DataStores::DirectFileStore.
The same code works correctly on Ruby 3.4.2, but fails on Ruby 4.0.1 with a NoMethodError related to CGI.parse.
Other data stores were not tested yet, but the error clearly originates from DirectFileStore.
Environment
Ruby:
✅ 3.4.2 (works)
❌ 4.0.1 (fails)
Reproduction steps
require 'prometheus/client'
require 'prometheus/client/data_stores/direct_file_store'
Prometheus::Client.config.data_store =
Prometheus::Client::DataStores::DirectFileStore.new(
dir: '/tmp/prometheus_direct_file_store'
)
prometheus = Prometheus::Client.registry
http_requests = Prometheus::Client::Counter.new(
:http_requests,
docstring: 'A counter of HTTP requests made',
labels: [:status_code]
)
prometheus.register(http_requests)
http_requests.increment(labels: { status_code: 200 })
prometheus.metrics.each do |metric|
puts "Metric: #{metric.name} #{metric.values}"
end
Expected behavior (Ruby 3.4.2)
Metric: http_requests {{} => 2.0, {status_code: "200"} => 15.0}
Actual behavior (Ruby 4.0.1)
/home/ebohrer/.asdf/installs/ruby/4.0.1/lib/ruby/gems/4.0.0/gems/prometheus-client-4.2.5/lib/prometheus/client/data_stores/direct_file_store.rb:139:in 'block (2 levels) in Prometheus::Client::DataStores::DirectFileStore::MetricStore#all_values': undefined method 'parse' for class CGI (NoMethodError)
label_set = CGI::parse(labelset_qs).map do |k, vs|
^^^^^^^
from /home/ebohrer/.asdf/installs/ruby/4.0.1/lib/ruby/gems/4.0.0/gems/prometheus-client-4.2.5/lib/prometheus/client/data_stores/direct_file_store.rb:135:in 'Array#each'
from /home/ebohrer/.asdf/installs/ruby/4.0.1/lib/ruby/gems/4.0.0/gems/prometheus-client-4.2.5/lib/prometheus/client/data_stores/direct_file_store.rb:135:in 'block in Prometheus::Client::DataStores::DirectFileStore::MetricStore#all_values'
from /home/ebohrer/.asdf/installs/ruby/4.0.1/lib/ruby/gems/4.0.0/gems/prometheus-client-4.2.5/lib/prometheus/client/data_stores/direct_file_store.rb:132:in 'Array#each'
from /home/ebohrer/.asdf/installs/ruby/4.0.1/lib/ruby/gems/4.0.0/gems/prometheus-client-4.2.5/lib/prometheus/client/data_stores/direct_file_store.rb:132:in 'Prometheus::Client::DataStores::DirectFileStore::MetricStore#all_values'
from /home/ebohrer/.asdf/installs/ruby/4.0.1/lib/ruby/gems/4.0.0/gems/prometheus-client-4.2.5/lib/prometheus/client/metric.rb:80:in 'Prometheus::Client::Metric#values'
from main.rb:17:in 'block in <main>'
from main.rb:16:in 'Array#each'
from main.rb:16:in '<main>'
Fast Analysis
This issue appears to be specific to DirectFileStore, more precisely in
DirectFileStore::MetricStore#all_values.
Ruby 4 removed or changed the availability of CGI.parse.
In Ruby 3.x this method exists, but in Ruby 4.x it raises NoMethodError.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels