Class: Gitlab::Ci::Trace::Backoff

Inherits:
Object
  • Object
show all
Includes:
Utils::StrongMemoize
Defined in:
lib/gitlab/ci/trace/backoff.rb

Overview

Trace::Backoff class is responsible for calculating a backoff value for when to be able to retry archiving a build’s trace

Because we’re updating ‘last_archival_attempt_at` timestamp with every failed archival attempt, we need to be sure that sum of the backoff values for 1..MAX_ATTEMPTS is under 7 days(CHUNK_REDIS_TTL).

Constant Summary collapse

MAX_JITTER_VALUE =
4

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(archival_attempts) ⇒ Backoff

Returns a new instance of Backoff.



21
22
23
# File 'lib/gitlab/ci/trace/backoff.rb', line 21

def initialize(archival_attempts)
  @archival_attempts = archival_attempts
end

Instance Attribute Details

#archival_attemptsObject (readonly)

Returns the value of attribute archival_attempts.



19
20
21
# File 'lib/gitlab/ci/trace/backoff.rb', line 19

def archival_attempts
  @archival_attempts
end

Instance Method Details

#valueObject



25
26
27
# File 'lib/gitlab/ci/trace/backoff.rb', line 25

def value
  (((chunks_ttl / (3.5 * max_attempts)) * archival_attempts) / 1.hour).hours
end

#value_with_jitterObject

This formula generates an increasing delay between executions 9.6, 19.2, 28.8, 38.4, 48.0 + a random amount of time to change the order of execution for the jobs. With maximum value for each call to rand(4), this sums up to 6.8 days and with minimum values is 6 days.



35
36
37
# File 'lib/gitlab/ci/trace/backoff.rb', line 35

def value_with_jitter
  value + jitter
end