Class: CiPlatformMetric
- Inherits:
-
Ci::ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Ci::ApplicationRecord
- CiPlatformMetric
- 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'
- ALLOWED_TARGETS =
%w[ECS FARGATE EC2].freeze
Constants included from BulkInsertSafe
BulkInsertSafe::ALLOWED_CALLBACKS, BulkInsertSafe::DEFAULT_BATCH_SIZE, BulkInsertSafe::MethodNotAllowedError, BulkInsertSafe::PrimaryKeySetError
Constants inherited from ApplicationRecord
Constants included from ResetOnUnionError
ResetOnUnionError::MAX_RESET_PERIOD
Class Method Summary collapse
Methods inherited from Ci::ApplicationRecord
Methods inherited from ApplicationRecord
cached_column_list, #create_or_load_association, declarative_enum, default_select_columns, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order
Methods included from SensitiveSerializableHash
Class Method Details
.insert_auto_devops_platform_targets! ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/models/ci_platform_metric.rb', line 21 def self.insert_auto_devops_platform_targets! recorded_at = Time.zone.now # 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) counts = variables.group_by(&:value).map do |value, variables| # While this value is, in theory, not secret. A user could accidentally # put a secret in here so we need to make sure we filter invalid values. next unless ALLOWED_TARGETS.include?(value) count = variables.count self.new(recorded_at: recorded_at, platform_target: value, count: count) end.compact bulk_insert!(counts, validate: true) end |