From d466a6f1ca3da12948a374eb132d39742cc38b77 Mon Sep 17 00:00:00 2001 From: Tomasz Maczukin Date: Wed, 3 Apr 2019 20:08:57 +0200 Subject: [PATCH] Make ci_created_builds to be gathered by default with option to disable --- config/gitlab-monitor.yml.example | 2 +- lib/gitlab_monitor/database/ci_builds.rb | 6 +++--- spec/database/ci_builds_spec.rb | 22 +++++++++++----------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/config/gitlab-monitor.yml.example b/config/gitlab-monitor.yml.example index 4957fb4..782d289 100644 --- a/config/gitlab-monitor.yml.example +++ b/config/gitlab-monitor.yml.example @@ -46,7 +46,7 @@ probes: opts: <<: *db_common_opts allowed_repeated_commands_count: 2 - count_created_builds: false + created_builds_counting_disabled: true tuple_stats: class_name: Database::TuplesProber <<: *db_common diff --git a/lib/gitlab_monitor/database/ci_builds.rb b/lib/gitlab_monitor/database/ci_builds.rb index 7f741ef..acae76b 100644 --- a/lib/gitlab_monitor/database/ci_builds.rb +++ b/lib/gitlab_monitor/database/ci_builds.rb @@ -239,12 +239,12 @@ module GitLab super(opts) @allowed_repeated_commands_count = opts[:allowed_repeated_commands_count] - @count_created_builds = opts[:count_created_builds] + @created_builds_counting_disabled = opts[:created_builds_counting_disabled] end def run results = {} - results[:created_builds] = builds(STATUS_CREATED) if @count_created_builds + results[:created_builds] = builds(STATUS_CREATED) unless @created_builds_counting_disabled results[:pending_builds] = builds(STATUS_PENDING) results[:stale_builds] = stale_builds results[:per_runner] = per_runner_builds @@ -378,7 +378,7 @@ module GitLab collector_opts = { connection_string: opts[:connection_string], allowed_repeated_commands_count: opts[:allowed_repeated_commands_count], - count_created_builds: opts[:count_created_builds] } + created_builds_counting_disabled: opts[:created_builds_counting_disabled] } @collector = CiBuildsCollector.new(collector_opts) end diff --git a/spec/database/ci_builds_spec.rb b/spec/database/ci_builds_spec.rb index 141b849..b76c1ee 100644 --- a/spec/database/ci_builds_spec.rb +++ b/spec/database/ci_builds_spec.rb @@ -15,7 +15,7 @@ describe GitLab::Monitor::Database do let(:connection_pool) { double("connection pool") } let(:connection) { double("connection") } let(:allowed_repeated_commands_count) { 5 } - let(:count_created_builds) { false } + let(:created_builds_counting_disabled) { true } def stub_ee allow(connection).to receive(:exec).with(mirror_column_query).and_return([{ "exists" => "t" }]) @@ -146,7 +146,7 @@ describe GitLab::Monitor::Database do let(:collector) do described_class.new(connection_string: "host=localhost", allowed_repeated_commands_count: allowed_repeated_commands_count, - count_created_builds: count_created_builds) + created_builds_counting_disabled: created_builds_counting_disabled) end let(:expected_stale_builds) { 2 } @@ -161,8 +161,8 @@ describe GitLab::Monitor::Database do expect(subject[:pending_builds]).to include(*expected_pending_builds) end - context "when count_created_build is set to true" do - let(:count_created_builds) { true } + context "when created_builds_counting_disabled is set to false" do + let(:created_builds_counting_disabled) { false } it "returns raw created_builds data" do expect(subject).to have_key(:created_builds) @@ -170,8 +170,8 @@ describe GitLab::Monitor::Database do end end - context "when count_created_build is set to false" do - let(:count_created_builds) { false } + context "when created_builds_counting_disabled is set to true" do + let(:created_builds_counting_disabled) { true } it "doesn't return raw created_builds data" do expect(subject).not_to have_key(:created_builds) @@ -257,7 +257,7 @@ describe GitLab::Monitor::Database do let(:prober) do opts = { connection_string: "host=localhost", allowed_repeated_commands_count: allowed_repeated_commands_count, - count_created_builds: count_created_builds } + created_builds_counting_disabled: created_builds_counting_disabled } described_class.new(opts, metrics: GitLab::Monitor::PrometheusMetrics.new(include_timestamp: false)) end @@ -274,8 +274,8 @@ describe GitLab::Monitor::Database do end context "when PG exceptions aren't raised" do - context "when count_created_builds is set to true" do - let(:count_created_builds) { true } + context "when created_builds_counting_disabled is set to false" do + let(:created_builds_counting_disabled) { false } it "responds with created builds Prometheus metrics" do ci_created_builds_expected_lines.each do |expected_line| @@ -284,8 +284,8 @@ describe GitLab::Monitor::Database do end end - context "when count_created_builds is set to false" do - let(:count_created_builds) { false } + context "when created_builds_counting_disabled is set to true" do + let(:created_builds_counting_disabled) { true } it "doesn't respond with created builds Prometheus metrics" do ci_created_builds_expected_lines.each do |expected_line| -- GitLab