-
Notifications
You must be signed in to change notification settings - Fork 40
Feat: debug page for failed replication items in the queue #79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
fuziontech
wants to merge
5
commits into
main
Choose a base branch
from
replication_debug
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,4 +11,6 @@ COPY . . | |
|
||
RUN pnpm i | ||
|
||
VOLUME /frontend/src | ||
|
||
CMD ["pnpm", "vite", "--port", "3000", "--host"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,196 @@ | ||
import { Table, Button, notification, Typography, Tooltip, Spin, Select, Space } from 'antd' | ||
import { usePollingEffect } from '../../utils/usePollingEffect' | ||
import React, { useState, useEffect } from 'react' | ||
import { ColumnType } from 'antd/es/table' | ||
|
||
const { Paragraph } = Typography | ||
|
||
interface ClusterNode { | ||
cluster: string | ||
shard_num: number | ||
shard_weight: number | ||
replica_num: number | ||
host_name: string | ||
host_address: string | ||
port: number | ||
is_local: number | ||
user: string | ||
default_database: string | ||
errors_count: number | ||
slowdowns_count: number | ||
estimated_recovery_time: number | ||
} | ||
|
||
interface Cluster { | ||
cluster: string | ||
nodes: ClusterNode[] | ||
} | ||
|
||
interface ReplicationQueueItem { | ||
host_name: string | ||
database: string | ||
table: string | ||
position: number | ||
error: string | ||
last_attempt_time: string | ||
num_attempts: number | ||
type: string | ||
postpone_reason: string | ||
postpone: string | ||
} | ||
|
||
export default function Replication() { | ||
const [replicationQueue, setReplicationQueue] = useState<ReplicationQueueItem[]>([]) | ||
const [loadingReplication, setLoadingReplication] = useState(false) | ||
const [selectedCluster, setSelectedCluster] = useState<string>('') | ||
const [clusters, setClusters] = useState<Cluster[]>([]) | ||
const [loadingClusters, setLoadingClusters] = useState(false) | ||
|
||
useEffect(() => { | ||
const fetchClusters = async () => { | ||
setLoadingClusters(true) | ||
try { | ||
const res = await fetch('/api/clusters') | ||
const resJson: Cluster[] = await res.json() | ||
setClusters(resJson) | ||
if (resJson.length > 0) { | ||
setSelectedCluster(resJson[0].cluster) | ||
} | ||
} catch (err) { | ||
notification.error({ | ||
message: 'Failed to fetch clusters', | ||
description: 'Please try again later', | ||
}) | ||
} | ||
setLoadingClusters(false) | ||
} | ||
fetchClusters() | ||
}, []) | ||
|
||
const columns: ColumnType<ReplicationQueueItem>[] = [ | ||
{ | ||
title: 'Host', | ||
dataIndex: 'host_name', | ||
key: 'host_name', | ||
}, | ||
{ | ||
title: 'Database', | ||
dataIndex: 'database', | ||
key: 'database', | ||
}, | ||
{ | ||
title: 'Table', | ||
dataIndex: 'table', | ||
key: 'table', | ||
}, | ||
{ | ||
title: 'Type', | ||
dataIndex: 'type', | ||
key: 'type', | ||
}, | ||
{ | ||
title: 'Last Postpone', | ||
dataIndex: 'last_postpone_time', | ||
key: 'postpone_time', | ||
}, | ||
{ | ||
title: 'Postpone Reason', | ||
dataIndex: 'postpone_reason', | ||
key: 'postpone_reason', | ||
render: (reason: string) => ( | ||
reason ? <Paragraph | ||
style={{ maxWidth: '400px', color: 'orange' }} | ||
ellipsis={{ | ||
rows: 2, | ||
expandable: true, | ||
}} | ||
> | ||
{reason} | ||
</Paragraph> : null | ||
), | ||
}, | ||
{ | ||
title: 'Last Attempt', | ||
dataIndex: 'last_attempt_time', | ||
key: 'last_attempt_time', | ||
}, | ||
{ | ||
title: 'Exception', | ||
dataIndex: 'last_exception', | ||
key: 'last_exception', | ||
render: (last_exception: string) => ( | ||
last_exception ? <Paragraph | ||
style={{ maxWidth: '400px', color: 'red' }} | ||
ellipsis={{ | ||
rows: 2, | ||
expandable: true, | ||
}} | ||
> | ||
{last_exception} | ||
</Paragraph> : null | ||
), | ||
}, | ||
{ | ||
title: 'Attempts', | ||
dataIndex: 'num_attempts', | ||
key: 'num_attempts', | ||
}, | ||
] | ||
|
||
usePollingEffect( | ||
async () => { | ||
if (!selectedCluster) return | ||
|
||
setLoadingReplication(true) | ||
try { | ||
const res = await fetch(`/api/replication/?cluster=${selectedCluster}`) | ||
const resJson: ReplicationQueueItem[] = await res.json() | ||
// Filter for failed items only | ||
const failedItems = resJson.filter((item) => item.error) | ||
setReplicationQueue(failedItems) | ||
} catch (err) { | ||
notification.error({ | ||
message: 'Failed to fetch replication queue', | ||
description: 'Please try again later', | ||
}) | ||
} | ||
setLoadingReplication(false) | ||
}, | ||
[selectedCluster], | ||
{ interval: 5000 } | ||
) | ||
|
||
return ( | ||
<> | ||
<Space direction="vertical" size="large" style={{ width: '100%' }}> | ||
<Space> | ||
<h1 style={{ margin: 0 }}> | ||
{`${replicationQueue.length}`} Failed Replication Queue Items | ||
</h1> | ||
{loadingReplication && <Spin />} | ||
</Space> | ||
|
||
<Select | ||
style={{ width: 200 }} | ||
value={selectedCluster} | ||
onChange={setSelectedCluster} | ||
loading={loadingClusters} | ||
placeholder="Select a cluster" | ||
> | ||
{clusters.map((cluster) => ( | ||
<Select.Option key={cluster.cluster} value={cluster.cluster}> | ||
{cluster.cluster} | ||
</Select.Option> | ||
))} | ||
</Select> | ||
|
||
<Table | ||
columns={columns} | ||
dataSource={replicationQueue} | ||
loading={replicationQueue.length === 0 && loadingReplication} | ||
rowKey={(record) => `${record.host_name}-${record.table}-${record.position}`} | ||
/> | ||
</Space> | ||
</> | ||
) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we also retrieve the
last_exception_time
? It's useful to compare the time the exception happened with thelast_attempt
time. Also, having thesource_replica
gives a hint of which host could be the source of the issue. 🕵️