Class: Gitlab::Ci::Trace
- Inherits:
-
Object
show all
- Includes:
- Checksummable, ExclusiveLeaseHelpers, Utils::StrongMemoize
- Defined in:
- lib/gitlab/ci/trace.rb,
lib/gitlab/ci/trace/stream.rb,
lib/gitlab/ci/trace/archive.rb,
lib/gitlab/ci/trace/backoff.rb,
lib/gitlab/ci/trace/metrics.rb,
lib/gitlab/ci/trace/checksum.rb,
lib/gitlab/ci/trace/chunked_io.rb,
lib/gitlab/ci/trace/section_parser.rb,
lib/gitlab/ci/trace/remote_checksum.rb
Defined Under Namespace
Classes: Archive, Backoff, Checksum, ChunkedIO, Metrics, RemoteChecksum, SectionParser, Stream
Constant Summary
collapse
- LOCK_TTL =
10.minutes
- LOCK_RETRIES =
2
- LOCK_SLEEP =
0.001.seconds
- WATCH_FLAG_TTL =
10.seconds
- UPDATE_FREQUENCY_DEFAULT =
60.seconds
- UPDATE_FREQUENCY_WHEN_BEING_WATCHED =
3.seconds
- LOAD_BALANCING_STICKING_NAMESPACE =
'ci/build/trace'
- ArchiveError =
Class.new(StandardError)
- AlreadyArchivedError =
Class.new(StandardError)
- LockedError =
Class.new(StandardError)
ExclusiveLeaseHelpers::FailedToObtainLockError
Instance Attribute Summary collapse
Instance Method Summary
collapse
#in_lock
Constructor Details
#initialize(job) ⇒ Trace
Returns a new instance of Trace.
29
30
31
|
# File 'lib/gitlab/ci/trace.rb', line 29
def initialize(job)
@job = job
end
|
Instance Attribute Details
#job ⇒ Object
Returns the value of attribute job.
24
25
26
|
# File 'lib/gitlab/ci/trace.rb', line 24
def job
@job
end
|
Instance Method Details
#append(data, offset) ⇒ Object
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/gitlab/ci/trace.rb', line 64
def append(data, offset)
write('a+b') do |stream|
current_length = stream.size
break current_length unless current_length == offset
data = job.hide_secrets(data)
stream.append(data, offset)
stream.size
end
end
|
#archive! ⇒ Object
117
118
119
120
121
|
# File 'lib/gitlab/ci/trace.rb', line 117
def archive!
in_write_lock do
unsafe_archive!
end
end
|
#archived? ⇒ Boolean
79
80
81
|
# File 'lib/gitlab/ci/trace.rb', line 79
def archived?
trace_artifact&.stored?
end
|
#attempt_archive_cleanup! ⇒ Object
123
124
125
|
# File 'lib/gitlab/ci/trace.rb', line 123
def attempt_archive_cleanup!
destroy_any_orphan_trace_data!
end
|
#being_watched? ⇒ Boolean
141
142
143
144
145
|
# File 'lib/gitlab/ci/trace.rb', line 141
def being_watched?
Gitlab::Redis::SharedState.with do |redis|
redis.exists?(being_watched_cache_key) end
end
|
#erase! ⇒ Object
104
105
106
107
108
109
110
111
112
113
114
115
|
# File 'lib/gitlab/ci/trace.rb', line 104
def erase!
trace_artifact&.destroy!
erase_trace_chunks!
FileUtils.rm_f(current_path) if current_path ensure
@current_path = nil
end
|
#erase_trace_chunks! ⇒ Object
100
101
102
|
# File 'lib/gitlab/ci/trace.rb', line 100
def erase_trace_chunks!
job.trace_chunks.fast_destroy_all end
|
#exist? ⇒ Boolean
75
76
77
|
# File 'lib/gitlab/ci/trace.rb', line 75
def exist?
archived? || live?
end
|
45
46
47
48
49
|
# File 'lib/gitlab/ci/trace.rb', line 45
def (regex)
read do |stream|
stream.(regex)
end
end
|
51
52
53
54
55
|
# File 'lib/gitlab/ci/trace.rb', line 51
def
read do |stream|
stream.
end
end
|
#html(last_lines: nil, max_size: nil) ⇒ Object
33
34
35
36
37
|
# File 'lib/gitlab/ci/trace.rb', line 33
def html(last_lines: nil, max_size: nil)
read do |stream|
stream.html(last_lines: last_lines, max_size: max_size)
end
end
|
#live? ⇒ Boolean
83
84
85
|
# File 'lib/gitlab/ci/trace.rb', line 83
def live?
job.trace_chunks.any? || current_path.present?
end
|
#lock(&block) ⇒ Object
147
148
149
150
151
|
# File 'lib/gitlab/ci/trace.rb', line 147
def lock(&block)
in_write_lock(&block)
rescue FailedToObtainLockError
raise LockedError, "build trace `#{job.id}` is locked"
end
|
#raw(last_lines: nil) ⇒ Object
39
40
41
42
43
|
# File 'lib/gitlab/ci/trace.rb', line 39
def raw(last_lines: nil)
read do |stream|
stream.raw(last_lines: last_lines)
end
end
|
#read(&block) ⇒ Object
87
88
89
90
91
92
|
# File 'lib/gitlab/ci/trace.rb', line 87
def read(&block)
read_stream(&block)
rescue Errno::ENOENT, ChunkedIO::FailedToGetChunkError
job.reset
read_stream(&block)
end
|
#set(data) ⇒ Object
57
58
59
60
61
62
|
# File 'lib/gitlab/ci/trace.rb', line 57
def set(data)
write('w+b') do |stream|
data = job.hide_secrets(data)
stream.set(data)
end
end
|
#update_interval ⇒ Object
#write(mode, &blk) ⇒ Object
94
95
96
97
98
|
# File 'lib/gitlab/ci/trace.rb', line 94
def write(mode, &blk)
in_write_lock do
unsafe_write!(mode, &blk)
end
end
|