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

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,
collector: opts[:connection_string]))
collector: opts[:connection_string]),
logger: nil)
@metrics = metrics
@collector = collector
@collector.logger = logger
@bloat_types = opts[:bloat_types] || %i(btree table)
......@@ -43,7 +43,11 @@ describe GitLab::Exporter::Database::BloatProber do
describe "#probe_db" do
subject {, metrics: metrics, collector: collector).probe_db }
subject {, metrics: metrics, collector: collector, logger: STDOUT).probe_db }
before do
expect(collector).to receive(:logger=).with(STDOUT)
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