Commit e6625e88 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Add build trace chunks migration duration histogram

This commit adds another metric improving observability of cloud native
build logs. We are adding a histogram recording a duration of the
operation that migrates build trace chunks to object storage.
parent b0c29c8f
...@@ -75,6 +75,7 @@ module Ci ...@@ -75,6 +75,7 @@ module Ci
unless live_chunks_pending? unless live_chunks_pending?
metrics.increment_trace_operation(operation: :finalized) metrics.increment_trace_operation(operation: :finalized)
metrics.observe_migration_duration(pending_state_seconds)
end end
::Gitlab::Ci::Trace::Checksum.new(build).then do |checksum| ::Gitlab::Ci::Trace::Checksum.new(build).then do |checksum|
...@@ -130,7 +131,15 @@ module Ci ...@@ -130,7 +131,15 @@ module Ci
end end
def pending_state_outdated? def pending_state_outdated?
Time.current - pending_state.created_at > ACCEPT_TIMEOUT pending_state_duration > ACCEPT_TIMEOUT
end
def pending_state_duration
Time.current - pending_state.created_at
end
def pending_state_seconds
pending_state_duration.seconds
end end
def build_state def build_state
......
...@@ -33,6 +33,10 @@ module Gitlab ...@@ -33,6 +33,10 @@ module Gitlab
self.class.trace_bytes.increment({}, size.to_i) self.class.trace_bytes.increment({}, size.to_i)
end end
def observe_migration_duration(seconds)
self.class.finalize_histogram.observe({}, seconds.to_f)
end
def self.trace_operations def self.trace_operations
strong_memoize(:trace_operations) do strong_memoize(:trace_operations) do
name = :gitlab_ci_trace_operations_total name = :gitlab_ci_trace_operations_total
...@@ -50,6 +54,17 @@ module Gitlab ...@@ -50,6 +54,17 @@ module Gitlab
Gitlab::Metrics.counter(name, comment) Gitlab::Metrics.counter(name, comment)
end end
end end
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.01, 0.05, 0.1, 0.5, 1.0, 2.0, 10.0, 30.0, 60.0, 300.0]
labels = {}
::Gitlab::Metrics.histogram(name, comment, labels, buckets)
end
end
end end
end end
end end
......
...@@ -131,6 +131,18 @@ RSpec.describe Ci::UpdateBuildStateService do ...@@ -131,6 +131,18 @@ RSpec.describe Ci::UpdateBuildStateService do
.with(operation: :finalized) .with(operation: :finalized)
end end
it 'records migration duration in a histogram' do
freeze_time do
create(:ci_build_pending_state, build: build, created_at: 0.5.seconds.ago)
execute_with_stubbed_metrics!
end
expect(metrics)
.to have_received(:observe_migration_duration)
.with(0.5)
end
context 'when trace checksum is not valid' do context 'when trace checksum is not valid' do
it 'increments invalid trace metric' do it 'increments invalid trace metric' do
execute_with_stubbed_metrics! execute_with_stubbed_metrics!
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment