Commit 939c8ce6 authored by Andreas Brandl's avatar Andreas Brandl

Add last update at gauge

This allows us to reason about which gauge value to use when gauges are
being reported from multiple (sidekiq) hosts over time.
parent d058aeb3
...@@ -67,6 +67,7 @@ module Gitlab ...@@ -67,6 +67,7 @@ module Gitlab
metric_for(:counter_updated_tuples).increment(base_labels, tracking_record.batch_size) metric_for(:counter_updated_tuples).increment(base_labels, tracking_record.batch_size)
metric_for(:gauge_migrated_tuples).set(base_labels, tracking_record.batched_migration.migrated_tuple_count) metric_for(:gauge_migrated_tuples).set(base_labels, tracking_record.batched_migration.migrated_tuple_count)
metric_for(:gauge_total_tuple_count).set(base_labels, tracking_record.batched_migration.total_tuple_count) metric_for(:gauge_total_tuple_count).set(base_labels, tracking_record.batched_migration.total_tuple_count)
metric_for(:gauge_last_update_time).set(base_labels, Time.current.to_i)
if metrics = tracking_record.metrics if metrics = tracking_record.metrics
metrics['timings']&.each do |key, timings| metrics['timings']&.each do |key, timings|
...@@ -120,6 +121,10 @@ module Gitlab ...@@ -120,6 +121,10 @@ module Gitlab
gauge_total_tuple_count: Gitlab::Metrics.gauge( gauge_total_tuple_count: Gitlab::Metrics.gauge(
:batched_migration_total_tuple_count, :batched_migration_total_tuple_count,
'Total tuple count the migration needs to touch' 'Total tuple count the migration needs to touch'
),
gauge_last_update_time: Gitlab::Metrics.gauge(
:batched_migration_last_update_time_seconds,
'Unix epoch time in seconds'
) )
} }
end end
......
...@@ -142,7 +142,7 @@ RSpec.describe Gitlab::Database::BackgroundMigration::BatchedMigrationWrapper, ' ...@@ -142,7 +142,7 @@ RSpec.describe Gitlab::Database::BackgroundMigration::BatchedMigrationWrapper, '
it 'reports job duration' do it 'reports job duration' do
freeze_time do freeze_time do
expect(Time).to receive(:current).and_return(Time.zone.now - 5.seconds).ordered expect(Time).to receive(:current).and_return(Time.zone.now - 5.seconds).ordered
expect(Time).to receive(:current).and_return(Time.zone.now).ordered allow(Time).to receive(:current).and_call_original
expect(described_class.metrics[:gauge_job_duration]).to receive(:set).with(labels, 5.seconds) expect(described_class.metrics[:gauge_job_duration]).to receive(:set).with(labels, 5.seconds)
...@@ -155,6 +155,14 @@ RSpec.describe Gitlab::Database::BackgroundMigration::BatchedMigrationWrapper, ' ...@@ -155,6 +155,14 @@ RSpec.describe Gitlab::Database::BackgroundMigration::BatchedMigrationWrapper, '
subject subject
end end
it 'reports last updated at timestamp' do
freeze_time do
expect(described_class.metrics[:gauge_last_update_time]).to receive(:set).with(labels, Time.current.to_i)
subject
end
end
end end
context 'when the migration job does not raise an error' do context 'when the migration job does not raise an error' do
......
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