|
| 1 | +/** |
| 2 | + * Copyright 2026 Antrea Authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +import { CdsCard } from '@cds/react/card'; |
| 18 | +import { CdsButton } from '@cds/react/button'; |
| 19 | +import { CdsDivider } from '@cds/react/divider'; |
| 20 | +import { NodeLink, NodeLatencyModel, nodeLinksFor } from '../routes/nodelatency-util'; |
| 21 | + |
| 22 | +function fmtRtt(link: NodeLink): string { |
| 23 | + return link.down || link.rttMs === undefined ? 'N/A' : link.rttMs.toFixed(3); |
| 24 | +} |
| 25 | + |
| 26 | +function latestRecv(link: NodeLink): string { |
| 27 | + const times = link.targets.map(t => t.lastRecvTime).filter((t): t is string => !!t).sort(); |
| 28 | + const t = times.length ? times[times.length - 1] : undefined; |
| 29 | + return t ? new Date(t).toLocaleString() : 'None'; |
| 30 | +} |
| 31 | + |
| 32 | +function targetIPs(link: NodeLink): string { |
| 33 | + return link.targets.map(t => t.targetIP).join(', ') || 'None'; |
| 34 | +} |
| 35 | + |
| 36 | +function LinkTable(props: { title: string, peerHeader: string, links: NodeLink[], peerOf: (l: NodeLink) => string }) { |
| 37 | + return ( |
| 38 | + <div cds-layout="vertical gap:sm"> |
| 39 | + <div cds-text="section">{props.title}</div> |
| 40 | + {props.links.length === 0 ? ( |
| 41 | + <p cds-text="secondary">No {props.title.toLowerCase()}.</p> |
| 42 | + ) : ( |
| 43 | + <table cds-table="border:all" cds-text="center body"> |
| 44 | + <thead> |
| 45 | + <tr> |
| 46 | + <th>{props.peerHeader}</th> |
| 47 | + <th>Status</th> |
| 48 | + <th>Latency (ms)</th> |
| 49 | + <th>Target IP</th> |
| 50 | + <th>Last Recv</th> |
| 51 | + </tr> |
| 52 | + </thead> |
| 53 | + <tbody> |
| 54 | + {props.links.map((link, idx) => ( |
| 55 | + <tr key={idx}> |
| 56 | + <td>{props.peerOf(link)}</td> |
| 57 | + <td style={link.down ? { color: '#e12200' } : undefined}>{link.down ? 'Down' : 'Up'}</td> |
| 58 | + <td>{fmtRtt(link)}</td> |
| 59 | + <td>{targetIPs(link)}</td> |
| 60 | + <td>{latestRecv(link)}</td> |
| 61 | + </tr> |
| 62 | + ))} |
| 63 | + </tbody> |
| 64 | + </table> |
| 65 | + )} |
| 66 | + </div> |
| 67 | + ); |
| 68 | +} |
| 69 | + |
| 70 | +export function NodeDetailPanel(props: { model: NodeLatencyModel, node: string, onClose: () => void }) { |
| 71 | + const { egress, ingress } = nodeLinksFor(props.model.links, props.node); |
| 72 | + const health = props.model.health.get(props.node); |
| 73 | + |
| 74 | + return ( |
| 75 | + <CdsCard> |
| 76 | + <div cds-layout="vertical gap:md"> |
| 77 | + <div cds-layout="horizontal align:vertical-center gap:md"> |
| 78 | + <div cds-text="section" cds-layout="align:left">Node: {props.node}</div> |
| 79 | + <CdsButton type="button" action="outline" size="sm" onClick={props.onClose}>Clear</CdsButton> |
| 80 | + </div> |
| 81 | + {health && ( |
| 82 | + <p cds-text="secondary"> |
| 83 | + Egress: {health.egressTotal - health.egressDown}/{health.egressTotal} up |
| 84 | + {' '}·{' '} |
| 85 | + Ingress: {health.ingressTotal - health.ingressDown}/{health.ingressTotal} up |
| 86 | + </p> |
| 87 | + )} |
| 88 | + <CdsDivider cds-card-remove-margin></CdsDivider> |
| 89 | + <LinkTable |
| 90 | + title="Egress Links" |
| 91 | + peerHeader="Target Node" |
| 92 | + links={egress} |
| 93 | + peerOf={l => l.targetNode} |
| 94 | + /> |
| 95 | + <LinkTable |
| 96 | + title="Ingress Links" |
| 97 | + peerHeader="Source Node" |
| 98 | + links={ingress} |
| 99 | + peerOf={l => l.sourceNode} |
| 100 | + /> |
| 101 | + </div> |
| 102 | + </CdsCard> |
| 103 | + ); |
| 104 | +} |
| 105 | + |
| 106 | +export function ProblemNodesPanel(props: { model: NodeLatencyModel, onSelect: (node: string) => void }) { |
| 107 | + const problems = props.model.problemNodes; |
| 108 | + if (problems.length === 0) return null; |
| 109 | + |
| 110 | + return ( |
| 111 | + <CdsCard> |
| 112 | + <div cds-layout="vertical gap:md"> |
| 113 | + <div cds-text="section" style={{ color: '#e12200' }}> |
| 114 | + Problem Nodes ({problems.length}) |
| 115 | + </div> |
| 116 | + <CdsDivider cds-card-remove-margin></CdsDivider> |
| 117 | + <table cds-table="border:all" cds-text="center body"> |
| 118 | + <thead> |
| 119 | + <tr> |
| 120 | + <th>Node</th> |
| 121 | + <th>Egress Down</th> |
| 122 | + <th>Ingress Down</th> |
| 123 | + <th></th> |
| 124 | + </tr> |
| 125 | + </thead> |
| 126 | + <tbody> |
| 127 | + {problems.map(h => ( |
| 128 | + <tr key={h.node}> |
| 129 | + <td>{h.node}</td> |
| 130 | + <td>{h.egressDown}/{h.egressTotal}</td> |
| 131 | + <td>{h.ingressDown}/{h.ingressTotal}</td> |
| 132 | + <td> |
| 133 | + <CdsButton type="button" action="flat" size="sm" onClick={() => props.onSelect(h.node)}> |
| 134 | + Inspect |
| 135 | + </CdsButton> |
| 136 | + </td> |
| 137 | + </tr> |
| 138 | + ))} |
| 139 | + </tbody> |
| 140 | + </table> |
| 141 | + </div> |
| 142 | + </CdsCard> |
| 143 | + ); |
| 144 | +} |
0 commit comments