Commit 5cb83a56 authored by Alper Akgun's avatar Alper Akgun

Merge branch 'skip-metric-validation' into 'master'

Skip metric validation if status is deprecated or removed

See merge request gitlab-org/gitlab!58105
parents f7bf97d4 7efbc6a0
......@@ -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