Skip to content

Conversation

@fbac
Copy link
Collaborator

@fbac fbac commented Aug 13, 2025

Implement comprehensive migrator metrics collection and flow control with semaphore-based inflight tracking to make the migrator writer the source of truth

The migrator system now collects extensive metrics across the reader, transformer, and writer stages while implementing flow control through a semaphore-based inflight tracking system. The changes include:

  • Addition of 15 new migrator-specific metrics in pkg/metrics/migrator.go covering latency histograms, error counters, and sequence ID gauges
  • Modification of migrator.Migrator.migrationWorker method in pkg/metrics/migrator.go to implement semaphore-based flow control with batchSize*4 maximum inflight records and comprehensive metrics emission
  • Refactoring of migrator.ISourceReader.Fetch interface in pkg/migrator/types.go to remove max ID return value, making the writer the authoritative source for migration progress
  • Updates to retry logic in pkg/migrator/writer.go to include retry attempt metrics with table and destination labels

📍Where to Start

Start with the migrator.Migrator.migrationWorker method in pkg/migrator/migrator.go to understand the core flow control and metrics implementation changes.


Macroscope summarized 395fc63.

@fbac fbac requested a review from a team as a code owner August 13, 2025 13:35
@graphite-app
Copy link

graphite-app bot commented Aug 13, 2025

How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • Queue - adds this PR to the back of the merge queue
  • Hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

Borja Aranda added 2 commits August 14, 2025 12:16
### Instrument migrator service with Prometheus metrics for reader,
transformer, writer operations and end-to-end latency tracking
The migrator service now emits comprehensive Prometheus metrics across
all migration phases. The changes introduce new metric collectors in
[pkg/metrics/migrator.go](https://github.com/xmtp/xmtpd/pull/1050/files#diff-94129ac032a24ee9c3f1a8c70772094f4d1e3d5979baeb72a86b511833303bcb)
for tracking reader fetch durations, transformer errors, writer
latencies, retry attempts, rows migrated, sequence IDs, and end-to-end
migration latency. The `migrator.Migrator.migrationWorker` in
[pkg/migrator/migrator.go](https://github.com/xmtp/xmtpd/pull/1050/files#diff-ccb0d31b1e7491838a2e4c7f2f6523eed971d6f18d4c04f006e14e2767671693)
integrates these metrics throughout the migration loop, recording timing
data for database operations and tracking inflight records. The
`migrator.retry` function in
[pkg/migrator/writer.go](https://github.com/xmtp/xmtpd/pull/1050/files#diff-79de0174d18bbb97eb4c62be1eeec1e2132ff3060f5beafb3b8721044791b258)
now accepts table name and destination parameters to emit retry attempt
metrics. All new metrics are registered with the Prometheus collector in
[pkg/metrics/metrics.go](https://github.com/xmtp/xmtpd/pull/1050/files#diff-4bc91a74bc47b8467cdcd25a7e3fe1651dbe44907f478377eca31b982f444f23)
and documented in
[doc/metrics_catalog.md](https://github.com/xmtp/xmtpd/pull/1050/files#diff-76ce58ca7626239d9d1fcf2571f79d0337a091f72961c3ef6113b2f5fe06a994).

#### 📍Where to Start
Start with the `migrator.Migrator.migrationWorker` function in
[pkg/migrator/migrator.go](https://github.com/xmtp/xmtpd/pull/1050/files#diff-ccb0d31b1e7491838a2e4c7f2f6523eed971d6f18d4c04f006e14e2767671693)
to see how metrics are integrated throughout the migration loop.

----

_[Macroscope](https://app.macroscope.com) summarized a84c3b5._
@fbac fbac requested a review from a team as a code owner August 15, 2025 15:39
@fbac fbac merged commit 485339b into main Aug 19, 2025
10 checks passed
@fbac fbac deleted the 08-13-migration_progress branch August 19, 2025 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants