Commit e79b7cf9 authored by Mikołaj Wawrzyniak's avatar Mikołaj Wawrzyniak

Merge branch 'am-add-skip-validation-attribute-to-metric-definitions' into 'master'

Add skip_validation attribute to metric definition

See merge request gitlab-org/gitlab!52226
parents 1894a85f 4b663bbe
......@@ -55,6 +55,9 @@
"type": "string",
"enum": ["free", "starter", "premium", "ultimate", "bronze", "silver", "gold"]
}
},
"skip_validation": {
"type": "boolean"
}
}
}
......@@ -22,8 +22,10 @@ module Gitlab
end
def validate!
self.class.schemer.validate(attributes.stringify_keys).map do |error|
Gitlab::ErrorTracking.track_and_raise_for_dev_exception(Metric::InvalidMetricError.new("#{error["details"] || error['data_pointer']} for `#{path}`"))
unless skip_validation?
self.class.schemer.validate(attributes.stringify_keys).each do |error|
Gitlab::ErrorTracking.track_and_raise_for_dev_exception(Metric::InvalidMetricError.new("#{error["details"] || error['data_pointer']} for `#{path}`"))
end
end
end
......@@ -78,6 +80,10 @@ module Gitlab
def method_missing(method, *args)
attributes[method] || super
end
def skip_validation?
!!attributes[:skip_validation]
end
end
end
end
......
......@@ -65,6 +65,20 @@ RSpec.describe Gitlab::Usage::MetricDefinition do
described_class.new(path, attributes).validate!
end
context 'with skip_validation' do
it 'raise exception if skip_validation: false' do
expect(Gitlab::ErrorTracking).to receive(:track_and_raise_for_dev_exception).at_least(:once).with(instance_of(Gitlab::Usage::Metric::InvalidMetricError))
described_class.new(path, attributes.merge( { skip_validation: false } )).validate!
end
it 'does not raise exception if has skip_validation: true' do
expect(Gitlab::ErrorTracking).not_to receive(:track_and_raise_for_dev_exception)
described_class.new(path, attributes.merge( { skip_validation: true } )).validate!
end
end
end
end
......
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