@@ -97,30 +97,26 @@ func FetchSyncMetrics(ctx context.Context, config *global.Config, socketPath str
9797 return & sync , fmt .Errorf ("failed to read Postgres version %w" , err )
9898 }
9999
100- var replicationLag string
101-
102100 var query = lag9xQuery
103101
104102 if pgVersion >= pgVersion10 {
105103 query = lagQuery
106104 }
107105
108- replicationLag , err = lag (ctx , conn , query )
106+ replicationLag , err : = lag (ctx , conn , query )
109107 if err != nil {
110108 log .Warn ("Failed to fetch replication lag" , err )
111109 } else {
112110 sync .ReplicationLag = replicationLag
113111 }
114112
115- var replayedLsn , lastReplayedLsnAt string
116-
117113 query = lastReplayedLsn9xQuery
118114
119115 if pgVersion >= pgVersion10 {
120116 query = lastReplayedLsnQuery
121117 }
122118
123- lastReplayedLsnAt , replayedLsn , err = lastReplayedLsn (ctx , conn , query )
119+ lastReplayedLsnAt , replayedLsn , err : = lastReplayedLsn (ctx , conn , query )
124120 if err != nil {
125121 log .Warn ("Failed to fetch last replayed lsn" , err )
126122 } else {
@@ -166,16 +162,16 @@ func version(ctx context.Context, conn *pgx.Conn) (int, error) {
166162 return pgVersion , nil
167163}
168164
169- func lag (ctx context.Context , conn * pgx.Conn , query string ) (string , error ) {
170- var lagSec sql. NullString
165+ func lag (ctx context.Context , conn * pgx.Conn , query string ) (int , error ) {
166+ var lagSec int
171167
172168 row := conn .QueryRow (ctx , query )
173169
174170 if err := row .Scan (& lagSec ); err != nil {
175- return "" , fmt .Errorf ("failed to read replication lag: %w" , err )
171+ return 0 , fmt .Errorf ("failed to read replication lag: %w" , err )
176172 }
177173
178- return lagSec . String , nil
174+ return lagSec , nil
179175}
180176
181177func lastReplayedLsn (ctx context.Context , conn * pgx.Conn , query string ) (string , string , error ) {
0 commit comments