Class: Ci::RegisterJobService::Logger

Inherits:
Object
  • Object
show all
Includes:
Gitlab::Utils::StrongMemoize
Defined in:
app/services/ci/register_job_service/logger.rb

Constant Summary collapse

MAX_DURATION =
5.seconds

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(runner:, destination: ::Gitlab::AppJsonLogger) {|_self| ... } ⇒ Logger

Returns a new instance of Logger.

Yields:

  • (_self)

Yield Parameters:



14
15
16
17
18
19
20
# File 'app/services/ci/register_job_service/logger.rb', line 14

def initialize(runner:, destination: ::Gitlab::AppJsonLogger)
  @started_at = current_monotonic_time
  @runner = runner
  @destination = destination

  yield(self) if block_given?
end

Class Method Details

.current_monotonic_timeObject



10
11
12
# File 'app/services/ci/register_job_service/logger.rb', line 10

def self.current_monotonic_time
  ::Gitlab::Metrics::System.monotonic_time
end

Instance Method Details

#commitObject



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/services/ci/register_job_service/logger.rb', line 36

def commit
  return unless log?

  attributes = {
    class: self.class.name.to_s,
    message: 'RegisterJobService exceeded maximum duration',
    total_duration_s: age,
    runner_id: runner.id,
    runner_type: runner.runner_type
  }.merge(observations_hash)

  destination.info(attributes)
end

#instrument(operation, once: false) ⇒ Object

Raises:

  • (ArgumentError)


22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/services/ci/register_job_service/logger.rb', line 22

def instrument(operation, once: false)
  return yield unless enabled?

  raise ArgumentError, 'block not given' unless block_given?

  op_started_at = current_monotonic_time

  result = yield

  observe(:"#{operation}_duration_s", current_monotonic_time - op_started_at, once: once)

  result
end