Skip to content

StatsD instrumentation: binlog throughput and transaction metrics - #1800

Open
grodowski wants to merge 5 commits into
github:masterfrom
Shopify:grodowski/binlog-metrics-upstream
Open

grodowski wants to merge 5 commits into
github:masterfrom
Shopify:grodowski/binlog-metrics-upstream

Conversation

@grodowski

Copy link
Copy Markdown
Contributor

Related issue: #1672

Description

Extends the StatsD instrumentation from #1701 with binlog processing metrics:

  • Processed, filtered and consumed row-event counters, plus consumed logical-row counts.
  • Rows per event/transaction, row events per transaction, MySQL GTID transaction length and commit-group size.
  • Time spent delivering row events to the consumer channel.

Respects header-only filtering: unrelated payloads remain undecoded, and unknown row counts are not emitted. UPDATE before/after images count as one logical row. MySQL and MariaDB GTID handling remain compatible.

Regression coverage checks decoded and header-filtered events, original/changelog tables, UPDATE pairs and transaction boundaries.

In case this PR introduced Go code changes:

  • contributed code is using same conventions as original code
  • script/cibuild returns with no formatting errors, build errors or unit test errors.

forge33 and others added 5 commits October 19, 2026 16:35
Build and golangci-lint failed because emit_test.go referenced histogramCountSpy without defining it.

Co-authored-by: Cursor <cursoragent@cursor.com>
Record counts on the existing histogramSpy instead of adding a duplicate spy type.

Co-authored-by: Cursor <cursoragent@cursor.com>
Port the metric-specific compatibility fix and MySQL/MariaDB regression tests from #56.

Co-authored-by: Bastian Bartmann <bastian.bartmann@shopify.com>
Count row events independently from decoded rows. Retire the processed and filtered row counters while preserving all event counters and consumed logical-row counts.

Add parser-to-streamer regressions for skipped payloads, original/changelog rows, update pairs, and transaction coordinates. Adapt test fixtures to the upstream streamer API.

(cherry picked from commit 6e43dc4)
Copilot AI dynamic review requested due to automatic review settings November 6, 2026 11:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Transaction metrics are miscounted or lost across commit grouping, file-position mode, and reconnects, while table tags introduce unbounded cardinality and malformed labels.

7 open issues
What changed in this PR

Extends the existing StatsD instrumentation with binlog throughput and transaction diagnostics for monitoring migration health, building on #1701.

Changes:

  • Adds row-event counters, logical-row counts, and channel-delivery timing.
  • Records transaction sizes and MySQL GTID metadata, with MariaDB transaction-boundary handling.
  • Adds regression coverage for table filtering, header-only events, UPDATE pairs, and transaction boundaries.
File Description
go/​metrics/​emit.go Adds binlog counter, histogram, and gauge helpers.
go/​metrics/​emit_test.go Tests metric values, tags, and nil-safe behavior.
go/​binlog/​gomysql_reader.go Wires metrics into row processing and transaction boundaries.
go/​binlog/​gomysql_reader_test.go Adds MySQL and MariaDB GTID metric coverage.
go/​binlog/​gomysql_reader_metrics_test.go Tests decoded and header-filtered row events across tables and transaction boundaries.
go/​binlog/​binlog_dml_event.go Adds DML metric tags and logical-row counting helpers.
go/​binlog/​binlog_dml_event_test.go Tests DML tags and logical-row counts, including UPDATE pairs.

Review effort: Max (auto)

return
}
emit := gmr.migrationContext.Metrics
metrics.RecordBinlogTransactionSize(emit, gmr.transactionRowEventTotal, gmr.transactionRowTotal)
Comment on lines +153 to +156
if event.LastCommitted != gmr.previousLastCommitted {
metrics.RecordUnfilteredCommitGroupSize(emit, float64(event.SequenceNumber-event.LastCommitted))
}
gmr.previousLastCommitted = event.LastCommitted
Comment on lines +222 to +224
if relevant {
metrics.RecordBinlogStreamerBlockedOnOutChannel(emit, time.Since(beforeChannel))
}
if err != nil {
return err
}
gmr.onGTIDEvent(gtidEvent)
Comment on lines +291 to +293
if !gmr.migrationContext.UseGTIDs {
gmr.flushTransactionMetrics()
}
Comment thread go/metrics/emit.go
Comment on lines +181 to +190
emit.Count("binlog_events", 1, "type:processed", "table:"+tableName)
}

// RecordBinlogRowsEventFiltered counts a rows event on an unrelated table.
// Header-only filtering leaves its row count unknown, so no rows are counted.
func RecordBinlogRowsEventFiltered(emit Emitter, tableName string) {
if emit == nil || tableName == "" {
return
}
emit.Count("binlog_events", 1, "type:filtered", "table:"+tableName)
Comment thread go/metrics/emit.go
if emit == nil || tableName == "" || binlogEventType == "" {
return
}
emit.Count("binlog_events", 1, "type:consumed", "table:"+tableName, "binlog_event_type:"+binlogEventType)

This branch has not been deployed

No deployments
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