Class: Gitlab::UsageDataQueries

Inherits:
UsageData show all
Defined in:
lib/gitlab/usage_data_queries.rb

Overview

This class is used by the `gitlab:usage_data:dump_sql` rake tasks to output SQL instead of running it. See gitlab.com/gitlab-org/gitlab/-/merge_requests/41091

Constant Summary

Constants inherited from UsageData

Gitlab::UsageData::CE_MEMOIZED_VALUES, Gitlab::UsageData::DEPRECATED_VALUE, Gitlab::UsageData::MAX_GENERATION_TIME_FOR_SAAS

Constants included from Gitlab::Usage::TimeFrame

Gitlab::Usage::TimeFrame::ALL_TIME_TIME_FRAME_NAME, Gitlab::Usage::TimeFrame::SEVEN_DAYS_TIME_FRAME_NAME, Gitlab::Usage::TimeFrame::TWENTY_EIGHT_DAYS_TIME_FRAME_NAME

Constants included from Gitlab::Utils::UsageData

Gitlab::Utils::UsageData::DISTRIBUTED_HLL_FALLBACK, Gitlab::Utils::UsageData::FALLBACK, Gitlab::Utils::UsageData::HISTOGRAM_FALLBACK, Gitlab::Utils::UsageData::MAX_BUCKET_SIZE

Class Method Summary collapse

Methods inherited from UsageData

action_monthly_active_users, aggregated_metrics_data, analytics_unique_visits_data, compliance_unique_visits_data, components_usage_data, container_expiration_policies_usage, data, features_usage_data, features_usage_data_ce, grafana_embed_usage_data, installation_type, jira_import_usage, jira_usage, license_usage_data, merge_requests_users, object_store_config, object_store_usage_data, operating_system, recorded_at, redis_hll_counters, runners_usage, search_unique_visits_data, services_usage, successful_deployments_with_cluster, system_usage_data, system_usage_data_license, system_usage_data_monthly, system_usage_data_settings, system_usage_data_weekly, usage_activity_by_stage, usage_activity_by_stage_configure, usage_activity_by_stage_create, usage_activity_by_stage_enablement, usage_activity_by_stage_manage, usage_activity_by_stage_monitor, usage_activity_by_stage_package, usage_activity_by_stage_plan, usage_activity_by_stage_release, usage_activity_by_stage_secure, usage_activity_by_stage_verify, usage_counters, usage_data_counters, user_preferences_usage

Methods included from Gitlab::Usage::TimeFrame

#monthly_time_range, #monthly_time_range_db_params, #weekly_time_range

Methods included from Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Methods included from Gitlab::Utils::UsageData

#add, #add_metric, #alt_usage_data, #count, #distinct_count, #epics_deepest_relationship_level, #estimate_batch_distinct_count, #histogram, #jira_integration_data, #maximum_id, #measure_duration, #minimum_id, #redis_usage_data, #sum, #track_usage_event, #with_duration, #with_finished_at, #with_prometheus_client

Class Method Details

.add(*args) ⇒ Object


43
44
45
# File 'lib/gitlab/usage_data_queries.rb', line 43

def add(*args)
  'SELECT ' + args.map { |arg| "(#{arg})" }.join(' + ')
end

.add_metric(metric, time_frame: 'none', options: {}) ⇒ Object


12
13
14
15
16
# File 'lib/gitlab/usage_data_queries.rb', line 12

def add_metric(metric, time_frame: 'none', options: {})
  metric_class = "Gitlab::Usage::Metrics::Instrumentations::#{metric}".constantize

  metric_class.new(time_frame: time_frame, options: options).instrumentation
end

.alt_usage_data(value = nil, fallback: FALLBACK, &block) ⇒ Object


55
56
57
58
59
60
61
# File 'lib/gitlab/usage_data_queries.rb', line 55

def alt_usage_data(value = nil, fallback: FALLBACK, &block)
  if block_given?
    { alt_usage_data_block: "non-SQL usage data block" }
  else
    { alt_usage_data_value: value }
  end
end

.count(relation, column = nil, *args, **kwargs) ⇒ Object


18
19
20
# File 'lib/gitlab/usage_data_queries.rb', line 18

def count(relation, column = nil, *args, **kwargs)
  Gitlab::Usage::Metrics::Query.for(:count, relation, column)
end

.distinct_count(relation, column = nil, *args, **kwargs) ⇒ Object


22
23
24
# File 'lib/gitlab/usage_data_queries.rb', line 22

def distinct_count(relation, column = nil, *args, **kwargs)
  Gitlab::Usage::Metrics::Query.for(:distinct_count, relation, column)
end

.epics_deepest_relationship_levelObject


78
79
80
# File 'lib/gitlab/usage_data_queries.rb', line 78

def epics_deepest_relationship_level
  { epics_deepest_relationship_level: 0 }
end

.estimate_batch_distinct_count(relation, column = nil, *args, **kwargs) ⇒ Object

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


39
40
41
# File 'lib/gitlab/usage_data_queries.rb', line 39

def estimate_batch_distinct_count(relation, column = nil, *args, **kwargs)
  Gitlab::Usage::Metrics::Query.for(:estimate_batch_distinct_count, relation, column)
end

.histogram(relation, column, buckets:, bucket_size: buckets.size) ⇒ Object

rubocop: disable CodeReuse/ActiveRecord


31
32
33
# File 'lib/gitlab/usage_data_queries.rb', line 31

def histogram(relation, column, buckets:, bucket_size: buckets.size)
  Gitlab::Usage::Metrics::Query.for(:histogram, relation, column, buckets: buckets, bucket_size: bucket_size)
end

.jira_integration_dataObject


71
72
73
74
75
76
# File 'lib/gitlab/usage_data_queries.rb', line 71

def jira_integration_data
  {
    projects_jira_server_active: 0,
    projects_jira_cloud_active: 0
  }
end

.maximum_id(model, column = nil) ⇒ Object


47
48
49
# File 'lib/gitlab/usage_data_queries.rb', line 47

def maximum_id(model, column = nil)
  # no-op: shadowing super for performance reasons
end

.minimum_id(model, column = nil) ⇒ Object


51
52
53
# File 'lib/gitlab/usage_data_queries.rb', line 51

def minimum_id(model, column = nil)
  # no-op: shadowing super for performance reasons
end

.redis_usage_data(counter = nil, &block) ⇒ Object


63
64
65
66
67
68
69
# File 'lib/gitlab/usage_data_queries.rb', line 63

def redis_usage_data(counter = nil, &block)
  if block_given?
    { redis_usage_data_block: "non-SQL usage data block" }
  elsif counter.present?
    { redis_usage_data_counter: counter.to_s }
  end
end

.sum(relation, column, *args, **kwargs) ⇒ Object


26
27
28
# File 'lib/gitlab/usage_data_queries.rb', line 26

def sum(relation, column, *args, **kwargs)
  Gitlab::Usage::Metrics::Query.for(:sum, relation, column)
end

.topology_usage_dataObject


82
83
84
85
86
87
# File 'lib/gitlab/usage_data_queries.rb', line 82

def topology_usage_data
  {
    duration_s: 0,
    failures: []
  }
end

.with_durationObject


8
9
10
# File 'lib/gitlab/usage_data_queries.rb', line 8

def with_duration
  yield
end