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 @@ ...@@ -55,6 +55,9 @@
"type": "string", "type": "string",
"enum": ["free", "starter", "premium", "ultimate", "bronze", "silver", "gold"] "enum": ["free", "starter", "premium", "ultimate", "bronze", "silver", "gold"]
} }
},
"skip_validation": {
"type": "boolean"
} }
} }
} }
...@@ -22,10 +22,12 @@ module Gitlab ...@@ -22,10 +22,12 @@ module Gitlab
end end
def validate! def validate!
self.class.schemer.validate(attributes.stringify_keys).map do |error| 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}`")) Gitlab::ErrorTracking.track_and_raise_for_dev_exception(Metric::InvalidMetricError.new("#{error["details"] || error['data_pointer']} for `#{path}`"))
end end
end end
end
alias_method :to_dictionary, :to_h alias_method :to_dictionary, :to_h
...@@ -78,6 +80,10 @@ module Gitlab ...@@ -78,6 +80,10 @@ module Gitlab
def method_missing(method, *args) def method_missing(method, *args)
attributes[method] || super attributes[method] || super
end end
def skip_validation?
!!attributes[:skip_validation]
end
end end
end end
end end
......
...@@ -65,6 +65,20 @@ RSpec.describe Gitlab::Usage::MetricDefinition do ...@@ -65,6 +65,20 @@ RSpec.describe Gitlab::Usage::MetricDefinition do
described_class.new(path, attributes).validate! described_class.new(path, attributes).validate!
end 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
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