Commit 82739bcd authored by Ahmad Sherif's avatar Ahmad Sherif

Merge branch 'sh-fix-database-bloat' into 'master'

Fix /database_bloat endpoint

See merge request gitlab-org/gitlab-exporter!124
parents bd165a59 b1dfbb67
Pipeline #177867 passed with stage
in 2 minutes and 13 seconds
......@@ -3,6 +3,8 @@ module GitLab
module Database
# Helper to collect bloat metrics.
class BloatCollector < Base
attr_writer :logger
def run(type = :btree)
execute(self.class.query_for(type)).each_with_object({}) do |row, h|
h[row["object_name"]] = row
......@@ -39,9 +41,11 @@ module GitLab
def initialize(opts,
metrics: PrometheusMetrics.new,
collector: BloatCollector.new(connection_string: opts[:connection_string]))
collector: BloatCollector.new(connection_string: opts[:connection_string]),
logger: nil)
@metrics = metrics
@collector = collector
@collector.logger = logger
@bloat_types = opts[:bloat_types] || %i(btree table)
end
......
......@@ -43,7 +43,11 @@ describe GitLab::Exporter::Database::BloatProber do
end
describe "#probe_db" do
subject { described_class.new(opts, metrics: metrics, collector: collector).probe_db }
subject { described_class.new(opts, metrics: metrics, collector: collector, logger: STDOUT).probe_db }
before do
expect(collector).to receive(:logger=).with(STDOUT)
end
it "invokes the collector for each bloat type" do
expect(collector).to receive(:run).with(:btree)
......
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