Commit c4f15e21 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Remove the class level metrics memoization

This would cause us to keep track of a reference of all metrics on the
class level.

Which would mean we would keep looking at the old metrics the registry
in that we kept track of in [Prometheus::Client::Registry#metrics][0]
after it was reset using[Gitlab::Metrics.reset_registry][1].

This wouldn't cause any issues in production, because the metrics are
never reset. But in specs, we do count on those being reset in between
runs.

This is safe to do, because the registry itself is memoized on
[Gitlab::Metrics][2].

Getting the specific metric is an [initialization the first time
around][3], but after a registry is memoized, it's just a [read from a
hash][4].

[0] https://gitlab.com/gitlab-org/prometheus-client-mmap/-/blob/9e5b696dfd47a96cf22808cbebb04f00cd3d4ffc/lib/prometheus/client/registry.rb#L17
[1] https://gitlab.com/gitlab-org/gitlab/blob/82db58bab85531e49fa7264d6461928d49425a6e/lib/gitlab/metrics/prometheus.rb#L30
[2] https://gitlab.com/gitlab-org/gitlab/blob/82db58bab85531e49fa7264d6461928d49425a6e/lib/gitlab/metrics/prometheus.rb#L39
[3] https://gitlab.com/gitlab-org/gitlab/blob/82db58bab85531e49fa7264d6461928d49425a6e/lib/gitlab/metrics/prometheus.rb#L87
[4] https://gitlab.com/gitlab-org/prometheus-client-mmap/-/blob/9e5b696dfd47a96cf22808cbebb04f00cd3d4ffc/lib/prometheus/client/registry.rb#L56
parent 82db58ba
......@@ -32,20 +32,20 @@ module Gitlab
end
def self.http_requests_total
@http_requests_total ||= ::Gitlab::Metrics.counter(:http_requests_total, 'Request count')
::Gitlab::Metrics.counter(:http_requests_total, 'Request count')
end
def self.rack_uncaught_errors_count
@rack_uncaught_errors_count ||= ::Gitlab::Metrics.counter(:rack_uncaught_errors_total, 'Request handling uncaught errors count')
::Gitlab::Metrics.counter(:rack_uncaught_errors_total, 'Request handling uncaught errors count')
end
def self.http_request_duration_seconds
@http_request_duration_seconds ||= ::Gitlab::Metrics.histogram(:http_request_duration_seconds, 'Request handling execution time',
{}, [0.05, 0.1, 0.25, 0.5, 0.7, 1, 2.5, 5, 10, 25])
::Gitlab::Metrics.histogram(:http_request_duration_seconds, 'Request handling execution time',
{}, [0.05, 0.1, 0.25, 0.5, 0.7, 1, 2.5, 5, 10, 25])
end
def self.http_health_requests_total
@http_health_requests_total ||= ::Gitlab::Metrics.counter(:http_health_requests_total, 'Health endpoint request count')
::Gitlab::Metrics.counter(:http_health_requests_total, 'Health endpoint request count')
end
def self.initialize_metrics
......
......@@ -365,7 +365,7 @@ RSpec.configure do |config|
end
config.before(:example, :prometheus) do
matching_files = File.join(::Prometheus::Client.configuration.multiprocess_files_dir, "*.db")
matching_files = File.join(::Prometheus::Client.configuration.multiprocess_files_dir, "**/*.db")
Dir[matching_files].map { |filename| File.delete(filename) if File.file?(filename) }
Gitlab::Metrics.reset_registry!
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment