Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
https://linear.app/unleash/issue/2-512/exploration-network-overview-represented-as-a-flow-chart <img width="1307" alt="image" src="https://user-images.githubusercontent.com/14320932/208110067-294a0b91-d52e-49d1-9024-fa5e8530e2d8.png">
- Loading branch information
Showing
14 changed files
with
581 additions
and
73 deletions.
There are no files selected for viewing
This file contains 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 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 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,63 @@ | ||
import { NetworkOverview } from './NetworkOverview/NetworkOverview'; | ||
import { NetworkTraffic } from './NetworkTraffic/NetworkTraffic'; | ||
import AdminMenu from '../menu/AdminMenu'; | ||
import { styled, Tab, Tabs } from '@mui/material'; | ||
import { Route, Routes, useLocation } from 'react-router-dom'; | ||
import { CenteredNavLink } from '../menu/CenteredNavLink'; | ||
import { PageContent } from 'component/common/PageContent/PageContent'; | ||
|
||
const StyledPageContent = styled(PageContent)(() => ({ | ||
'.page-header': { | ||
padding: 0, | ||
}, | ||
})); | ||
|
||
const tabs = [ | ||
{ | ||
label: 'Overview', | ||
path: '/admin/network', | ||
}, | ||
{ | ||
label: 'Traffic', | ||
path: '/admin/network/traffic', | ||
}, | ||
]; | ||
|
||
export const Network = () => { | ||
const { pathname } = useLocation(); | ||
|
||
return ( | ||
<div> | ||
<AdminMenu /> | ||
<StyledPageContent | ||
headerClass="page-header" | ||
header={ | ||
<Tabs | ||
value={pathname} | ||
indicatorColor="primary" | ||
textColor="primary" | ||
variant="scrollable" | ||
allowScrollButtonsMobile | ||
> | ||
{tabs.map(({ label, path }) => ( | ||
<Tab | ||
key={label} | ||
value={path} | ||
label={ | ||
<CenteredNavLink to={path}> | ||
<span>{label}</span> | ||
</CenteredNavLink> | ||
} | ||
/> | ||
))} | ||
</Tabs> | ||
} | ||
> | ||
<Routes> | ||
<Route path="traffic" element={<NetworkTraffic />} /> | ||
<Route path="*" element={<NetworkOverview />} /> | ||
</Routes> | ||
</StyledPageContent> | ||
</div> | ||
); | ||
}; |
68 changes: 68 additions & 0 deletions
68
frontend/src/component/admin/network/NetworkOverview/NetworkOverview.tsx
This file contains 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,68 @@ | ||
import { usePageTitle } from 'hooks/usePageTitle'; | ||
import { Mermaid } from 'component/common/Mermaid/Mermaid'; | ||
import { useInstanceMetrics } from 'hooks/api/getters/useInstanceMetrics/useInstanceMetrics'; | ||
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender'; | ||
import { Alert, styled } from '@mui/material'; | ||
|
||
const StyledMermaid = styled(Mermaid)(({ theme }) => ({ | ||
'#mermaid .node rect': { | ||
fill: theme.palette.secondary.light, | ||
stroke: theme.palette.secondary.border, | ||
}, | ||
})); | ||
|
||
interface INetworkApp { | ||
label?: string; | ||
reqs: string; | ||
type: string; | ||
} | ||
|
||
export const NetworkOverview = () => { | ||
usePageTitle('Network - Overview'); | ||
const { metrics } = useInstanceMetrics(); | ||
|
||
const apps: INetworkApp[] = []; | ||
if (Boolean(metrics)) { | ||
Object.keys(metrics).forEach(metric => { | ||
apps.push( | ||
...( | ||
metrics[metric].data?.result | ||
?.map(result => ({ | ||
label: result.metric?.appName, | ||
reqs: parseFloat( | ||
result.values?.[ | ||
result.values?.length - 1 | ||
][1].toString() || '0' | ||
).toFixed(2), | ||
type: metric.split('Metrics')[0], | ||
})) | ||
.filter(app => app.label !== 'undefined') || [] | ||
).filter(app => app.reqs !== '0.00') | ||
); | ||
}); | ||
} | ||
|
||
const graph = ` | ||
graph TD | ||
subgraph _[ ] | ||
direction BT | ||
Unleash(<img src='https://www.getunleash.io/logos/unleash_glyph_pos.svg' width='60' height='60' /><br/>Unleash) | ||
${apps | ||
.map( | ||
({ label, reqs, type }, i) => | ||
`app-${i}(${label}) -- ${reqs} req/s<br>${type} --> Unleash` | ||
) | ||
.join('\n')} | ||
end | ||
`; | ||
|
||
return ( | ||
<ConditionallyRender | ||
condition={apps.length === 0} | ||
show={<Alert severity="warning">No data available.</Alert>} | ||
elseShow={<StyledMermaid>{graph}</StyledMermaid>} | ||
/> | ||
); | ||
}; | ||
|
||
export default NetworkOverview; |
This file contains 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 was deleted.
Oops, something went wrong.
This file contains 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,43 @@ | ||
import { styled } from '@mui/material'; | ||
import mermaid from 'mermaid'; | ||
import { useEffect } from 'react'; | ||
|
||
const StyledMermaid = styled('div')(({ theme }) => ({ | ||
display: 'flex', | ||
justifyContent: 'center', | ||
'#mermaid .edgeLabel': { | ||
backgroundColor: theme.palette.background.paper, | ||
}, | ||
})); | ||
|
||
mermaid.initialize({ | ||
theme: 'default', | ||
themeCSS: ` | ||
.clusters #_ rect { | ||
fill: transparent; | ||
stroke: transparent; | ||
} | ||
`, | ||
}); | ||
|
||
interface IMermaidProps { | ||
className?: string; | ||
children: string; | ||
} | ||
|
||
export const Mermaid = ({ className = '', children }: IMermaidProps) => { | ||
useEffect(() => { | ||
mermaid.render('mermaid', children, (svgCode: string) => { | ||
const mermaidDiv = document.querySelector('.mermaid'); | ||
if (mermaidDiv) { | ||
mermaidDiv.innerHTML = svgCode; | ||
} | ||
}); | ||
}, [children]); | ||
|
||
return ( | ||
<StyledMermaid className={`mermaid ${className}`}> | ||
{children} | ||
</StyledMermaid> | ||
); | ||
}; |
Oops, something went wrong.