Commit 81c3921e authored by Luis Mejia's avatar Luis Mejia Committed by Alper Akgun

Exclude removed metrics from with_instrumentation_class method

parent 77299e52
......@@ -26,7 +26,7 @@ RSpec.describe Gitlab::UsageDataMetrics do
let(:metric_files_key_paths) do
Gitlab::Usage::MetricDefinition
.definitions
.select { |k, v| v.attributes[:data_source] == 'redis_hll' && v.key_path.starts_with?('redis_hll_counters') }
.select { |k, v| v.attributes[:data_source] == 'redis_hll' && v.key_path.starts_with?('redis_hll_counters') && v.available? }
.keys
.sort
end
......
......@@ -6,6 +6,7 @@ module Gitlab
METRIC_SCHEMA_PATH = Rails.root.join('config', 'metrics', 'schema.json')
BASE_REPO_PATH = 'https://gitlab.com/gitlab-org/gitlab/-/blob/master'
SKIP_VALIDATION_STATUSES = %w[deprecated removed].to_set.freeze
AVAILABLE_STATUSES = %w[active data_available implemented deprecated].freeze
InvalidError = Class.new(RuntimeError)
......@@ -59,6 +60,10 @@ module Gitlab
attributes[:data_category]&.downcase!
end
def available?
AVAILABLE_STATUSES.include?(attributes[:status])
end
alias_method :to_dictionary, :to_h
class << self
......@@ -76,7 +81,7 @@ module Gitlab
end
def with_instrumentation_class
all.select { |definition| definition.attributes[:instrumentation_class].present? }
all.select { |definition| definition.attributes[:instrumentation_class].present? && definition.available? }
end
def schemer
......
......@@ -49,6 +49,37 @@ RSpec.describe Gitlab::Usage::MetricDefinition do
expect { described_class.definitions }.not_to raise_error
end
describe '#with_instrumentation_class' do
let(:metric_status) { 'active' }
let(:all_definitions) do
metrics_definitions = [
{ key_path: 'metric1', instrumentation_class: 'RedisHLLMetric', status: 'data_available' },
{ key_path: 'metric2', instrumentation_class: 'RedisHLLMetric', status: 'implemented' },
{ key_path: 'metric3', instrumentation_class: 'RedisHLLMetric', status: 'deprecated' },
{ key_path: 'metric4', instrumentation_class: 'RedisHLLMetric', status: metric_status },
{ key_path: 'metric5', status: 'active' },
{ key_path: 'metric_missing_status' }
]
metrics_definitions.map { |definition| described_class.new(definition[:key_path], definition.symbolize_keys) }
end
before do
allow(described_class).to receive(:all).and_return(all_definitions)
end
it 'includes definitions with instrumentation_class' do
expect(described_class.with_instrumentation_class.count).to eq(4)
end
context 'with removed metric' do
let(:metric_status) { 'removed' }
it 'excludes removed definitions' do
expect(described_class.with_instrumentation_class.count).to eq(3)
end
end
end
describe '#key' do
subject { definition.key }
......
......@@ -46,7 +46,7 @@ RSpec.describe Gitlab::UsageDataMetrics do
let(:metric_files_key_paths) do
Gitlab::Usage::MetricDefinition
.definitions
.select { |k, v| v.attributes[:data_source] == 'redis_hll' && v.key_path.starts_with?('redis_hll_counters') }
.select { |k, v| v.attributes[:data_source] == 'redis_hll' && v.key_path.starts_with?('redis_hll_counters') && v.available? }
.keys
.sort
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