Class: CiPlatformMetric

Inherits:
ApplicationRecord show all
Includes:
BulkInsertSafe
Defined in:
app/models/ci_platform_metric.rb

Constant Summary collapse

PLATFORM_TARGET_MAX_LENGTH =
255
CI_VARIABLE_KEY =
'AUTO_DEVOPS_PLATFORM_TARGET'

Constants included from BulkInsertSafe

BulkInsertSafe::ALLOWED_CALLBACKS, BulkInsertSafe::DEFAULT_BATCH_SIZE, BulkInsertSafe::MethodNotAllowedError, BulkInsertSafe::PrimaryKeySetError

Class Method Summary collapse

Methods inherited from ApplicationRecord

at_most, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, underscore, without_order

Class Method Details

.insert_auto_devops_platform_targets!Object


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/models/ci_platform_metric.rb', line 18

def self.insert_auto_devops_platform_targets!
  # This work can NOT be done in-database because value is encrypted.
  # However, for 'AUTO_DEVOPS_PLATFORM_TARGET', these values are only
  # encrypted as a matter of course, rather than as a need for secrecy.
  # So this is not a security risk, but exposing other keys possibly could be.
  variables = Ci::Variable.by_key(CI_VARIABLE_KEY)
  recorded_at = Time.zone.now
  counts = variables.group_by(&:value).map do |value, variables|
    target = value.truncate(PLATFORM_TARGET_MAX_LENGTH, separator: '', omission: '')
    count = variables.count
    self.new(recorded_at: recorded_at, platform_target: target, count: count)
  end

  bulk_insert!(counts, validate: true)
end