Skip to content
Snippets Groups Projects
Commit 06964419 authored by Ahmad Sherif's avatar Ahmad Sherif
Browse files

Merge branch 'fix/ci-builds-exception' into 'master'

Return a correct result structure in case of an exception in CiBuildsCollector#get_builds

See merge request !50
parents ac211af7 59f06a27
No related branches found
No related tags found
1 merge request!50Return a correct result structure in case of an exception in CiBuildsCollector#get_builds
Pipeline #
PATH
remote: .
specs:
gitlab-monitor (1.5.0)
gitlab-monitor (1.6.0)
pg (~> 0.18.4)
quantile (~> 0.2.0)
redis-namespace (~> 1.5.2)
Loading
Loading
Loading
Loading
@@ -103,7 +103,7 @@ module GitLab
 
results
rescue PG::UndefinedTable, PG::UndefinedColumn
{}
results
end
end
 
Loading
Loading
module GitLab
module Monitor
VERSION = "1.5.0".freeze
VERSION = "1.6.0".freeze
end
end
Loading
Loading
@@ -71,25 +71,48 @@ describe GitLab::Monitor::Database do
allow_any_instance_of(GitLab::Monitor::Database::CiBuildsCollector).to receive(:connected?).and_return(true)
end
 
it "responds with Prometheus metrics" do
prober.probe_db
prober.write_to(writer)
context "when no PG exceptions are raised" do
it "responds with Prometheus metrics" do
prober.probe_db
prober.write_to(writer)
 
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 = <<-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}/, ""))
expect(writer.string).to eq(output.strip_heredoc)
end
end
context "when PG exceptions are raised" do
before do
allow(connection).to receive(:exec).and_raise(PG::UndefinedColumn)
end
it "responds with Prometheus metrics" do
prober.probe_db
prober.write_to(writer)
output = <<-OUTPUT
ci_pending_builds{namespace="",shared_runners="yes"} 0
ci_pending_builds{namespace="",shared_runners="no"} 0
ci_created_builds{namespace="",shared_runners="yes"} 0
ci_created_builds{namespace="",shared_runners="no"} 0
ci_stale_builds 0
OUTPUT
expect(writer.string).to eq(output.strip_heredoc)
end
end
end
end
Loading
Loading
@@ -4,6 +4,9 @@ require "gitlab_monitor"
require "open3"
require "tmpdir"
 
$LOAD_PATH.unshift File.expand_path(".")
Dir["spec/support/**/*.rb"].each do |f| require f end
class GitRepoBuilder
def origin
@origin ||= create_origin
Loading
Loading
class String
# Copied from activesupport gem
def strip_heredoc
gsub(/^#{scan(/^[ \t]*(?=\S)/).min}/, "".freeze)
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment