Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/usage/service_ping/payload_keys_processor_spec.rb')
-rw-r--r--spec/lib/gitlab/usage/service_ping/payload_keys_processor_spec.rb56
1 files changed, 56 insertions, 0 deletions
diff --git a/spec/lib/gitlab/usage/service_ping/payload_keys_processor_spec.rb b/spec/lib/gitlab/usage/service_ping/payload_keys_processor_spec.rb
new file mode 100644
index 00000000000..dd4349b99df
--- /dev/null
+++ b/spec/lib/gitlab/usage/service_ping/payload_keys_processor_spec.rb
@@ -0,0 +1,56 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::Usage::ServicePing::PayloadKeysProcessor do
+ context 'with an object metric' do
+ let(:payload) { { counts: { issues: 1, boards: 1 }, topology: { duration_d: 100 }, redis_hll_counters: { search: { i_search_total_monthly: 1 } } } }
+
+ it 'returns the payload keys that have a metric definition' do
+ expect(described_class.new(payload).key_paths).to match_array(['counts.issues', 'counts.boards', 'topology', 'redis_hll_counters.search.i_search_total_monthly'])
+ end
+ end
+
+ context 'with a missing metric definition' do
+ let(:payload) { { counts: { issues: 1, boards: 1 }, missing_definition: 1, topology: { duration_d: 100 } } }
+
+ it 'returns the payload keys that have a metric definition' do
+ expect(described_class.new(payload).key_paths).to match_array(['counts.issues', 'counts.boards', 'topology'])
+ end
+ end
+
+ context 'with array metric' do
+ let(:payload) { { counts: { issues: 1, boards: 1 }, settings: { collected_data_categories: ['standard'] }, topology: { duration_d: 100 } } }
+
+ it 'returns the payload keys that have a metric definition' do
+ expect(described_class.new(payload).key_paths).to match_array(['counts.issues', 'counts.boards', 'topology', 'settings.collected_data_categories'])
+ end
+ end
+
+ context 'missing_instrumented_metrics_key_paths' do
+ let(:payload) do
+ {
+ counts: { issues: 1, boards: 1 },
+ topology: { duration_d: 100 },
+ redis_hll_counters: { search: { i_search_total_monthly: 1 } }
+ }
+ end
+
+ let(:metrics_definitions) do
+ [
+ instance_double(::Gitlab::Usage::MetricDefinition, key: 'counts.issues'),
+ instance_double(::Gitlab::Usage::MetricDefinition, key: 'topology'),
+ instance_double(::Gitlab::Usage::MetricDefinition, key: 'redis_hll_counters.search.i_search_total_monthly'),
+ instance_double(::Gitlab::Usage::MetricDefinition, key: 'settings.collected_data_categories')
+ ]
+ end
+
+ before do
+ allow(::Gitlab::Usage::MetricDefinition).to receive(:with_instrumentation_class).and_return(metrics_definitions)
+ end
+
+ it 'returns the missing keys' do
+ expect(described_class.new(payload).missing_instrumented_metrics_key_paths).to match_array(['settings.collected_data_categories'])
+ end
+ end
+end