diff --git a/config/metrics/schema/base.json b/config/metrics/schema/base.json index 5f5715666512b12687454a0bdf96f6005f3d82fe..0d16a55c9fbfe4ce1c41f0d8454913cc7425136b 100644 --- a/config/metrics/schema/base.json +++ b/config/metrics/schema/base.json @@ -71,18 +71,21 @@ "type": [ "string", "null" - ] + ], + "format": "uri" }, "removed_by_url": { "type": [ "string", "null" - ] + ], + "format": "uri" }, "repair_issue_url": { "type": [ "string" - ] + ], + "format": "uri" }, "options": { "type": "object" @@ -166,5 +169,19 @@ "value_json_schema": { "type": "string" } - } + }, + "allOf": [ + { + "$ref": "internal_events.json" + }, + { + "$ref": "redis_hll.json" + }, + { + "$ref": "redis.json" + }, + { + "$ref": "status.json" + } + ] } diff --git a/lib/gitlab/tracking/event_definition.rb b/lib/gitlab/tracking/event_definition.rb index ce8263e824ba5836021c8eba213641753818d096..8159df09e78ff03708a77f54ad52071cb1eb137e 100644 --- a/lib/gitlab/tracking/event_definition.rb +++ b/lib/gitlab/tracking/event_definition.rb @@ -6,7 +6,7 @@ module Tracking class EventDefinition EVENT_SCHEMA_PATH = Rails.root.join('config', 'events', 'schema.json') - SCHEMA = ::JSONSchemer.schema(Pathname.new(EVENT_SCHEMA_PATH)) + SCHEMA = ::JSONSchemer.schema(EVENT_SCHEMA_PATH) attr_reader :path attr_reader :attributes diff --git a/lib/gitlab/usage/metric_definition.rb b/lib/gitlab/usage/metric_definition.rb index 71d3680e67e987911bce4e552ba7ce75fdbcce43..80d0e17744d155f157c813a92e65fca488ab3789 100644 --- a/lib/gitlab/usage/metric_definition.rb +++ b/lib/gitlab/usage/metric_definition.rb @@ -3,7 +3,8 @@ module Gitlab module Usage class MetricDefinition - METRIC_SCHEMA_PATH = Rails.root.join('config', 'metrics', 'schema', '**', '*.json') + METRIC_SCHEMA_PATH = Rails.root.join('config', 'metrics', 'schema', 'base.json') + SCHEMA = ::JSONSchemer.schema(METRIC_SCHEMA_PATH) AVAILABLE_STATUSES = %w[active broken].to_set.freeze VALID_SERVICE_PING_STATUSES = %w[active broken].to_set.freeze @@ -60,7 +61,7 @@ def has_json_schema? end def validation_errors - errors.map do |error| + SCHEMA.validate(attributes.deep_stringify_keys).map do |error| <<~ERROR_MSG --------------- VALIDATION ERROR --------------- Metric file: #{path} @@ -116,12 +117,6 @@ def context_for(key_path) definitions[key_path]&.to_context end - def schemers - @schemers ||= Dir[METRIC_SCHEMA_PATH].map do |path| - ::JSONSchemer.schema(Pathname.new(path)) - end - end - def dump_metrics_yaml @metrics_yaml ||= definitions.values.map(&:to_h).map(&:deep_stringify_keys).to_yaml end @@ -159,19 +154,6 @@ def load_all_from_path!(definitions, glob_path) private - def errors - result = [] - - self.class.schemers.each do |schemer| - # schemer.validate returns an Enumerator object - schemer.validate(attributes.deep_stringify_keys).each do |error| - result << error - end - end - - result - end - def method_missing(method, *args) attributes[method] || super end