Commit 45ce9949 authored by Mikołaj Wawrzyniak's avatar Mikołaj Wawrzyniak Committed by Bob Van Landuyt

Skip ServicePing metrics conditionaly included

There is no robus generic mechanism to conditionally include metrics
computed from instrumentation classes. Untill it is delivered
in order to avoid failing whole ServicePing process, skip such
metrics when adding metrics from instrumntation classes
parent 6fd529f6
# frozen_string_literal: true
module EE
module Gitlab
module Usage
module ServicePing
module PayloadKeysProcessor
extend ActiveSupport::Concern
extend ::Gitlab::Utils::Override
# TODO: Provide more generic and robust conditional availability method https://gitlab.com/gitlab-org/gitlab/-/issues/352875
METRICS_WITH_CONDITIONAL_AVAILABILITY = %w[
license_md5
license_id
historical_max_users
licensee
license_user_count
license_billable_users
license_starts_at
license_expires_at
license_plan
license_add_ons
license_trial
license_subscription_id
].freeze
override :missing_instrumented_metrics_key_paths
def missing_instrumented_metrics_key_paths
@missing_key_paths ||= super - METRICS_WITH_CONDITIONAL_AVAILABILITY
end
end
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::Usage::ServicePing::PayloadKeysProcessor do
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'),
instance_double(::Gitlab::Usage::MetricDefinition, key: 'license_md5'),
instance_double(::Gitlab::Usage::MetricDefinition, key: 'license_id'),
instance_double(::Gitlab::Usage::MetricDefinition, key: 'historical_max_users'),
instance_double(::Gitlab::Usage::MetricDefinition, key: 'licensee'),
instance_double(::Gitlab::Usage::MetricDefinition, key: 'license_user_count'),
instance_double(::Gitlab::Usage::MetricDefinition, key: 'license_billable_users'),
instance_double(::Gitlab::Usage::MetricDefinition, key: 'license_starts_at'),
instance_double(::Gitlab::Usage::MetricDefinition, key: 'license_expires_at'),
instance_double(::Gitlab::Usage::MetricDefinition, key: 'license_plan'),
instance_double(::Gitlab::Usage::MetricDefinition, key: 'license_add_ons'),
instance_double(::Gitlab::Usage::MetricDefinition, key: 'license_trial'),
instance_double(::Gitlab::Usage::MetricDefinition, key: 'license_subscription_id')
]
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
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::Usage::ServicePingReport, :use_clean_rails_memory_store_caching do
include UsageDataHelpers
let(:usage_data) { { uuid: "1111", counts: { issue: 0 } } }
context 'when feature merge_service_ping_instrumented_metrics enabled' do
context 'for conditional metrics inclusion' do
before do
stub_feature_flags(merge_service_ping_instrumented_metrics: true)
stub_usage_data_connections
stub_object_store_settings
stub_prometheus_queries
memoized_constants = Gitlab::UsageData::CE_MEMOIZED_VALUES
memoized_constants += Gitlab::UsageData::EE_MEMOIZED_VALUES if defined? Gitlab::UsageData::EE_MEMOIZED_VALUES
memoized_constants.each { |v| Gitlab::UsageData.clear_memoization(v) }
stub_database_flavor_check('Cloud SQL for PostgreSQL')
allow(License).to receive(:current)
end
it 'does not raise errors' do
expect { described_class.for(output: :all_metrics_values) }.not_to raise_error
end
end
end
end
......@@ -17,7 +17,7 @@ module Gitlab
end
def missing_instrumented_metrics_key_paths
@missing_key_paths ||= metrics_with_instrumentation.map(&:key_path) - key_paths
@missing_key_paths ||= metrics_with_instrumentation.map(&:key) - key_paths
end
private
......@@ -50,3 +50,5 @@ module Gitlab
end
end
end
Gitlab::Usage::ServicePing::PayloadKeysProcessor.prepend_mod_with('Gitlab::Usage::ServicePing::PayloadKeysProcessor')
......@@ -38,10 +38,10 @@ RSpec.describe Gitlab::Usage::ServicePing::PayloadKeysProcessor do
let(:metrics_definitions) do
[
double(:issues, key_path: 'counts.issues'),
double(:topology, key_path: 'topology'),
double(:i_search_total_monthly, key_path: 'redis_hll_counters.search.i_search_total_monthly'),
double(:collected_data_categories, key_path: 'settings.collected_data_categories')
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
......
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