Class: Gitlab::Usage::Metrics::Aggregates::Aggregate

Inherits:
Object
  • Object
show all
Includes:
TimeFrame
Defined in:
lib/gitlab/usage/metrics/aggregates/aggregate.rb

Constant Summary

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 Method Summary collapse

Methods included from TimeFrame

#monthly_time_range, #monthly_time_range_db_params, #weekly_time_range, #weekly_time_range_db_params

Constructor Details

#initialize(recorded_at) ⇒ Aggregate

Returns a new instance of Aggregate.



10
11
12
# File 'lib/gitlab/usage/metrics/aggregates/aggregate.rb', line 10

def initialize(recorded_at)
  @recorded_at = recorded_at
end

Instance Method Details

#calculate_count_for_aggregation(aggregation:, time_frame:) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/gitlab/usage/metrics/aggregates/aggregate.rb', line 14

def calculate_count_for_aggregation(aggregation:, time_frame:)
  with_validate_configuration(aggregation, time_frame) do
    source = SOURCES[aggregation[:source]]
    events = select_defined_events(aggregation[:events], aggregation[:source])

    if aggregation[:operator] == UNION_OF_AGGREGATED_METRICS
      source.calculate_metrics_union(**time_constraints(time_frame).merge(metric_names: events, recorded_at: recorded_at))
    else
      source.calculate_metrics_intersections(**time_constraints(time_frame).merge(metric_names: events, recorded_at: recorded_at))
    end
  end
rescue Gitlab::UsageDataCounters::HLLRedisCounter::EventError, AggregatedMetricError => error
  failure(error)
end