2023-04-23 21:23:45 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Cache
|
|
|
|
# Value object for cache metadata
|
|
|
|
class Metadata
|
|
|
|
VALID_BACKING_RESOURCES = [:cpu, :database, :gitaly, :memory, :unknown].freeze
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
# @param cache_identifier [String] defines the location of the cache definition
|
|
|
|
# Example: "ProtectedBranches::CacheService#fetch"
|
|
|
|
# @param feature_category [Symbol] name of the feature category (from config/feature_categories.yml)
|
|
|
|
# @param caller_id [String] caller id from labkit context
|
|
|
|
# @param backing_resource [Symbol] most affected resource by cache generation (full list: VALID_BACKING_RESOURCES)
|
|
|
|
# @return [Gitlab::Cache::Metadata]
|
2023-04-23 21:23:45 +05:30
|
|
|
def initialize(
|
|
|
|
cache_identifier:,
|
|
|
|
feature_category:,
|
|
|
|
caller_id: Gitlab::ApplicationContext.current_context_attribute(:caller_id),
|
2023-05-27 22:25:52 +05:30
|
|
|
backing_resource: Client::DEFAULT_BACKING_RESOURCE
|
2023-04-23 21:23:45 +05:30
|
|
|
)
|
|
|
|
@cache_identifier = cache_identifier
|
|
|
|
@feature_category = Gitlab::FeatureCategories.default.get!(feature_category)
|
|
|
|
@caller_id = caller_id
|
|
|
|
@backing_resource = fetch_backing_resource!(backing_resource)
|
|
|
|
end
|
|
|
|
|
|
|
|
attr_reader :caller_id, :cache_identifier, :feature_category, :backing_resource
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def fetch_backing_resource!(resource)
|
|
|
|
return resource if VALID_BACKING_RESOURCES.include?(resource)
|
|
|
|
|
|
|
|
raise "Unknown backing resource: #{resource}" if Gitlab.dev_or_test_env?
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
Client::DEFAULT_BACKING_RESOURCE
|
2023-04-23 21:23:45 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|