Remove CommonMetricsImporter patch

Remove CommonMetricsImporter patch and change all references to
CommonMetrics::Importer. Move specs into their appropriate folders. Also
cleans up some common_metric importer namespacing.
This commit is contained in:
Ryan Cobb 2019-07-03 16:19:15 -07:00
parent 3cabc5581e
commit 36f39eb318
12 changed files with 34 additions and 53 deletions

View file

@ -1,5 +1,3 @@
# frozen_string_literal: true
require Rails.root.join('db/importers/common_metrics_importer.rb')
::Importers::CommonMetricsImporter.new.execute
::Gitlab::Importers::CommonMetrics::Importer.new.execute

View file

@ -1,5 +1,3 @@
# frozen_string_literal: true
require Rails.root.join('db/importers/common_metrics_importer.rb')
::Importers::CommonMetricsImporter.new.execute
::Gitlab::Importers::CommonMetrics::Importer.new.execute

View file

@ -1,9 +0,0 @@
# This functionality has been moved to the lib/gitlab/importers/common_metrics module.
# This is here only to preserve existing ::Importers::CommonMetricsImporter api
module Importers
module CommonMetricsImporter
def self.new(*args)
Gitlab::Importers::CommonMetrics::Importer.new(*args)
end
end
end

View file

@ -3,12 +3,10 @@
class ImportCommonMetrics < ActiveRecord::Migration[4.2]
include Gitlab::Database::MigrationHelpers
require Rails.root.join('db/importers/common_metrics_importer.rb')
DOWNTIME = false
def up
Importers::CommonMetricsImporter.new.execute
::Gitlab::Importers::CommonMetrics::Importer.new.execute
end
def down

View file

@ -1,12 +1,10 @@
class ImportCommonMetricsNginxVts < ActiveRecord::Migration[5.0]
include Gitlab::Database::MigrationHelpers
require Rails.root.join('db/importers/common_metrics_importer.rb')
DOWNTIME = false
def up
Importers::CommonMetricsImporter.new.execute
::Gitlab::Importers::CommonMetrics::Importer.new.execute
end
def down

View file

@ -3,12 +3,10 @@
class ImportCommonMetricsKnative < ActiveRecord::Migration[5.0]
include Gitlab::Database::MigrationHelpers
require Rails.root.join('db/importers/common_metrics_importer.rb')
DOWNTIME = false
def up
Importers::CommonMetricsImporter.new.execute
::Gitlab::Importers::CommonMetrics::Importer.new.execute
end
def down

View file

@ -6,12 +6,10 @@
class PrometheusKnative05Fix < ActiveRecord::Migration[5.0]
include Gitlab::Database::MigrationHelpers
require Rails.root.join('db/importers/common_metrics_importer.rb')
DOWNTIME = false
def up
Importers::CommonMetricsImporter.new.execute
::Gitlab::Importers::CommonMetrics::Importer.new.execute
end
def down

View file

@ -33,12 +33,10 @@ For example: you might be interested in migrating all dependent data to a differ
class ImportCommonMetrics < ActiveRecord::Migration[4.2]
include Gitlab::Database::MigrationHelpers
require Rails.root.join('db/importers/common_metrics_importer.rb')
DOWNTIME = false
def up
Importers::CommonMetricsImporter.new.execute
::Gitlab::Importers::CommonMetrics::Importer.new.execute
end
def down

View file

@ -13,7 +13,7 @@ module Gitlab
end
def execute
::Gitlab::Importers::CommonMetrics::PrometheusMetric.reset_column_information
CommonMetrics::PrometheusMetric.reset_column_information
process_content do |id, attributes|
find_or_build_metric!(id)
@ -62,17 +62,17 @@ module Gitlab
def find_or_build_metric!(id)
raise MissingQueryId unless id
::Gitlab::Importers::CommonMetrics::PrometheusMetric.common.find_by(identifier: id) ||
::Gitlab::Importers::CommonMetrics::PrometheusMetric.new(common: true, identifier: id)
CommonMetrics::PrometheusMetric.common.find_by(identifier: id) ||
CommonMetrics::PrometheusMetric.new(common: true, identifier: id)
end
# rubocop: enable CodeReuse/ActiveRecord
def find_group_title_key(title)
::Gitlab::Importers::CommonMetrics::PrometheusMetricEnums.groups[find_group_title(title)]
CommonMetrics::PrometheusMetricEnums.groups[find_group_title(title)]
end
def find_group_title(title)
::Gitlab::Importers::CommonMetrics::PrometheusMetricEnums.group_titles.invert[title]
CommonMetrics::PrometheusMetricEnums.group_titles.invert[title]
end
end
end

View file

@ -38,3 +38,5 @@ module Gitlab
end
end
end
::Gitlab::Importers::CommonMetrics::PrometheusMetricEnums.prepend EE::Gitlab::Importers::CommonMetrics::PrometheusMetricEnums

View file

@ -1,25 +1,8 @@
# frozen_string_literal: true
require 'rails_helper'
require Rails.root.join("db", "importers", "common_metrics_importer.rb")
describe Gitlab::Importers::CommonMetrics::PrometheusMetric do
let(:existing_group_titles) do
::PrometheusMetricEnums.group_details.each_with_object({}) do |(key, value), memo|
memo[key] = value[:group_title]
end
end
it 'group enum equals ::PrometheusMetric' do
expect(described_class.groups).to eq(::PrometheusMetric.groups)
end
it 'GROUP_TITLES equals ::PrometheusMetric' do
expect(Gitlab::Importers::CommonMetrics::PrometheusMetricEnums.group_titles).to eq(existing_group_titles)
end
end
describe Importers::CommonMetricsImporter do
describe Gitlab::Importers::CommonMetrics::Importer do
subject { described_class.new }
context "does import common_metrics.yml" do

View file

@ -0,0 +1,19 @@
# frozen_string_literal: true
require 'rails_helper'
describe Gitlab::Importers::CommonMetrics::PrometheusMetric do
let(:existing_group_titles) do
::PrometheusMetricEnums.group_details.each_with_object({}) do |(key, value), memo|
memo[key] = value[:group_title]
end
end
it 'group enum equals ::PrometheusMetric' do
expect(described_class.groups).to eq(::PrometheusMetric.groups)
end
it '.group_titles equals ::PrometheusMetric' do
expect(Gitlab::Importers::CommonMetrics::PrometheusMetricEnums.group_titles).to eq(existing_group_titles)
end
end