Skip to content
代码片段 群组 项目
提交 8e22b5fc 编辑于 作者: Sarah Yasonik's avatar Sarah Yasonik 提交者: syasonik
浏览文件

Combine json-schemas for metrics into a single file

上级 d07b2044
No related branches found
No related tags found
无相关合并请求
...@@ -71,18 +71,21 @@ ...@@ -71,18 +71,21 @@
"type": [ "type": [
"string", "string",
"null" "null"
] ],
"format": "uri"
}, },
"removed_by_url": { "removed_by_url": {
"type": [ "type": [
"string", "string",
"null" "null"
] ],
"format": "uri"
}, },
"repair_issue_url": { "repair_issue_url": {
"type": [ "type": [
"string" "string"
] ],
"format": "uri"
}, },
"options": { "options": {
"type": "object" "type": "object"
...@@ -166,5 +169,19 @@ ...@@ -166,5 +169,19 @@
"value_json_schema": { "value_json_schema": {
"type": "string" "type": "string"
} }
} },
"allOf": [
{
"$ref": "internal_events.json"
},
{
"$ref": "redis_hll.json"
},
{
"$ref": "redis.json"
},
{
"$ref": "status.json"
}
]
} }
...@@ -6,7 +6,7 @@ module Tracking ...@@ -6,7 +6,7 @@ module Tracking
class EventDefinition class EventDefinition
EVENT_SCHEMA_PATH = Rails.root.join('config', 'events', 'schema.json') 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 :path
attr_reader :attributes attr_reader :attributes
......
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
module Gitlab module Gitlab
module Usage module Usage
class MetricDefinition 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 AVAILABLE_STATUSES = %w[active broken].to_set.freeze
VALID_SERVICE_PING_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? ...@@ -60,7 +61,7 @@ def has_json_schema?
end end
def validation_errors def validation_errors
errors.map do |error| SCHEMA.validate(attributes.deep_stringify_keys).map do |error|
<<~ERROR_MSG <<~ERROR_MSG
--------------- VALIDATION ERROR --------------- --------------- VALIDATION ERROR ---------------
Metric file: #{path} Metric file: #{path}
...@@ -116,12 +117,6 @@ def context_for(key_path) ...@@ -116,12 +117,6 @@ def context_for(key_path)
definitions[key_path]&.to_context definitions[key_path]&.to_context
end end
def schemers
@schemers ||= Dir[METRIC_SCHEMA_PATH].map do |path|
::JSONSchemer.schema(Pathname.new(path))
end
end
def dump_metrics_yaml def dump_metrics_yaml
@metrics_yaml ||= definitions.values.map(&:to_h).map(&:deep_stringify_keys).to_yaml @metrics_yaml ||= definitions.values.map(&:to_h).map(&:deep_stringify_keys).to_yaml
end end
...@@ -159,19 +154,6 @@ def load_all_from_path!(definitions, glob_path) ...@@ -159,19 +154,6 @@ def load_all_from_path!(definitions, glob_path)
private 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) def method_missing(method, *args)
attributes[method] || super attributes[method] || super
end end
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册