forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[APM] Experimental Service Map front end (elastic#46497)
Add service map tabs on the main APM screen and for individual services. This is not yet hooked up to work with back-end data, so it always shows the same hard-coded graph. This is experimental, so you must have x-pack.apm.serviceMapEnabled: true in your Kibana config for it to show up. Also add "PSF" to the list of allowed licenses since a new dependency added uses this license (it's on the [green list](https://github.com/elastic/open-source/blob/master/elastic-product-policy.md#green-list).) Fixes elastic#44890 Fixes elastic#44853
- Loading branch information
Showing
24 changed files
with
2,190 additions
and
425 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
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
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
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
108 changes: 108 additions & 0 deletions
108
x-pack/legacy/plugins/apm/public/components/app/ServiceMap/Controls.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,108 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React, { useContext, useState, useEffect } from 'react'; | ||
import { EuiButtonIcon, EuiPanel } from '@elastic/eui'; | ||
import theme from '@elastic/eui/dist/eui_theme_light.json'; | ||
import styled from 'styled-components'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { CytoscapeContext } from './Cytoscape'; | ||
import { FullscreenPanel } from './FullscreenPanel'; | ||
|
||
const Container = styled('div')` | ||
left: ${theme.gutterTypes.gutterMedium}; | ||
position: absolute; | ||
top: ${theme.gutterTypes.gutterSmall}; | ||
`; | ||
|
||
const Button = styled(EuiButtonIcon)` | ||
display: block; | ||
margin: ${theme.paddingSizes.xs}; | ||
`; | ||
|
||
const ZoomInButton = styled(Button)` | ||
margin-bottom: ${theme.paddingSizes.s}; | ||
`; | ||
|
||
const ZoomPanel = styled(EuiPanel)` | ||
margin-bottom: ${theme.paddingSizes.s}; | ||
`; | ||
|
||
const duration = parseInt(theme.euiAnimSpeedFast, 10); | ||
const steps = 5; | ||
|
||
function doZoom(cy: cytoscape.Core | undefined, increment: number) { | ||
if (cy) { | ||
const level = cy.zoom() + increment; | ||
cy.animate({ | ||
duration, | ||
zoom: { level, position: cy.$('.primary').position() } | ||
}); | ||
} | ||
} | ||
|
||
export function Controls() { | ||
const cy = useContext(CytoscapeContext); | ||
|
||
const [zoom, setZoom] = useState((cy && cy.zoom()) || 1); | ||
|
||
useEffect(() => { | ||
if (cy) { | ||
cy.on('zoom', event => { | ||
setZoom(event.cy.zoom()); | ||
}); | ||
} | ||
}, [cy]); | ||
|
||
function zoomIn() { | ||
doZoom(cy, increment); | ||
} | ||
|
||
function zoomOut() { | ||
doZoom(cy, -increment); | ||
} | ||
|
||
if (!cy) { | ||
return null; | ||
} | ||
|
||
const maxZoom = cy.maxZoom(); | ||
const isMaxZoom = zoom === maxZoom; | ||
const minZoom = cy.minZoom(); | ||
const isMinZoom = zoom === minZoom; | ||
const increment = (maxZoom - minZoom) / steps; | ||
const mapDomElement = cy.container(); | ||
const zoomInLabel = i18n.translate('xpack.apm.serviceMap.zoomIn', { | ||
defaultMessage: 'Zoom in' | ||
}); | ||
const zoomOutLabel = i18n.translate('xpack.apm.serviceMap.zoomOut', { | ||
defaultMessage: 'Zoom out' | ||
}); | ||
|
||
return ( | ||
<Container> | ||
<ZoomPanel hasShadow={true} paddingSize="none"> | ||
<ZoomInButton | ||
aria-label={zoomInLabel} | ||
color="text" | ||
disabled={isMaxZoom} | ||
iconType="plusInCircleFilled" | ||
onClick={zoomIn} | ||
title={zoomInLabel} | ||
/> | ||
<Button | ||
aria-label={zoomOutLabel} | ||
color="text" | ||
disabled={isMinZoom} | ||
iconType="minusInCircleFilled" | ||
onClick={zoomOut} | ||
title={zoomOutLabel} | ||
/> | ||
</ZoomPanel> | ||
<FullscreenPanel element={mapDomElement} /> | ||
</Container> | ||
); | ||
} |
93 changes: 93 additions & 0 deletions
93
x-pack/legacy/plugins/apm/public/components/app/ServiceMap/Cytoscape.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,93 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React, { | ||
CSSProperties, | ||
useState, | ||
useRef, | ||
useEffect, | ||
ReactNode, | ||
createContext | ||
} from 'react'; | ||
import cytoscape from 'cytoscape'; | ||
import dagre from 'cytoscape-dagre'; | ||
import { cytoscapeOptions } from './cytoscapeOptions'; | ||
|
||
cytoscape.use(dagre); | ||
|
||
export const CytoscapeContext = createContext<cytoscape.Core | undefined>( | ||
undefined | ||
); | ||
|
||
interface CytoscapeProps { | ||
children?: ReactNode; | ||
elements: cytoscape.ElementDefinition[]; | ||
serviceName?: string; | ||
style: CSSProperties; | ||
} | ||
|
||
function useCytoscape(options: cytoscape.CytoscapeOptions) { | ||
const [cy, setCy] = useState<cytoscape.Core | undefined>(undefined); | ||
const ref = useRef(null); | ||
|
||
useEffect(() => { | ||
if (!cy) { | ||
setCy(cytoscape({ ...options, container: ref.current })); | ||
} | ||
}, [options, cy]); | ||
|
||
// Destroy the cytoscape instance on unmount | ||
useEffect(() => { | ||
return () => { | ||
if (cy) { | ||
cy.destroy(); | ||
} | ||
}; | ||
}, [cy]); | ||
|
||
return [ref, cy] as [React.MutableRefObject<any>, cytoscape.Core | undefined]; | ||
} | ||
|
||
export function Cytoscape({ | ||
children, | ||
elements, | ||
serviceName, | ||
style | ||
}: CytoscapeProps) { | ||
const [ref, cy] = useCytoscape({ ...cytoscapeOptions, elements }); | ||
|
||
// Trigger a custom "data" event when data changes | ||
useEffect(() => { | ||
if (cy) { | ||
cy.add(elements); | ||
cy.trigger('data'); | ||
} | ||
}, [cy, elements]); | ||
|
||
// Set up cytoscape event handlers | ||
useEffect(() => { | ||
if (cy) { | ||
cy.on('data', event => { | ||
// Add the "primary" class to the node if its id matches the serviceName. | ||
if (cy.nodes().length > 0 && serviceName) { | ||
cy.getElementById(serviceName).addClass('primary'); | ||
} | ||
|
||
if (event.cy.elements().length > 0) { | ||
cy.layout(cytoscapeOptions.layout as cytoscape.LayoutOptions).run(); | ||
} | ||
}); | ||
} | ||
}, [cy, serviceName]); | ||
|
||
return ( | ||
<CytoscapeContext.Provider value={cy}> | ||
<div ref={ref} style={style}> | ||
{children} | ||
</div> | ||
</CytoscapeContext.Provider> | ||
); | ||
} |
Oops, something went wrong.