Skip to content

Commit 90251b2

Browse files
denis256agneum
authored andcommitted
fix(engine): update ReplicationLag format to be passed as integer
1 parent fe3b8ca commit 90251b2

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

engine/internal/retrieval/status/retrieval_status.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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

181177
func lastReplayedLsn(ctx context.Context, conn *pgx.Conn, query string) (string, string, error) {

engine/pkg/models/sync.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ type Sync struct {
66
StartedAt string `json:"startedAt,omitempty"`
77
LastReplayedLsn string `json:"lastReplayedLsn"`
88
LastReplayedLsnAt string `json:"lastReplayedLsnAt"`
9-
ReplicationLag string `json:"replicationLag"`
9+
ReplicationLag int `json:"replicationLag"`
1010
ReplicationUptime int `json:"replicationUptime"`
1111
}

0 commit comments

Comments
 (0)