Commit 894845b1 authored by Ahmad Sherif's avatar Ahmad Sherif

Use Licenses count as an indicator of an EE installation

Fixes #71
parent 97694202
PATH
remote: .
specs:
gitlab-exporter (7.0.4)
gitlab-exporter (7.0.5)
connection_pool (~> 2.2.1)
pg (~> 1.1)
quantile (~> 0.2.0)
......
......@@ -144,9 +144,9 @@ module GitLab
ci_builds.trigger_request_id
SQL
MIRROR_COLUMN_QUERY =
EE_CHECK_QUERY =
<<~SQL.freeze
SELECT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name='projects' AND column_name='mirror')
SELECT COUNT(*) FROM licenses
SQL
REPEATED_COMMANDS_QUERY_EE =
......@@ -289,7 +289,7 @@ module GitLab
def builds(status)
results = []
query = mirror_column? ? BUILDS_QUERY_EE : BUILDS_QUERY_CE
query = ee? ? BUILDS_QUERY_EE : BUILDS_QUERY_CE
query = query % [status] # rubocop:disable Style/FormatString
exec_query_with_custom_random_page_cost(query).each do |row|
results << transform_builds_row_to_values(row)
......@@ -318,7 +318,7 @@ module GitLab
def per_runner_builds
results = []
query = mirror_column? ? PER_RUNNER_QUERY_EE : PER_RUNNER_QUERY_CE
query = ee? ? PER_RUNNER_QUERY_EE : PER_RUNNER_QUERY_CE
exec_query_with_custom_random_page_cost(query).each do |row|
results << transform_per_runners_builds_row_to_values(row)
end
......@@ -341,7 +341,7 @@ module GitLab
def repeated_commands
results = []
query = mirror_column? ? REPEATED_COMMANDS_QUERY_EE : REPEATED_COMMANDS_QUERY_CE
query = ee? ? REPEATED_COMMANDS_QUERY_EE : REPEATED_COMMANDS_QUERY_CE
query = query % [allowed_repeated_commands_count] # rubocop:disable Style/FormatString
exec_query_with_custom_random_page_cost(query).each do |row|
results << transform_repeated_commands_row_to_values(row)
......@@ -406,11 +406,11 @@ module GitLab
end
end
def mirror_column?
@mirror_column ||=
def ee?
@ee ||=
begin
with_connection_pool do |conn|
conn.exec(MIRROR_COLUMN_QUERY)[0]["exists"] == "t"
conn.exec(EE_CHECK_QUERY)[0]["count"].to_i > 0 # rubocop:disable Style/NumericPredicate
end
rescue PG::UndefinedColumn
false
......
module GitLab
module Exporter
VERSION = "7.0.4".freeze
VERSION = "7.0.5".freeze
end
end
......@@ -9,7 +9,7 @@ describe GitLab::Exporter::Database do
let(:stale_builds_query) { "SELECT NOT UPDATED RUNNING" }
let(:per_runner_query_ee) { "SELECT ALL RUNNING PER RUNNER EE" }
let(:per_runner_query_ce) { "SELECT ALL RUNNING PER RUNNER CE" }
let(:mirror_column_query) { "SELECT DOES MIRROR COLUMN EXISTS" }
let(:ee_check_query) { "SELECT COUNT(*) FROM licenses" }
let(:repeated_commands_query_ee) { "SELECT EE REPEATED COMNANDS %d" }
let(:repeated_commands_query_ce) { "SELECT CE REPEATED COMNANDS %d" }
let(:unarchived_traces_query) { "SELECT UNARCHIVED TRACES %s LIST" }
......@@ -22,11 +22,11 @@ describe GitLab::Exporter::Database do
let(:unarchived_traces_offset_minutes) { 60 }
def stub_ee
allow(connection).to receive(:exec).with(mirror_column_query).and_return([{ "exists" => "t" }])
allow(connection).to receive(:exec).with(ee_check_query).and_return([{ "count" => 1 }])
end
def stub_ce
allow(connection).to receive(:exec).with(mirror_column_query).and_return([{ "exists" => "f" }])
allow(connection).to receive(:exec).with(ee_check_query).and_return([{ "count" => 0 }])
end
def builds_query_row_ee(shared_runners_enabled, status, namespace_id, has_minutes, count)
......@@ -86,7 +86,7 @@ describe GitLab::Exporter::Database do
stub_const("GitLab::Exporter::Database::CiBuildsCollector::STALE_BUILDS_QUERY", stale_builds_query)
stub_const("GitLab::Exporter::Database::CiBuildsCollector::PER_RUNNER_QUERY_EE", per_runner_query_ee)
stub_const("GitLab::Exporter::Database::CiBuildsCollector::PER_RUNNER_QUERY_CE", per_runner_query_ce)
stub_const("GitLab::Exporter::Database::CiBuildsCollector::MIRROR_COLUMN_QUERY", mirror_column_query)
stub_const("GitLab::Exporter::Database::CiBuildsCollector::EE_CHECK_QUERY", ee_check_query)
stub_const("GitLab::Exporter::Database::CiBuildsCollector::REPEATED_COMMANDS_QUERY_EE", repeated_commands_query_ee)
stub_const("GitLab::Exporter::Database::CiBuildsCollector::REPEATED_COMMANDS_QUERY_CE", repeated_commands_query_ce)
stub_const("GitLab::Exporter::Database::CiBuildsCollector::UNARCHIVED_TRACES_QUERY", unarchived_traces_query)
......
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