Skip to content

Move BBM prometheus metrics into separate class

Patrick Bair requested to merge pb-move-bbm-prometheus-metrics into master

What does this MR do and why?

Related to #357033 (closed)

Move the prometheus metrics gathering for batched background migrations out of the migration wrapper and into a separate class. This simplifies the migration wrapper a bit, before we begin hoist some of the batching boilerplate into the wrapper.

How to set up and validate locally

  1. In a rails console, create an instance of the metrics class, and verify the gauges have no values
    metrics = Gitlab::Database::BackgroundMigration::PrometheusMetrics.new
    metrics.class.metrics[:gauge_batch_size].values # => {}
    metrics.class.metrics[:gauge_sub_batch_size].values # => {}
  2. Create a test job and pass it to the metrics instance:
    job = FactoryBot.create(:batched_background_migration_job, started_at: 5.minutes.ago, finished_at: Time.current)
    metrics.track(job)
  3. Verify the metrics class has the correct metric values:
    metrics.class.metrics[:gauge_batch_size].values[job.batched_migration.prometheus_labels].get # => 5
    metrics.class.metrics[:gauge_sub_batch_size].values[job.batched_migration.prometheus_labels].get # => 1

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Patrick Bair

Merge request reports

Loading