@@ -20,15 +20,20 @@ var (
2020
2121var typeMap = pgtype .NewMap ()
2222
23+ type XLogUpdater interface {
24+ UpdateXLogPos (l pq.LSN )
25+ }
26+
2327type Slot struct {
24- conn pq.Connection
25- metric metric.Metric
26- ticker * time.Ticker
27- statusSQL string
28- cfg Config
28+ conn pq.Connection
29+ metric metric.Metric
30+ logUpdater XLogUpdater
31+ ticker * time.Ticker
32+ statusSQL string
33+ cfg Config
2934}
3035
31- func NewSlot (ctx context.Context , dsn string , cfg Config , m metric.Metric ) (* Slot , error ) {
36+ func NewSlot (ctx context.Context , dsn string , cfg Config , m metric.Metric , updater XLogUpdater ) (* Slot , error ) {
3237 query := fmt .Sprintf ("SELECT slot_name, slot_type, active, active_pid, restart_lsn, confirmed_flush_lsn, wal_status, PG_CURRENT_WAL_LSN() AS current_lsn FROM pg_replication_slots WHERE slot_name = '%s';" , cfg .Name )
3338
3439 conn , err := pq .NewConnection (ctx , dsn )
@@ -37,11 +42,12 @@ func NewSlot(ctx context.Context, dsn string, cfg Config, m metric.Metric) (*Slo
3742 }
3843
3944 return & Slot {
40- cfg : cfg ,
41- conn : conn ,
42- statusSQL : query ,
43- metric : m ,
44- ticker : time .NewTicker (time .Millisecond * cfg .SlotActivityCheckerInterval ),
45+ cfg : cfg ,
46+ conn : conn ,
47+ statusSQL : query ,
48+ metric : m ,
49+ ticker : time .NewTicker (time .Millisecond * cfg .SlotActivityCheckerInterval ),
50+ logUpdater : updater ,
4551 }, nil
4652}
4753
@@ -109,6 +115,8 @@ func (s *Slot) Metrics(ctx context.Context) {
109115 s .metric .SetSlotRetainedWALSize (float64 (slotInfo .RetainedWALSize ))
110116 s .metric .SetSlotLag (float64 (slotInfo .Lag ))
111117
118+ s .logUpdater .UpdateXLogPos (slotInfo .CurrentLSN )
119+
112120 logger .Debug ("slot metrics" , "info" , slotInfo )
113121 }
114122}
0 commit comments