Commit 7efbc6a0 authored by Rajendra Kadam's avatar Rajendra Kadam Committed by Alper Akgun

Skip metric validation if status is deprecated or removed

parent 7f9a47c1
......@@ -5,6 +5,7 @@ module Gitlab
class MetricDefinition
METRIC_SCHEMA_PATH = Rails.root.join('config', 'metrics', 'schema.json')
BASE_REPO_PATH = 'https://gitlab.com/gitlab-org/gitlab/-/blob/master'
DEPRECATED_METRIC_STATUSES = %w[deprecated removed].to_set.freeze
attr_reader :path
attr_reader :attributes
......@@ -106,7 +107,7 @@ module Gitlab
end
def skip_validation?
!!attributes[:skip_validation] || @skip_validation
!!attributes[:skip_validation] || @skip_validation || DEPRECATED_METRIC_STATUSES.include?(attributes[:status])
end
end
end
......
......@@ -84,6 +84,33 @@ RSpec.describe Gitlab::Usage::MetricDefinition do
end
end
describe 'statuses' do
using RSpec::Parameterized::TableSyntax
where(:status, :raise_exception) do
'deprecated' | false
'removed' | false
'data_available' | false
'random' | true
end
with_them do
subject(:validation) do
described_class.new(path, attributes.merge( { status: status } )).validate!
end
it "checks for valid/invalid statuses" do
if raise_exception
expect(Gitlab::ErrorTracking).to receive(:track_and_raise_for_dev_exception).at_least(:once).with(instance_of(Gitlab::Usage::Metric::InvalidMetricError))
else
expect(Gitlab::ErrorTracking).not_to receive(:track_and_raise_for_dev_exception)
end
validation
end
end
end
describe '.load_all!' do
let(:metric1) { Dir.mktmpdir('metric1') }
let(:metric2) { Dir.mktmpdir('metric2') }
......
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