@@ -16,6 +16,7 @@ import (
1616
1717 "github.com/github/gh-ost/go/base"
1818 "github.com/github/gh-ost/go/binlog"
19+ "github.com/github/gh-ost/go/metrics"
1920 "github.com/github/gh-ost/go/sql"
2021
2122 "context"
@@ -893,22 +894,27 @@ func (apl *Applier) CalculateNextIterationRangeEndValues() (hasFurtherRange bool
893894 return hasFurtherRange , err
894895 }
895896
897+ queryStartTime := time .Now ()
896898 rows , err := apl .db .Query (query , explodedArgs ... )
897899 if err != nil {
900+ metrics .RecordQueryDuration (apl .migrationContext .Metrics , "source" , "range_select" , time .Since (queryStartTime ), err )
898901 return hasFurtherRange , err
899902 }
900903 defer rows .Close ()
901904
902905 iterationRangeMaxValues := sql .NewColumnValues (apl .migrationContext .UniqueKey .Len ())
903906 for rows .Next () {
904907 if err = rows .Scan (iterationRangeMaxValues .ValuesPointers ... ); err != nil {
908+ metrics .RecordQueryDuration (apl .migrationContext .Metrics , "source" , "range_select" , time .Since (queryStartTime ), err )
905909 return hasFurtherRange , err
906910 }
907911 hasFurtherRange = true
908912 }
909913 if err = rows .Err (); err != nil {
914+ metrics .RecordQueryDuration (apl .migrationContext .Metrics , "source" , "range_select" , time .Since (queryStartTime ), err )
910915 return hasFurtherRange , err
911916 }
917+ metrics .RecordQueryDuration (apl .migrationContext .Metrics , "source" , "range_select" , time .Since (queryStartTime ), nil )
912918 if hasFurtherRange {
913919 apl .migrationContext .MigrationIterationRangeMaxValues = iterationRangeMaxValues
914920 return hasFurtherRange , nil
@@ -956,7 +962,9 @@ func (apl *Applier) ApplyIterationInsertQuery() (chunkSize int64, rowsAffected i
956962 if _ , err := tx .Exec (sessionQuery ); err != nil {
957963 return nil , err
958964 }
965+ queryStartTime := time .Now ()
959966 result , err := tx .Exec (query , explodedArgs ... )
967+ metrics .RecordQueryDuration (apl .migrationContext .Metrics , "target" , "chunk_copy" , time .Since (queryStartTime ), err )
960968 if err != nil {
961969 return nil , err
962970 }
@@ -1669,13 +1677,16 @@ func (apl *Applier) ApplyDMLEventQueries(dmlEvents [](*binlog.BinlogDMLEvent)) e
16691677 // in the batch. SHOW WARNINGS only shows warnings from the last statement in a
16701678 // multi-statement query, so we interleave SHOW WARNINGS after each DML statement.
16711679 if apl .migrationContext .PanicOnWarnings {
1680+ queryStartTime := time .Now ()
16721681 totalDelta , err = apl .executeBatchWithWarningChecking (ctx , tx , buildResults )
1682+ metrics .RecordQueryDuration (apl .migrationContext .Metrics , "target" , "binlog_apply" , time .Since (queryStartTime ), err )
16731683 if err != nil {
16741684 return rollback (err )
16751685 }
16761686 } else {
16771687 // Fast path: batch together DML queries into multi-statements to minimize network trips.
16781688 // We use the raw driver connection to access the rows affected for each statement.
1689+ queryStartTime := time .Now ()
16791690 execErr := conn .Raw (func (driverConn any ) error {
16801691 ex := driverConn .(driver.ExecerContext )
16811692 nvc := driverConn .(driver.NamedValueChecker )
@@ -1709,6 +1720,7 @@ func (apl *Applier) ApplyDMLEventQueries(dmlEvents [](*binlog.BinlogDMLEvent)) e
17091720 return nil
17101721 })
17111722
1723+ metrics .RecordQueryDuration (apl .migrationContext .Metrics , "target" , "binlog_apply" , time .Since (queryStartTime ), execErr )
17121724 if execErr != nil {
17131725 return rollback (execErr )
17141726 }
0 commit comments