Skip to content

Commit

Permalink
slot lag graph: also have lsn graph (#2199)
Browse files Browse the repository at this point in the history
Unfortunately we aren't tracking latest wal so no line to show how far behind confirmed is from latest
  • Loading branch information
serprex authored Oct 28, 2024
1 parent 556e95e commit 9b9062b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 13 deletions.
15 changes: 11 additions & 4 deletions flow/cmd/peer_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,8 @@ func (h *FlowRequestHandler) GetSlotLagHistory(
ctx context.Context,
req *protos.GetSlotLagHistoryRequest,
) (*protos.GetSlotLagHistoryResponse, error) {
rows, err := h.pool.Query(ctx, `select updated_at, slot_size
rows, err := h.pool.Query(ctx, `select updated_at, slot_size,
coalesce(redo_lsn,''), coalesce(restart_lsn,''), coalesce(confirmed_flush_lsn,'')
from peerdb_stats.peer_slot_size
where slot_size is not null
and peer_name = $1
Expand All @@ -374,12 +375,18 @@ func (h *FlowRequestHandler) GetSlotLagHistory(
points, err := pgx.CollectRows(rows, func(row pgx.CollectableRow) (*protos.SlotLagPoint, error) {
var updatedAt time.Time
var slotSize int64
if err := row.Scan(&updatedAt, &slotSize); err != nil {
var redoLSN string
var restartLSN string
var confirmedFlushLSN string
if err := row.Scan(&updatedAt, &slotSize, &redoLSN, &restartLSN, &confirmedFlushLSN); err != nil {
return nil, err
}
return &protos.SlotLagPoint{
UpdatedAt: float64(updatedAt.UnixMilli()),
SlotSize: float64(slotSize) / 1000.0,
Time: float64(updatedAt.UnixMilli()),
Size: float64(slotSize) / 1000.0,
RedoLSN: redoLSN,
RestartLSN: restartLSN,
ConfirmedLSN: confirmedFlushLSN,
}, nil
})
if err != nil {
Expand Down
7 changes: 5 additions & 2 deletions protos/route.proto
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,11 @@ message SlotInfo {
}

message SlotLagPoint {
double updated_at = 1;
double slot_size = 2;
double time = 1;
double size = 2;
string redo_lSN = 3;
string restart_lSN = 4;
string confirmed_lSN = 5;
}
message GetSlotLagHistoryRequest {
string peer_name = 1;
Expand Down
32 changes: 25 additions & 7 deletions ui/app/peers/[peerName]/lagGraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ type LagGraphProps = {
peerName: string;
};

function parseLSN(lsn: string): number {
if (!lsn) return 0;
const [lsn1, lsn2] = lsn.split('/');
return Number(
(BigInt(parseInt(lsn1)) << BigInt(32)) | BigInt(parseInt(lsn2))
);
}

export default function LagGraph({ peerName }: LagGraphProps) {
const [slotNames, setSlotNames] = useState<string[]>([]);
const [mounted, setMounted] = useState(false);
Expand All @@ -30,9 +38,10 @@ export default function LagGraph({ peerName }: LagGraphProps) {
);
const [selectedSlot, setSelectedSlot] = useState<string>(defaultSlot);
const [loading, setLoading] = useState(false);
let [timeSince, setTimeSince] = useState<TimeAggregateTypes>(
const [timeSince, setTimeSince] = useState<TimeAggregateTypes>(
TimeAggregateTypes.HOUR
);
const [showLsn, setShowLsn] = useState(false);

const fetchSlotNames = useCallback(async () => {
const slots = await getSlotData(peerName);
Expand All @@ -58,10 +67,13 @@ export default function LagGraph({ peerName }: LagGraphProps) {
const points: GetSlotLagHistoryResponse = await pointsRes.json();
setLagPoints(
points.data
.sort((x, y) => x.updatedAt - y.updatedAt)
.sort((x, y) => x.time - y.time)
.map((data) => ({
time: moment(data.updatedAt).format('MMM Do HH:mm'),
'Lag in GB': data.slotSize,
time: moment(data.time).format('MMM Do HH:mm'),
'Lag in GB': data.size,
redoLSN: parseLSN(data.redoLSN),
restartLSN: parseLSN(data.restartLSN),
confirmedLSN: parseLSN(data.confirmedLSN),
}))
);
}
Expand Down Expand Up @@ -121,7 +133,11 @@ export default function LagGraph({ peerName }: LagGraphProps) {
}
theme={SelectTheme}
/>

<input
type='button'
value={showLsn ? 'Show LSN' : 'Show Lag'}
onClick={() => setShowLsn((val) => !val)}
/>
<ReactSelect
id={timeSince}
placeholder='Select a timeframe'
Expand All @@ -140,8 +156,10 @@ export default function LagGraph({ peerName }: LagGraphProps) {
<LineChart
index='time'
data={lagPoints}
categories={['Lag in GB']}
colors={['rose']}
categories={
showLsn ? ['redoLSN', 'restartLSN', 'confirmedLSN'] : ['Lag in GB']
}
colors={showLsn ? ['maroon', 'red', 'lime'] : ['rose']}
showXAxis={false}
/>
)}
Expand Down

0 comments on commit 9b9062b

Please sign in to comment.