debian-mirror-gitlab/lib/gitlab/usage_data_queries.rb

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

97 lines
3.2 KiB
Ruby
Raw Normal View History

2020-11-24 15:15:51 +05:30
# frozen_string_literal: true
module Gitlab
# This class is used by the `gitlab:usage_data:dump_sql` rake tasks to output SQL instead of running it.
# See https://gitlab.com/gitlab-org/gitlab/-/merge_requests/41091
class UsageDataQueries < UsageData
class << self
2022-07-16 23:28:13 +05:30
def with_duration
yield
end
2021-12-11 22:18:48 +05:30
def add_metric(metric, time_frame: 'none', options: {})
2021-10-27 15:23:28 +05:30
metric_class = "Gitlab::Usage::Metrics::Instrumentations::#{metric}".constantize
2021-12-11 22:18:48 +05:30
metric_class.new(time_frame: time_frame, options: options).instrumentation
2021-10-27 15:23:28 +05:30
end
2021-04-29 21:17:54 +05:30
def count(relation, column = nil, *args, **kwargs)
2021-09-04 01:27:46 +05:30
Gitlab::Usage::Metrics::Query.for(:count, relation, column)
2020-11-24 15:15:51 +05:30
end
2021-04-29 21:17:54 +05:30
def distinct_count(relation, column = nil, *args, **kwargs)
2021-09-04 01:27:46 +05:30
Gitlab::Usage::Metrics::Query.for(:distinct_count, relation, column)
2020-11-24 15:15:51 +05:30
end
2021-04-29 21:17:54 +05:30
def sum(relation, column, *args, **kwargs)
2021-09-04 01:27:46 +05:30
Gitlab::Usage::Metrics::Query.for(:sum, relation, column)
2020-11-24 15:15:51 +05:30
end
2021-06-08 01:23:25 +05:30
# rubocop: disable CodeReuse/ActiveRecord
def histogram(relation, column, buckets:, bucket_size: buckets.size)
2021-09-04 01:27:46 +05:30
Gitlab::Usage::Metrics::Query.for(:histogram, relation, column, buckets: buckets, bucket_size: bucket_size)
2021-06-08 01:23:25 +05:30
end
# rubocop: enable CodeReuse/ActiveRecord
2021-02-22 17:27:13 +05:30
# For estimated distinct count use exact query instead of hll
# buckets query, because it can't be used to obtain estimations without
# supplementary ruby code present in Gitlab::Database::PostgresHll::BatchDistinctCounter
2021-04-29 21:17:54 +05:30
def estimate_batch_distinct_count(relation, column = nil, *args, **kwargs)
2021-09-04 01:27:46 +05:30
Gitlab::Usage::Metrics::Query.for(:estimate_batch_distinct_count, relation, column)
2021-02-22 17:27:13 +05:30
end
2021-04-17 20:07:23 +05:30
def add(*args)
2021-09-04 01:27:46 +05:30
'SELECT ' + args.map { |arg| "(#{arg})" }.join(' + ')
2021-04-17 20:07:23 +05:30
end
2021-06-08 01:23:25 +05:30
def maximum_id(model, column = nil)
2022-05-07 20:08:51 +05:30
# no-op: shadowing super for performance reasons
2021-06-08 01:23:25 +05:30
end
def minimum_id(model, column = nil)
2022-05-07 20:08:51 +05:30
# no-op: shadowing super for performance reasons
end
def alt_usage_data(value = nil, fallback: FALLBACK, &block)
2022-08-27 11:52:29 +05:30
if block
2022-06-21 17:19:12 +05:30
{ alt_usage_data_block: "non-SQL usage data block" }
2022-05-07 20:08:51 +05:30
else
{ alt_usage_data_value: value }
end
2021-06-08 01:23:25 +05:30
end
2021-09-04 01:27:46 +05:30
def redis_usage_data(counter = nil, &block)
2022-08-27 11:52:29 +05:30
if block
2022-06-21 17:19:12 +05:30
{ redis_usage_data_block: "non-SQL usage data block" }
2021-09-04 01:27:46 +05:30
elsif counter.present?
2022-06-21 17:19:12 +05:30
{ redis_usage_data_counter: counter.to_s }
2021-09-04 01:27:46 +05:30
end
end
2021-09-30 23:02:18 +05:30
def jira_integration_data
2021-06-08 01:23:25 +05:30
{
projects_jira_server_active: 0,
projects_jira_cloud_active: 0
}
2021-04-29 21:17:54 +05:30
end
2022-06-21 17:19:12 +05:30
def topology_usage_data
{
duration_s: 0,
failures: []
}
end
2022-07-23 23:45:48 +05:30
# rubocop: disable CodeReuse/ActiveRecord
def sent_in_product_marketing_email_count(sent_emails, track, series)
count(Users::InProductMarketingEmail.where(track: track, series: series))
end
def clicked_in_product_marketing_email_count(clicked_emails, track, series)
count(Users::InProductMarketingEmail.where(track: track, series: series).where.not(cta_clicked_at: nil))
end
# rubocop: enable CodeReuse/ActiveRecord
2020-11-24 15:15:51 +05:30
end
end
end