debian-mirror-gitlab/lib/gitlab/ci/trace/metrics.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

95 lines
3.4 KiB
Ruby
Raw Normal View History

2020-11-24 15:15:51 +05:30
# frozen_string_literal: true
module Gitlab
module Ci
class Trace
class Metrics
extend Gitlab::Utils::StrongMemoize
2021-01-03 14:25:43 +05:30
OPERATIONS = [
:appended, # new trace data has been written to a chunk
:streamed, # new trace data has been sent by a runner
:chunked, # new trace chunk has been created
:mutated, # trace has been mutated when removing secrets
:accepted, # scheduled chunks for migration and responded with 202
:finalized, # all live build trace chunks have been persisted
:discarded, # failed to persist live chunks before timeout
:conflict, # runner has sent unrecognized build state details
:locked, # build trace has been locked by a different mechanism
:stalled, # failed to migrate chunk due to a worker duplication
2021-02-22 17:27:13 +05:30
:invalid, # invalid build trace has been detected using CRC32
:corrupted # malformed trace found after comparing CRC32 and size
2021-01-03 14:25:43 +05:30
].freeze
2020-11-24 15:15:51 +05:30
2021-12-11 22:18:48 +05:30
TRACE_ERROR_REASONS = [
2021-11-18 22:05:49 +05:30
:chunks_invalid_size, # used to be :corrupted
:chunks_invalid_checksum, # used to be :invalid
:archive_invalid_checksum # malformed trace found into object store after comparing MD5
].freeze
2020-11-24 15:15:51 +05:30
def increment_trace_operation(operation: :unknown)
unless OPERATIONS.include?(operation)
raise ArgumentError, "unknown trace operation: #{operation}"
end
self.class.trace_operations.increment(operation: operation)
end
def increment_trace_bytes(size)
2021-01-03 14:25:43 +05:30
self.class.trace_bytes.increment({}, size.to_i)
end
2021-12-11 22:18:48 +05:30
def increment_error_counter(error_reason: :unknown)
unless TRACE_ERROR_REASONS.include?(error_reason)
raise ArgumentError, "unknown error reason: #{error_reason}"
2021-11-18 22:05:49 +05:30
end
2021-12-11 22:18:48 +05:30
self.class.trace_errors_counter.increment(error_reason: error_reason)
2021-11-18 22:05:49 +05:30
end
2021-01-03 14:25:43 +05:30
def observe_migration_duration(seconds)
self.class.finalize_histogram.observe({}, seconds.to_f)
2020-11-24 15:15:51 +05:30
end
def self.trace_operations
strong_memoize(:trace_operations) do
name = :gitlab_ci_trace_operations_total
comment = 'Total amount of different operations on a build trace'
Gitlab::Metrics.counter(name, comment)
end
end
def self.trace_bytes
strong_memoize(:trace_bytes) do
name = :gitlab_ci_trace_bytes_total
comment = 'Total amount of build trace bytes transferred'
Gitlab::Metrics.counter(name, comment)
end
end
2021-01-03 14:25:43 +05:30
def self.finalize_histogram
strong_memoize(:finalize_histogram) do
name = :gitlab_ci_trace_finalize_duration_seconds
comment = 'Duration of build trace chunks migration to object storage'
buckets = [0.1, 0.5, 1.0, 2.0, 3.0, 5.0, 7.0, 10.0, 20.0, 30.0, 60.0, 300.0]
labels = {}
::Gitlab::Metrics.histogram(name, comment, labels, buckets)
end
end
2021-11-18 22:05:49 +05:30
def self.trace_errors_counter
strong_memoize(:trace_errors_counter) do
name = :gitlab_ci_build_trace_errors_total
comment = 'Total amount of different error types on a build trace'
Gitlab::Metrics.counter(name, comment)
end
end
2020-11-24 15:15:51 +05:30
end
end
end
end