Class: Gitlab::Analytics::CycleAnalytics::StageEvents::StageEvent

Inherits:
Object
  • Object
show all
Extended by:
Utils::Override
Includes:
CycleAnalytics::MetricsTables
Defined in:
lib/gitlab/analytics/cycle_analytics/stage_events/stage_event.rb

Overview

Base class for expressing an event that can be used for a stage.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utils::Override

extended, extensions, included, method_added, override, prepended, queue_verification, verify!

Methods included from CycleAnalytics::MetricsTables

#build_table, #issue_metrics_table, #issue_table, #mr_closing_issues_table, #mr_diff_commits_table, #mr_diff_table, #mr_metrics_table, #mr_table, #projects_table, #routes_table, #user_table

Constructor Details

#initialize(params) ⇒ StageEvent

Returns a new instance of StageEvent.


14
15
16
# File 'lib/gitlab/analytics/cycle_analytics/stage_events/stage_event.rb', line 14

def initialize(params)
  @params = params
end

Class Method Details

.identifierObject

Raises:

  • (NotImplementedError)

26
27
28
# File 'lib/gitlab/analytics/cycle_analytics/stage_events/stage_event.rb', line 26

def self.identifier
  raise NotImplementedError
end

.label_based?Boolean

Returns:

  • (Boolean)

68
69
70
# File 'lib/gitlab/analytics/cycle_analytics/stage_events/stage_event.rb', line 68

def self.label_based?
  false
end

.nameObject

Raises:

  • (NotImplementedError)

18
19
20
# File 'lib/gitlab/analytics/cycle_analytics/stage_events/stage_event.rb', line 18

def self.name
  raise NotImplementedError
end

Instance Method Details

#apply_negated_query_customization(query) ⇒ Object

rubocop: disable CodeReuse/ActiveRecord


59
60
61
# File 'lib/gitlab/analytics/cycle_analytics/stage_events/stage_event.rb', line 59

def apply_negated_query_customization(query)
  query.where(timestamp_projection.eq(nil))
end

#apply_query_customization(query) ⇒ Object

Optionally a StageEvent may apply additional filtering or join other tables on the base query.


54
55
56
# File 'lib/gitlab/analytics/cycle_analytics/stage_events/stage_event.rb', line 54

def apply_query_customization(query)
  query
end

#column_listObject

List of columns that are referenced in the `timestamp_projection` expression Example timestamp projection: COALESCE(issue_metrics.created_at, issue_metrics.updated_at) Expected column list: issue_metrics.created_at, issue_metrics.updated_at

Raises:

  • (NotImplementedError)

49
50
51
# File 'lib/gitlab/analytics/cycle_analytics/stage_events/stage_event.rb', line 49

def column_list
  raise NotImplementedError
end

#hash_codeObject


34
35
36
# File 'lib/gitlab/analytics/cycle_analytics/stage_events/stage_event.rb', line 34

def hash_code
  Digest::SHA256.hexdigest(self.class.identifier.to_s)
end

#html_description(options = {}) ⇒ Object


22
23
24
# File 'lib/gitlab/analytics/cycle_analytics/stage_events/stage_event.rb', line 22

def html_description(options = {})
  self.class.name
end

#include_in(query) ⇒ Object

rubocop: enable CodeReuse/ActiveRecord


64
65
66
# File 'lib/gitlab/analytics/cycle_analytics/stage_events/stage_event.rb', line 64

def include_in(query)
  query
end

#object_typeObject

Raises:

  • (NotImplementedError)

30
31
32
# File 'lib/gitlab/analytics/cycle_analytics/stage_events/stage_event.rb', line 30

def object_type
  raise NotImplementedError
end

#timestamp_projectionObject

Each StageEvent must expose a timestamp or a timestamp like expression in order to build a range query. Example: get me all the Issue records between start event end end event


40
41
42
43
44
# File 'lib/gitlab/analytics/cycle_analytics/stage_events/stage_event.rb', line 40

def timestamp_projection
  columns = column_list

  columns.one? ? columns.first : Arel::Nodes::NamedFunction.new('COALESCE', columns)
end