Class: Ci::CollectPipelineAnalyticsService

Inherits:
Object
  • Object
show all
Defined in:
app/services/ci/collect_pipeline_analytics_service.rb

Constant Summary collapse

STATUS_GROUP_TO_STATUSES =
{ success: %w[success], failed: %w[failed], other: %w[canceled skipped] }.freeze
STATUS_GROUPS =
STATUS_GROUP_TO_STATUSES.keys.freeze
STATUS_TO_STATUS_GROUP =
STATUS_GROUP_TO_STATUSES.flat_map { |k, v| v.product([k]) }.to_h
ALLOWED_PERCENTILES =
[50, 75, 90, 95, 99].freeze

Instance Method Summary collapse

Constructor Details

#initialize(current_user:, project:, from_time:, to_time:, source: nil, ref: nil, status_groups: [:any], duration_percentiles: []) ⇒ CollectPipelineAnalyticsService

Returns a new instance of CollectPipelineAnalyticsService.



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/services/ci/collect_pipeline_analytics_service.rb', line 11

def initialize(
  current_user:, project:, from_time:, to_time:,
  source: nil, ref: nil, status_groups: [:any], duration_percentiles: []
)
  @current_user = current_user
  @project = project
  @status_groups = status_groups
  @source = source
  @ref = ref
  @duration_percentiles = duration_percentiles
  @from_time = from_time || 1.week.ago.utc
  @to_time = to_time || Time.now.utc
end

Instance Method Details

#executeObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/services/ci/collect_pipeline_analytics_service.rb', line 25

def execute
  return ServiceResponse.error(message: 'Project must be specified') unless @project

  unless ::Gitlab::ClickHouse.configured?
    return ServiceResponse.error(message: 'ClickHouse database is not configured')
  end

  return ServiceResponse.error(message: 'Not allowed') unless allowed?

  error_message = clickhouse_model.validate_time_window(@from_time, @to_time)
  return ServiceResponse.error(message: error_message) if error_message

  ServiceResponse.success(payload: { aggregate: calculate_aggregate })
end