debian-mirror-gitlab/spec/lib/gitlab/usage_data_metrics_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

89 lines
3 KiB
Ruby
Raw Permalink Normal View History

2021-06-08 01:23:25 +05:30
# frozen_string_literal: true
require 'spec_helper'
2023-04-23 21:23:45 +05:30
RSpec.describe Gitlab::UsageDataMetrics, :with_license, feature_category: :service_ping do
2021-06-08 01:23:25 +05:30
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-12-11 22:18:48 +05:30
allow_next_instance_of(Gitlab::Database::BatchCounter) do |batch_counter|
allow(batch_counter).to receive(:transaction_open?).and_return(false)
end
2022-10-11 01:57:18 +05:30
allow_next_instance_of(Gitlab::Database::BatchAverageCounter) do |instance|
allow(instance).to receive(:transaction_open?).and_return(false)
end
2021-06-08 01:23:25 +05:30
end
2021-10-27 15:23:28 +05:30
context 'with instrumentation_class' do
2021-06-08 01:23:25 +05:30
it 'includes top level keys' do
expect(subject).to include(:uuid)
expect(subject).to include(:hostname)
end
2022-07-23 23:45:48 +05:30
it 'includes counts keys', :aggregate_failures do
2021-06-08 01:23:25 +05:30
expect(subject[:counts]).to include(:boards)
expect(subject[:counts]).to include(:issues)
2022-11-25 23:54:43 +05:30
expect(subject[:counts]).to include(:gitlab_for_jira_app_direct_installations)
expect(subject[:counts]).to include(:gitlab_for_jira_app_proxy_installations)
2021-06-08 01:23:25 +05:30
end
it 'includes usage_activity_by_stage keys' do
expect(subject[:usage_activity_by_stage][:plan]).to include(:issues)
end
2022-10-11 01:57:18 +05:30
it 'includes usage_activity_by_stage metrics' do
expect(subject[:usage_activity_by_stage][:manage]).to include(:count_user_auth)
end
2021-06-08 01:23:25 +05:30
it 'includes usage_activity_by_stage_monthly keys' do
expect(subject[:usage_activity_by_stage_monthly][:plan]).to include(:issues)
end
2021-10-27 15:23:28 +05:30
it 'includes settings keys' do
expect(subject[:settings]).to include(:collected_data_categories)
end
describe 'Redis_HLL_counters' do
let(:metric_files_key_paths) do
Gitlab::Usage::MetricDefinition
.definitions
2021-11-18 22:05:49 +05:30
.select { |k, v| v.attributes[:data_source] == 'redis_hll' && v.key_path.starts_with?('redis_hll_counters') && v.available? }
2021-10-27 15:23:28 +05:30
.keys
.sort
end
# Recursively traverse nested Hash of a generated Service 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_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
let(:service_ping_key_paths) do
parse_service_ping_keys(subject)
.flatten
.select { |k| k.starts_with?('redis_hll_counters') }
.sort
end
it 'is included in the Service Ping hash structure' do
expect(metric_files_key_paths).to match_array(service_ping_key_paths)
end
end
2021-06-08 01:23:25 +05:30
end
end
end