Commit ac440507 authored by alinamihaila's avatar alinamihaila

Add skip_validation attribute to metric definition

Use each instead of map
parent 5ebfde5b
......@@ -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,12 @@ module Gitlab
def method_missing(method, *args)
attributes[method] || super
end
def skip_validation?
return false if attributes[:skip_validation].blank?
attributes[:skip_validation]
end
end
end
end
......
......@@ -65,6 +65,12 @@ RSpec.describe Gitlab::Usage::MetricDefinition do
described_class.new(path, attributes).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
......
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