Commit 38cca778 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch 'am-use-only-data-usage_data-method' into 'master'

Make Gitlab::UsageData.uncached_data private

See merge request gitlab-org/gitlab!79198
parents 2969055a fadc6629
...@@ -53,13 +53,6 @@ module EE ...@@ -53,13 +53,6 @@ module EE
class_methods do class_methods do
extend ::Gitlab::Utils::Override extend ::Gitlab::Utils::Override
override :uncached_data
def uncached_data
with_finished_at(:recording_ee_finished_at) do
super
end
end
override :features_usage_data override :features_usage_data
def features_usage_data def features_usage_data
super.merge(features_usage_data_ee) super.merge(features_usage_data_ee)
...@@ -401,6 +394,13 @@ module EE ...@@ -401,6 +394,13 @@ module EE
private private
override :uncached_data
def uncached_data
with_finished_at(:recording_ee_finished_at) do
super
end
end
# rubocop:disable CodeReuse/ActiveRecord # rubocop:disable CodeReuse/ActiveRecord
# rubocop: disable UsageData/LargeTable # rubocop: disable UsageData/LargeTable
def count_secure_scans(time_period) def count_secure_scans(time_period)
......
...@@ -5,7 +5,7 @@ require 'spec_helper' ...@@ -5,7 +5,7 @@ require 'spec_helper'
RSpec.describe 'Every metric definition' do RSpec.describe 'Every metric definition' do
include UsageDataHelpers include UsageDataHelpers
let(:usage_ping) { Gitlab::UsageData.uncached_data } let(:usage_ping) { Gitlab::UsageData.data(force_refresh: true) }
let(:ignored_usage_ping_key_patterns) do let(:ignored_usage_ping_key_patterns) do
%w( %w(
license_add_ons license_add_ons
......
...@@ -10,10 +10,10 @@ RSpec.describe Gitlab::UsageDataNonSqlMetrics do ...@@ -10,10 +10,10 @@ RSpec.describe Gitlab::UsageDataNonSqlMetrics do
stub_database_flavor_check stub_database_flavor_check
end end
describe '.uncached_data' do describe '.data' do
it 'does make instrumentations_class DB calls' do it 'does make instrumentations_class DB calls' do
recorder = ActiveRecord::QueryRecorder.new do recorder = ActiveRecord::QueryRecorder.new do
described_class.uncached_data described_class.data(force_refresh: true)
end end
expect(recorder.count).to eq(65) expect(recorder.count).to eq(65)
......
...@@ -801,7 +801,7 @@ RSpec.describe Gitlab::UsageData do ...@@ -801,7 +801,7 @@ RSpec.describe Gitlab::UsageData do
it 'clears memoized values' do it 'clears memoized values' do
allow(described_class).to receive(:clear_memoization) allow(described_class).to receive(:clear_memoization)
described_class.uncached_data described_class.data(force_refresh: true)
described_class::EE_MEMOIZED_VALUES.each do |key| described_class::EE_MEMOIZED_VALUES.each do |key|
expect(described_class).to have_received(:clear_memoization).with(key) expect(described_class).to have_received(:clear_memoization).with(key)
......
...@@ -18,7 +18,7 @@ module API ...@@ -18,7 +18,7 @@ module API
get 'non_sql_metrics' do get 'non_sql_metrics' do
Gitlab::QueryLimiting.disable!('https://gitlab.com/gitlab-org/gitlab/-/issues/325534') Gitlab::QueryLimiting.disable!('https://gitlab.com/gitlab-org/gitlab/-/issues/325534')
data = Gitlab::UsageDataNonSqlMetrics.uncached_data data = Gitlab::UsageDataNonSqlMetrics.data(force_refresh: true)
present data present data
end end
......
...@@ -18,7 +18,7 @@ module API ...@@ -18,7 +18,7 @@ module API
get 'queries' do get 'queries' do
Gitlab::QueryLimiting.disable!('https://gitlab.com/gitlab-org/gitlab/-/issues/325534') Gitlab::QueryLimiting.disable!('https://gitlab.com/gitlab-org/gitlab/-/issues/325534')
queries = Gitlab::UsageDataQueries.uncached_data queries = Gitlab::UsageDataQueries.data(force_refresh: true)
present queries present queries
end end
......
...@@ -47,14 +47,6 @@ module Gitlab ...@@ -47,14 +47,6 @@ module Gitlab
end end
end end
def uncached_data
clear_memoized
with_finished_at(:recording_ce_finished_at) do
usage_data_metrics
end
end
def to_json(force_refresh: false) def to_json(force_refresh: false)
data(force_refresh: force_refresh).to_json data(force_refresh: force_refresh).to_json
end end
...@@ -697,6 +689,14 @@ module Gitlab ...@@ -697,6 +689,14 @@ module Gitlab
private private
def uncached_data
clear_memoized
with_finished_at(:recording_ce_finished_at) do
usage_data_metrics
end
end
def stage_manage_events(time_period) def stage_manage_events(time_period)
if time_period.empty? if time_period.empty?
Gitlab::Utils::UsageData::FALLBACK Gitlab::Utils::UsageData::FALLBACK
......
...@@ -4,17 +4,17 @@ namespace :gitlab do ...@@ -4,17 +4,17 @@ namespace :gitlab do
namespace :usage_data do namespace :usage_data do
desc 'GitLab | UsageData | Generate raw SQLs for usage ping in YAML' desc 'GitLab | UsageData | Generate raw SQLs for usage ping in YAML'
task dump_sql_in_yaml: :environment do task dump_sql_in_yaml: :environment do
puts Gitlab::UsageDataQueries.uncached_data.to_yaml puts Gitlab::UsageDataQueries.data(force_refresh: true).to_yaml
end end
desc 'GitLab | UsageData | Generate raw SQLs for usage ping in JSON' desc 'GitLab | UsageData | Generate raw SQLs for usage ping in JSON'
task dump_sql_in_json: :environment do task dump_sql_in_json: :environment do
puts Gitlab::Json.pretty_generate(Gitlab::UsageDataQueries.uncached_data) puts Gitlab::Json.pretty_generate(Gitlab::UsageDataQueries.data(force_refresh: true))
end end
desc 'GitLab | UsageData | Generate usage ping in JSON' desc 'GitLab | UsageData | Generate usage ping in JSON'
task generate: :environment do task generate: :environment do
puts Gitlab::Json.pretty_generate(Gitlab::UsageData.uncached_data) puts Gitlab::Json.pretty_generate(Gitlab::UsageData.data(force: true))
end end
desc 'GitLab | UsageData | Generate usage ping and send it to Versions Application' desc 'GitLab | UsageData | Generate usage ping and send it to Versions Application'
......
...@@ -12,8 +12,8 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do ...@@ -12,8 +12,8 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
stub_database_flavor_check('Cloud SQL for PostgreSQL') stub_database_flavor_check('Cloud SQL for PostgreSQL')
end end
describe '.uncached_data' do describe '.data' do
subject { described_class.uncached_data } subject { described_class.data(force_refresh: true) }
it 'includes basic top and second level keys' do it 'includes basic top and second level keys' do
is_expected.to include(:counts) is_expected.to include(:counts)
......
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