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
|
2021-10-27 15:23:28 +05:30
|
|
|
def uncached_data
|
|
|
|
super.with_indifferent_access.deep_merge(instrumentation_metrics_queries.with_indifferent_access)
|
|
|
|
end
|
|
|
|
|
|
|
|
def add_metric(metric, time_frame: 'none')
|
|
|
|
metric_class = "Gitlab::Usage::Metrics::Instrumentations::#{metric}".constantize
|
|
|
|
|
|
|
|
metric_class.new(time_frame: time_frame).instrumentation
|
|
|
|
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)
|
|
|
|
end
|
|
|
|
|
|
|
|
def minimum_id(model, column = nil)
|
|
|
|
end
|
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
def redis_usage_data(counter = nil, &block)
|
|
|
|
if block_given?
|
|
|
|
{ redis_usage_data_block: block.to_s }
|
|
|
|
elsif counter.present?
|
|
|
|
{ redis_usage_data_counter: counter }
|
|
|
|
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
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
def epics_deepest_relationship_level
|
|
|
|
{ epics_deepest_relationship_level: 0 }
|
2021-04-29 21:17:54 +05:30
|
|
|
end
|
2021-10-27 15:23:28 +05:30
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def instrumentation_metrics_queries
|
|
|
|
::Gitlab::Usage::Metric.all.map(&:with_instrumentation).reduce({}, :deep_merge)
|
|
|
|
end
|
2020-11-24 15:15:51 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|