Skip to content

Commit 648f13c

Browse files
author
ffffwh
committed
metrics: delay: compare timestamp with tx execution time
1 parent 839ae5e commit 648f13c

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

drivers/mysql/mysql/extractor.go

+5-10
Original file line numberDiff line numberDiff line change
@@ -890,10 +890,10 @@ func (e *Extractor) setStatementFor() string {
890890
}
891891
type TimestampContext struct {
892892
stopCh chan struct{}
893-
Timestamp uint32
894893
TimestampCh chan uint32
895894
logger hclog.Logger
896895
f func() bool
896+
delay int64
897897
}
898898
func NewTimestampContext(stopCh chan struct{}, logger hclog.Logger, f func() bool) *TimestampContext {
899899
return &TimestampContext{
@@ -905,13 +905,8 @@ func NewTimestampContext(stopCh chan struct{}, logger hclog.Logger, f func() boo
905905
}
906906
}
907907
func (tsc *TimestampContext) GetDelay() (d int64) {
908-
if tsc.Timestamp == 0 {
909-
d = 0
910-
} else {
911-
d = time.Now().Unix() - int64(tsc.Timestamp)
912-
}
913-
tsc.logger.Debug("TimestampContext.GetDelay", "delay", d)
914-
return d
908+
tsc.logger.Debug("TimestampContext.GetDelay", "delay", tsc.delay)
909+
return tsc.delay
915910
}
916911
func (tsc *TimestampContext) Handle() {
917912
interval := 15 * time.Second
@@ -921,7 +916,7 @@ func (tsc *TimestampContext) Handle() {
921916
select {
922917
case ts := <-tsc.TimestampCh:
923918
tsc.logger.Debug("TimestampContext.Handle: got", "timestamp", ts)
924-
tsc.Timestamp = ts
919+
tsc.delay = time.Now().Unix() - int64(ts)
925920
if !t.Stop() {
926921
select {
927922
case <-t.C:
@@ -934,7 +929,7 @@ func (tsc *TimestampContext) Handle() {
934929
}
935930
case <-t.C:
936931
tsc.logger.Debug("delay: resetting timestamp")
937-
tsc.Timestamp = 0
932+
tsc.delay = 0
938933
case <-tsc.stopCh:
939934
return
940935
}

0 commit comments

Comments
 (0)