Class: Gitlab::Usage::EventSelectionRule
- Inherits:
-
Object
- Object
- Gitlab::Usage::EventSelectionRule
- Extended by:
- Gitlab::Utils::StrongMemoize
- Includes:
- TimeFrame, TimeSeriesStorable
- Defined in:
- lib/gitlab/usage/event_selection_rule.rb
Constant Summary collapse
- TOTAL_COUNTER_KEY_PREFIX =
"event_counters"- SUM_KEY_PREFIX =
"event_sums"
Constants included from TimeFrame
TimeFrame::ALL_TIME_TIME_FRAME_NAME, TimeFrame::DEFAULT_TIMESTAMP_COLUMN, TimeFrame::SEVEN_DAYS_TIME_FRAME_NAME, TimeFrame::TWENTY_EIGHT_DAYS_TIME_FRAME_NAME
Instance Attribute Summary collapse
-
#filter ⇒ Object
readonly
Returns the value of attribute filter.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#operator ⇒ Object
readonly
Returns the value of attribute operator.
-
#unique_identifier_name ⇒ Object
readonly
Returns the value of attribute unique_identifier_name.
Class Method Summary collapse
-
.key_overrides ⇒ Object
We want to avoid reading the key_overrides every time a rule is used.
Instance Method Summary collapse
-
#==(other) ⇒ Object
(also: #eql?)
Implementing ‘==` to make sure that `a == b` is true if and only if
aandbhave equal properties Checks equality by comparing each attribute. -
#hash ⇒ Integer
Calculates hash code according to all attributes.
-
#initialize(name:, time_framed:, filter: {}, unique_identifier_name: nil, operator: nil) ⇒ EventSelectionRule
constructor
A new instance of EventSelectionRule.
- #matches?(additional_properties) ⇒ Boolean
- #redis_key_for_date(date = Date.today) ⇒ Object
- #redis_keys_for_time_frame(time_frame) ⇒ Object
- #sum? ⇒ Boolean
- #time_framed? ⇒ Boolean
- #total_counter? ⇒ Boolean
- #unique_total? ⇒ Boolean
Methods included from TimeFrame
#monthly_time_range, #monthly_time_range_db_params, #weekly_time_range, #weekly_time_range_db_params
Methods included from TimeSeriesStorable
#apply_time_aggregation, #keys_for_aggregation
Constructor Details
#initialize(name:, time_framed:, filter: {}, unique_identifier_name: nil, operator: nil) ⇒ EventSelectionRule
Returns a new instance of EventSelectionRule.
33 34 35 36 37 38 39 |
# File 'lib/gitlab/usage/event_selection_rule.rb', line 33 def initialize(name:, time_framed:, filter: {}, unique_identifier_name: nil, operator: nil) @name = name @time_framed = time_framed @filter = filter || {} @unique_identifier_name = unique_identifier_name @operator = operator end |
Instance Attribute Details
#filter ⇒ Object (readonly)
Returns the value of attribute filter.
31 32 33 |
# File 'lib/gitlab/usage/event_selection_rule.rb', line 31 def filter @filter end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
31 32 33 |
# File 'lib/gitlab/usage/event_selection_rule.rb', line 31 def name @name end |
#operator ⇒ Object (readonly)
Returns the value of attribute operator.
31 32 33 |
# File 'lib/gitlab/usage/event_selection_rule.rb', line 31 def operator @operator end |
#unique_identifier_name ⇒ Object (readonly)
Returns the value of attribute unique_identifier_name.
31 32 33 |
# File 'lib/gitlab/usage/event_selection_rule.rb', line 31 def unique_identifier_name @unique_identifier_name end |
Class Method Details
.key_overrides ⇒ Object
We want to avoid reading the key_overrides every time a rule is used.
25 26 27 28 29 |
# File 'lib/gitlab/usage/event_selection_rule.rb', line 25 def self.key_overrides strong_memoize(:key_overrides) do YAML.safe_load(File.read(Gitlab::UsageDataCounters::HLLRedisCounter::KEY_OVERRIDES_PATH)).freeze end end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
Implementing ‘==` to make sure that `a == b` is true if and only if a and b have equal properties Checks equality by comparing each attribute.
78 79 80 81 82 83 84 85 |
# File 'lib/gitlab/usage/event_selection_rule.rb', line 78 def ==(other) other.is_a?(self.class) && name == other.name && time_framed? == other.time_framed? && filter == other.filter && unique_identifier_name == other.unique_identifier_name && operator == other.operator end |
#hash ⇒ Integer
Calculates hash code according to all attributes. Ensures 2 objects with the same attributes can’t be keys in the same hash twice
93 94 95 |
# File 'lib/gitlab/usage/event_selection_rule.rb', line 93 def hash [name, time_framed?, filter, unique_identifier_name, operator].hash end |
#matches?(additional_properties) ⇒ Boolean
69 70 71 72 73 |
# File 'lib/gitlab/usage/event_selection_rule.rb', line 69 def matches?(additional_properties) filter.all? do |property_name, value| additional_properties[property_name] == value end end |
#redis_key_for_date(date = Date.today) ⇒ Object
41 42 43 |
# File 'lib/gitlab/usage/event_selection_rule.rb', line 41 def redis_key_for_date(date = Date.today) redis_key(nil, date) end |
#redis_keys_for_time_frame(time_frame) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/gitlab/usage/event_selection_rule.rb', line 45 def redis_keys_for_time_frame(time_frame) if time_frame == 'all' [redis_key] else keys_for_aggregation(events: [path_part_of_redis_key], **time_constraint(time_frame)) end end |
#sum? ⇒ Boolean
61 62 63 |
# File 'lib/gitlab/usage/event_selection_rule.rb', line 61 def sum? operator == 'sum(value)' end |
#time_framed? ⇒ Boolean
53 54 55 |
# File 'lib/gitlab/usage/event_selection_rule.rb', line 53 def time_framed? @time_framed end |
#total_counter? ⇒ Boolean
57 58 59 |
# File 'lib/gitlab/usage/event_selection_rule.rb', line 57 def total_counter? unique_identifier_name.nil? && !sum? end |
#unique_total? ⇒ Boolean
65 66 67 |
# File 'lib/gitlab/usage/event_selection_rule.rb', line 65 def unique_total? unique_identifier_name && operator == 'total' end |