Class: PodLogs::BaseService

Inherits:
BaseService show all
Includes:
ReactiveCaching, Stepable
Defined in:
app/services/pod_logs/base_service.rb

Direct Known Subclasses

ElasticsearchService, KubernetesService

Constant Summary collapse

CACHE_KEY_GET_POD_LOG =
'get_pod_log'
K8S_NAME_MAX_LENGTH =
253

Constants included from ReactiveCaching

ReactiveCaching::ExceededReactiveCacheLimit, ReactiveCaching::InvalidateReactiveCache, ReactiveCaching::WORK_TYPE

Instance Attribute Summary collapse

Attributes inherited from BaseService

#current_user, #project

Instance Method Summary collapse

Methods included from Stepable

#execute_steps, #steps

Methods included from BaseServiceUtility

#deny_visibility_level, #event_service, #log_error, #log_info, #notification_service, #system_hook_service, #todo_service, #visibility_level

Methods included from Gitlab::Allowable

#can?

Constructor Details

#initialize(cluster, namespace, params: {}) ⇒ BaseService

Returns a new instance of BaseService.


17
18
19
20
21
# File 'app/services/pod_logs/base_service.rb', line 17

def initialize(cluster, namespace, params: {})
  @cluster = cluster
  @namespace = namespace
  @params = filter_params(params.dup.stringify_keys).to_hash
end

Instance Attribute Details

#clusterObject (readonly)

Returns the value of attribute cluster


8
9
10
# File 'app/services/pod_logs/base_service.rb', line 8

def cluster
  @cluster
end

#namespaceObject (readonly)

Returns the value of attribute namespace


8
9
10
# File 'app/services/pod_logs/base_service.rb', line 8

def namespace
  @namespace
end

#paramsObject (readonly)

Returns the value of attribute params


8
9
10
# File 'app/services/pod_logs/base_service.rb', line 8

def params
  @params
end

Instance Method Details

#calculate_reactive_cache(request, _namespace, _params) ⇒ Object


33
34
35
36
37
38
39
40
41
42
# File 'app/services/pod_logs/base_service.rb', line 33

def calculate_reactive_cache(request, _namespace, _params)
  case request
  when CACHE_KEY_GET_POD_LOG
    execute_steps
  else
    exception = StandardError.new('Unknown reactive cache request')
    Gitlab::ErrorTracking.track_and_raise_for_dev_exception(exception, request: request)
    error(_('Unknown cache key'))
  end
end

#executeObject


23
24
25
26
27
28
29
30
31
# File 'app/services/pod_logs/base_service.rb', line 23

def execute
  with_reactive_cache(
    CACHE_KEY_GET_POD_LOG,
    namespace,
    params
  ) do |result|
    result
  end
end

#idObject


13
14
15
# File 'app/services/pod_logs/base_service.rb', line 13

def id
  cluster.id
end