Class: Gitlab::Ci::Trace::Metrics

Inherits:
Object
  • Object
show all
Extended by:
Utils::StrongMemoize
Defined in:
lib/gitlab/ci/trace/metrics.rb

Constant Summary collapse

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
  :overwrite, # runner requested overwritting a build trace
  :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
  :invalid    # malformed build trace has been detected using CRC32
].freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utils::StrongMemoize

clear_memoization, strong_memoize, strong_memoized?

Class Method Details

.finalize_histogramObject


58
59
60
61
62
63
64
65
66
67
# File 'lib/gitlab/ci/trace/metrics.rb', line 58

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

.trace_bytesObject


49
50
51
52
53
54
55
56
# File 'lib/gitlab/ci/trace/metrics.rb', line 49

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

.trace_operationsObject


40
41
42
43
44
45
46
47
# File 'lib/gitlab/ci/trace/metrics.rb', line 40

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

Instance Method Details

#increment_trace_bytes(size) ⇒ Object


32
33
34
# File 'lib/gitlab/ci/trace/metrics.rb', line 32

def increment_trace_bytes(size)
  self.class.trace_bytes.increment({}, size.to_i)
end

#increment_trace_operation(operation: :unknown) ⇒ Object


24
25
26
27
28
29
30
# File 'lib/gitlab/ci/trace/metrics.rb', line 24

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

#observe_migration_duration(seconds) ⇒ Object


36
37
38
# File 'lib/gitlab/ci/trace/metrics.rb', line 36

def observe_migration_duration(seconds)
  self.class.finalize_histogram.observe({}, seconds.to_f)
end