Commit 6e38391b authored by Ahmad Sherif's avatar Ahmad Sherif
Browse files

Merge branch 'bjk/more_ci_builds' into 'master'

Cleanup stale builds metric

See merge request !41
parents 11c9071d 69c43ff5
Pipeline #42859 passed with stage
in 4 minutes and 59 seconds
PATH
remote: .
specs:
gitlab-monitor (1.1.0)
gitlab-monitor (1.2.0)
pg (~> 0.18.4)
quantile (~> 0.2.0)
redis-namespace (~> 1.5.2)
......
......@@ -19,7 +19,7 @@ module GitLab
" ci_builds.status, " \
" projects.shared_runners_enabled".freeze
NOT_UPDATED_RUNNING_BUILDS_QUERY =
STALE_BUILDS_QUERY =
"SELECT " \
" COUNT(*) AS count " \
" FROM ci_builds " \
......@@ -54,7 +54,7 @@ module GitLab
results.merge!(get_builds(BUILDS_QUERY))
results[:not_updated_last_hour] = get_general(NOT_UPDATED_RUNNING_BUILDS_QUERY)
results[:stale_builds] = get_general(STALE_BUILDS_QUERY)
results[:per_runner] = get_per_runner(PER_RUNNER_QUERY)
results
end
......@@ -152,7 +152,7 @@ module GitLab
end
def ci_stale_builds_metrics
@metrics.add("ci_builds_stale", @results[:not_updated_last_hour], status: "running", when: "last_hour")
@metrics.add("ci_stale_builds", @results[:stale_builds])
end
def metrics_per_runner
......
module GitLab
module Monitor
VERSION = "1.1.0".freeze
VERSION = "1.2.0".freeze
end
end
......@@ -4,14 +4,13 @@ require "gitlab_monitor/database/ci_builds"
# rubocop:disable Metrics/LineLength
describe GitLab::Monitor::Database do
let(:builds_query) { "SELECT BUILDS" }
let(:not_updated_running_builds_query) { "SELECT NOT UPDATED RUNNING" }
let(:stale_builds_query) { "SELECT NOT UPDATED RUNNING" }
let(:per_runner_query) { "SELECT ALL RUNNING PER RUNNER" }
let(:connection) { double("connection") }
before do
stub_const("GitLab::Monitor::Database::CiBuildsCollector::BUILDS_QUERY", builds_query)
stub_const("GitLab::Monitor::Database::CiBuildsCollector::NOT_UPDATED_RUNNING_BUILDS_QUERY",
not_updated_running_builds_query)
stub_const("GitLab::Monitor::Database::CiBuildsCollector::STALE_BUILDS_QUERY", stale_builds_query)
stub_const("GitLab::Monitor::Database::CiBuildsCollector::PER_RUNNER_QUERY", per_runner_query)
allow_any_instance_of(GitLab::Monitor::Database::CiBuildsCollector).to receive(:connection).and_return(connection)
......@@ -23,7 +22,7 @@ describe GitLab::Monitor::Database do
{ "shared_runners_enabled" => "t", "status" => "pending", "namespace_id" => "2", "count" => 50 },
{ "shared_runners_enabled" => "t", "status" => "pending", "namespace_id" => "3", "count" => 1 },
{ "shared_runners_enabled" => "t", "status" => "pending", "namespace_id" => "4", "count" => 2 }])
allow(connection).to receive(:exec).with(not_updated_running_builds_query).and_return([{ "count" => 2 }])
allow(connection).to receive(:exec).with(stale_builds_query).and_return([{ "count" => 2 }])
allow(connection).to receive(:exec).with(per_runner_query)
.and_return([{ "runner_id" => 1,
"is_shared" => "t",
......@@ -57,7 +56,7 @@ describe GitLab::Monitor::Database do
{ namespace: "1", shared_runners: "no", value: 10 },
{ namespace: "2", shared_runners: "no", value: 20 }
],
not_updated_last_hour: 2)
stale_builds: 2)
end
end
......@@ -76,17 +75,21 @@ describe GitLab::Monitor::Database do
prober.probe_db
prober.write_to(writer)
expect(writer.string).to match(/ci_created_builds{namespace="1",shared_runners="no"} 10/)
expect(writer.string).to match(/ci_created_builds{namespace="2",shared_runners="no"} 20/)
expect(writer.string).to match(/ci_pending_builds{namespace="1",shared_runners="yes"} 30/)
expect(writer.string).to match(/ci_pending_builds{namespace="2",shared_runners="yes"} 50/)
expect(writer.string).to match(/ci_pending_builds{namespace="",shared_runners="yes"} 3/)
expect(writer.string).to match(/ci_pending_builds{namespace="",shared_runners="no"} 0/)
expect(writer.string).to match(/ci_created_builds{namespace="",shared_runners="yes"} 0/)
expect(writer.string).to match(/ci_created_builds{namespace="",shared_runners="no"} 0/)
expect(writer.string).to match(/ci_builds_stale{status="running",when="last_hour"} 2/)
expect(writer.string).to match(/ci_running_builds{runner="1",shared_runner="yes",mirror="no",pending_delete="no",mirror_trigger_builds="no"} 15/)
expect(writer.string).to match(/ci_running_builds{runner="2",shared_runner="no",mirror="yes",pending_delete="no",mirror_trigger_builds="yes"} 5/)
output = <<-OUTPUT
ci_pending_builds{namespace="1",shared_runners="yes"} 30
ci_pending_builds{namespace="2",shared_runners="yes"} 50
ci_pending_builds{namespace="",shared_runners="yes"} 3
ci_pending_builds{namespace="",shared_runners="no"} 0
ci_created_builds{namespace="1",shared_runners="no"} 10
ci_created_builds{namespace="2",shared_runners="no"} 20
ci_created_builds{namespace="",shared_runners="yes"} 0
ci_created_builds{namespace="",shared_runners="no"} 0
ci_stale_builds 2
ci_running_builds{runner="1",shared_runner="yes",mirror="no",pending_delete="no",mirror_trigger_builds="no"} 15
ci_running_builds{runner="2",shared_runner="no",mirror="yes",pending_delete="no",mirror_trigger_builds="yes"} 5
OUTPUT
expect(writer.string).to eq(output.gsub(/^ {8}/, ""))
end
end
end
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