diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-19 12:08:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-19 12:08:42 +0300 |
commit | b76ae638462ab0f673e5915986070518dd3f9ad3 (patch) | |
tree | bdab0533383b52873be0ec0eb4d3c66598ff8b91 /lib/gitlab/usage/metric_definition.rb | |
parent | 434373eabe7b4be9593d18a585fb763f1e5f1a6f (diff) |
Add latest changes from gitlab-org/gitlab@14-2-stable-eev14.2.0-rc42
Diffstat (limited to 'lib/gitlab/usage/metric_definition.rb')
-rw-r--r-- | lib/gitlab/usage/metric_definition.rb | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/lib/gitlab/usage/metric_definition.rb b/lib/gitlab/usage/metric_definition.rb index ccd2c69e2e7..db0cb4c6326 100644 --- a/lib/gitlab/usage/metric_definition.rb +++ b/lib/gitlab/usage/metric_definition.rb @@ -7,6 +7,8 @@ module Gitlab BASE_REPO_PATH = 'https://gitlab.com/gitlab-org/gitlab/-/blob/master' SKIP_VALIDATION_STATUSES = %w[deprecated removed].to_set.freeze + InvalidError = Class.new(RuntimeError) + attr_reader :path attr_reader :attributes @@ -48,11 +50,15 @@ module Gitlab Metric file: #{path} ERROR_MSG - Gitlab::ErrorTracking.track_and_raise_for_dev_exception(Gitlab::Usage::Metric::InvalidMetricError.new(error_message)) + Gitlab::ErrorTracking.track_and_raise_for_dev_exception(InvalidError.new(error_message)) end end end + def category_to_lowercase + attributes[:data_category]&.downcase! + end + alias_method :to_dictionary, :to_h class << self @@ -69,6 +75,10 @@ module Gitlab @all ||= definitions.map { |_key_path, definition| definition } end + def with_instrumentation_class + all.select { |definition| definition.attributes[:instrumentation_class].present? } + end + def schemer @schemer ||= ::JSONSchemer.schema(Pathname.new(METRIC_SCHEMA_PATH)) end @@ -90,9 +100,9 @@ module Gitlab definition = YAML.safe_load(definition) definition.deep_symbolize_keys! - self.new(path, definition).tap(&:validate!) + self.new(path, definition).tap(&:validate!).tap(&:category_to_lowercase) rescue StandardError => e - Gitlab::ErrorTracking.track_and_raise_for_dev_exception(Gitlab::Usage::Metric::InvalidMetricError.new(e.message)) + Gitlab::ErrorTracking.track_and_raise_for_dev_exception(InvalidError.new(e.message)) end def load_all_from_path!(definitions, glob_path) @@ -100,7 +110,7 @@ module Gitlab definition = load_from_file(path) if previous = definitions[definition.key] - Gitlab::ErrorTracking.track_and_raise_for_dev_exception(Gitlab::Usage::Metric::InvalidMetricError.new("Metric '#{definition.key}' is already defined in '#{previous.path}'")) + Gitlab::ErrorTracking.track_and_raise_for_dev_exception(InvalidError.new("Metric '#{definition.key}' is already defined in '#{previous.path}'")) end definitions[definition.key] = definition @@ -114,6 +124,10 @@ module Gitlab attributes[method] || super end + def respond_to_missing?(method, *args) + attributes[method].present? || super + end + def skip_validation? !!attributes[:skip_validation] || @skip_validation || SKIP_VALIDATION_STATUSES.include?(attributes[:status]) end |