Commit 5dce47e8 authored by Piotr Skorupa's avatar Piotr Skorupa

Ignore contents of metrics with value schemas

parent 1f56f09a
{
"type": "object",
"required": ["duration", "failures"],
"required": ["duration_s", "failures"],
"properties": {
"duration": { "type": "number", "description": "The time it took to collect topology data" },
"duration_s": { "type": "number", "description": "The time it took to collect topology data" },
"failures": { "type": "array", "description": "The information about failed queries" },
"application_requests_per_hour": { "type": "number", "description": "The number of requests to the web application per hour" },
"nodes": {
......
......@@ -11,7 +11,6 @@ RSpec.describe 'Every metric definition' do
geo_node_usage
license_add_ons
testing_total_unique_counts
topology
user_auth_by_provider
).freeze
end
......@@ -19,7 +18,7 @@ RSpec.describe 'Every metric definition' do
let(:usage_ping_key_paths) do
parse_usage_ping_keys(usage_ping)
.flatten
.reject { |v| v =~ Regexp.union(ignored_usage_ping_key_patterns)}
.reject { |v| v =~ Regexp.union(ignored_usage_ping_key_patterns) }
.sort
end
......@@ -29,7 +28,6 @@ RSpec.describe 'Every metric definition' do
geo_node_usage
mock_ci
mock_monitoring
projects_with_enabled_alert_integrations_histogram
user_auth_by_provider
user_dast_scans
user_sast_scans
......@@ -38,22 +36,28 @@ RSpec.describe 'Every metric definition' do
user_secret_detection_scans
user_coverage_fuzzing_scans
user_api_fuzzing_scans
topology
).freeze
end
let(:metric_files_key_paths) do
Gitlab::Usage::MetricDefinition
.definitions
.reject { |k, v| v.status == 'removed' || v.key_path =~ Regexp.union(ignored_metric_files_key_patterns)}
.reject { |k, v| v.status == 'removed' || v.key_path =~ Regexp.union(ignored_metric_files_key_patterns) }
.keys
.sort
end
let(:metric_files_with_schema) do
Gitlab::Usage::MetricDefinition
.definitions
.select { |k, v| v.respond_to?(:value_json_schema) }
.keys
end
# Recursively traverse nested Hash of a generated Usage Ping to return an Array of key paths
# in the dotted format used in metric definition YAML files, e.g.: 'count.category.metric_name'
def parse_usage_ping_keys(object, key_path = [])
if object.is_a? Hash
if object.is_a?(Hash) && !object_with_schema?(key_path.join('.'))
object.each_with_object([]) do |(key, value), result|
result.append parse_usage_ping_keys(value, key_path + [key])
end
......@@ -62,6 +66,10 @@ RSpec.describe 'Every metric definition' do
end
end
def object_with_schema?(key_path)
metric_files_with_schema.include?(key_path)
end
before do
allow(Gitlab::UsageData).to receive_messages(count: -1, distinct_count: -1, estimate_batch_distinct_count: -1, sum: -1, alt_usage_data: -1)
allow(Gitlab::Geo).to receive(:enabled?).and_return(true)
......
......@@ -114,6 +114,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
......
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