-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Servicemap POC #42120
Servicemap POC #42120
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* 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 from 'react'; | ||
import CytoscapeComponent from 'react-cytoscapejs'; | ||
import { IUrlParams } from '../../../context/UrlParamsContext/types'; | ||
|
||
function elementId(serviceName: string, environment?: string) { | ||
return serviceName + '/' + (environment ? '/' + environment : ''); | ||
} | ||
|
||
function label(serviceName: string, environment?: string) { | ||
return serviceName + (environment ? '/' + environment : ''); | ||
} | ||
|
||
// interface Props { | ||
// connections: any; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI cytoscape has very good DefinitelyTyped definitions which we can use to our advantage later, since you can deal with some pretty complex objects. Not sure where to ask this, so I'll ask it here: Are there reason's we're not using the components that make up the Graph capabilities already in x-pack? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Without having looked into it much I don't think the Graph plugin is easily embeddable in APM UI. Afaict Graph is based on Angular while APM UI uses React. Mixing those frameworks is possible but something we should think twice about doing. Secondly, I think our use case requires a lot of custom UI work and we would probably spend more time fighting the capabilities and visual appearance of Graph instead of building it from scratch. We already had a meeting with other teams who also need graph visualizations and we found common ground in using the same lib ( |
||
// } | ||
export function MapOfServices({ connections, layout }: any) { | ||
const services: { [s: string]: object } = {}; | ||
const conns: Array<{ data: object }> = []; | ||
let destNodeID; | ||
connections.forEach(c => { | ||
if (c['callee.name']) { | ||
destNodeID = elementId(c['callee.name'], c['callee.environment']); | ||
const node = { | ||
data: { | ||
id: destNodeID, | ||
label: label(c['callee.name'], c['callee.environment']), | ||
color: 'black' | ||
} | ||
}; | ||
services[destNodeID] = node; | ||
} else { | ||
destNodeID = elementId(c['destination.address']); | ||
services[destNodeID] = { | ||
data: { | ||
id: destNodeID, | ||
label: label(c['destination.address']) | ||
} | ||
}; | ||
} | ||
const sourceNodeID = elementId(c['service.name'], c['service.environment']); | ||
|
||
services[sourceNodeID] = { | ||
data: { | ||
id: sourceNodeID, | ||
label: label(c['service.name'], c['service.environment']), | ||
color: 'black' | ||
} | ||
}; | ||
|
||
conns.push({ | ||
data: { | ||
source: sourceNodeID, | ||
target: destNodeID, | ||
label: c['connection.subtype'] | ||
} | ||
}); | ||
}); | ||
const elements = Object.values(services).concat(conns); | ||
// const elements = []; | ||
// { data: { id: 'one', label: 'Node 1' }}, | ||
// { data: { id: 'two', label: 'Node 2' }}, | ||
// { data: { source: 'one', target: 'two', label: 'Edge from Node1 to Node2' } } | ||
// ]; | ||
const stylesheet = [ | ||
{ | ||
selector: 'node', | ||
style: { | ||
label: 'data(label)' // maps to data.label | ||
} | ||
}, | ||
{ | ||
selector: 'node[color]', | ||
style: { | ||
'background-color': 'data(color)' | ||
} | ||
}, | ||
{ | ||
selector: 'edge', | ||
style: { | ||
width: 2, | ||
label: 'data(label)', // maps to data.label | ||
'curve-style': 'bezier', | ||
'target-arrow-shape': 'triangle' | ||
} | ||
} | ||
]; | ||
|
||
return ( | ||
<CytoscapeComponent | ||
elements={elements} | ||
layout={{ name: layout }} | ||
stylesheet={stylesheet} | ||
style={{ width: '1024px', height: '600px' }} | ||
/> | ||
); | ||
} |
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.
Should this be a new key instead of
tracesTabLabel
?