2021-05-07 12:10:27 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe Gitlab::UsageDataMetrics do
|
|
|
|
describe '.uncached_data' do
|
|
|
|
subject { described_class.uncached_data }
|
|
|
|
|
|
|
|
around do |example|
|
|
|
|
described_class.instance_variable_set(:@definitions, nil)
|
|
|
|
example.run
|
|
|
|
described_class.instance_variable_set(:@definitions, nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
2021-11-15 15:10:57 +00:00
|
|
|
allow_next_instance_of(Gitlab::Database::BatchCounter) do |batch_counter|
|
|
|
|
allow(batch_counter).to receive(:transaction_open?).and_return(false)
|
|
|
|
end
|
2021-05-07 12:10:27 +00:00
|
|
|
end
|
|
|
|
|
2021-07-28 00:10:24 +00:00
|
|
|
context 'with instrumentation_class' do
|
2021-05-07 12:10:27 +00:00
|
|
|
it 'includes top level keys' do
|
|
|
|
expect(subject).to include(:uuid)
|
2021-05-10 15:10:24 +00:00
|
|
|
expect(subject).to include(:hostname)
|
2021-05-07 12:10:27 +00:00
|
|
|
end
|
2021-05-07 18:10:21 +00:00
|
|
|
|
2022-06-15 15:09:20 +00:00
|
|
|
it 'includes counts keys', :aggregate_failures do
|
2021-05-07 18:10:21 +00:00
|
|
|
expect(subject[:counts]).to include(:boards)
|
2021-08-13 12:10:58 +00:00
|
|
|
expect(subject[:counts]).to include(:issues)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'includes usage_activity_by_stage keys' do
|
|
|
|
expect(subject[:usage_activity_by_stage][:plan]).to include(:issues)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'includes usage_activity_by_stage_monthly keys' do
|
|
|
|
expect(subject[:usage_activity_by_stage_monthly][:plan]).to include(:issues)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'includes settings keys' do
|
|
|
|
expect(subject[:settings]).to include(:collected_data_categories)
|
|
|
|
end
|
2021-08-10 18:10:13 +00:00
|
|
|
|
2021-08-13 12:10:58 +00:00
|
|
|
describe 'Redis_HLL_counters' do
|
2021-08-12 18:10:45 +00:00
|
|
|
let(:metric_files_key_paths) do
|
|
|
|
Gitlab::Usage::MetricDefinition
|
|
|
|
.definitions
|
2021-10-05 09:12:23 +00:00
|
|
|
.select { |k, v| v.attributes[:data_source] == 'redis_hll' && v.key_path.starts_with?('redis_hll_counters') && v.available? }
|
2021-08-12 18:10:45 +00:00
|
|
|
.keys
|
|
|
|
.sort
|
|
|
|
end
|
2021-08-10 09:10:08 +00:00
|
|
|
|
2021-08-13 12:10:58 +00:00
|
|
|
# Recursively traverse nested Hash of a generated Service Ping to return an Array of key paths
|
2021-08-12 18:10:45 +00:00
|
|
|
# in the dotted format used in metric definition YAML files, e.g.: 'count.category.metric_name'
|
|
|
|
def parse_service_ping_keys(object, key_path = [])
|
|
|
|
if object.is_a?(Hash)
|
|
|
|
object.each_with_object([]) do |(key, value), result|
|
|
|
|
result.append parse_service_ping_keys(value, key_path + [key])
|
|
|
|
end
|
|
|
|
else
|
|
|
|
key_path.join('.')
|
|
|
|
end
|
|
|
|
end
|
2021-08-10 09:10:08 +00:00
|
|
|
|
2021-08-13 12:10:58 +00:00
|
|
|
let(:service_ping_key_paths) do
|
2021-08-12 18:10:45 +00:00
|
|
|
parse_service_ping_keys(subject)
|
|
|
|
.flatten
|
|
|
|
.select { |k| k.starts_with?('redis_hll_counters') }
|
|
|
|
.sort
|
|
|
|
end
|
2021-08-10 09:10:08 +00:00
|
|
|
|
2021-08-13 12:10:58 +00:00
|
|
|
it 'is included in the Service Ping hash structure' do
|
|
|
|
expect(metric_files_key_paths).to match_array(service_ping_key_paths)
|
2021-08-12 18:10:45 +00:00
|
|
|
end
|
2021-08-09 18:08:33 +00:00
|
|
|
end
|
2021-05-07 12:10:27 +00:00
|
|
|
end
|
|
|
|
end
|
2021-10-25 18:12:16 +00:00
|
|
|
|
|
|
|
describe '.suggested_names' do
|
|
|
|
subject { described_class.suggested_names }
|
|
|
|
|
|
|
|
let(:suggested_names) do
|
|
|
|
::Gitlab::Usage::Metric.all.map(&:with_suggested_name).reduce({}, :deep_merge)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'includes Service Ping suggested names' do
|
|
|
|
expect(subject).to match_array(suggested_names)
|
|
|
|
end
|
|
|
|
end
|
2021-05-07 12:10:27 +00:00
|
|
|
end
|