2021-05-09 15:41:57 +05:30
|
|
|
import { uniqBy, uniq, maxBy, cloneDeep, find } from "lodash";
|
|
|
|
|
import { serviceMapStore } from "Src/store/actions";
|
2021-05-09 14:44:14 +05:30
|
|
|
import { graphDataType } from "./ServiceMap";
|
|
|
|
|
|
2021-05-09 20:47:56 +05:30
|
|
|
const MIN_WIDTH = 25;
|
|
|
|
|
const MAX_WIDTH = 50;
|
|
|
|
|
const MIN_HEIGHT = 10;
|
|
|
|
|
const MAX_HEIGHT = 15;
|
|
|
|
|
const DEFAULT_FONT_SIZE = 4;
|
2021-05-09 15:41:57 +05:30
|
|
|
export const getDimensions = (num, highest) => {
|
|
|
|
|
const percentage = (num / highest) * 100;
|
|
|
|
|
const width = (percentage * (MAX_WIDTH - MIN_WIDTH)) / 100 + MIN_WIDTH;
|
2021-05-09 20:47:56 +05:30
|
|
|
const height = (percentage * (MAX_HEIGHT - MIN_HEIGHT)) / 100 + MIN_HEIGHT;
|
|
|
|
|
const fontSize = DEFAULT_FONT_SIZE;
|
2021-05-09 15:41:57 +05:30
|
|
|
return {
|
|
|
|
|
fontSize,
|
|
|
|
|
width,
|
2021-05-09 20:47:56 +05:30
|
|
|
height,
|
2021-05-09 15:41:57 +05:30
|
|
|
};
|
|
|
|
|
};
|
2021-05-09 14:44:14 +05:30
|
|
|
|
2021-05-09 15:41:57 +05:30
|
|
|
export const getGraphData = (serviceMap: serviceMapStore): graphDataType => {
|
|
|
|
|
const { items, services } = serviceMap;
|
|
|
|
|
const highestCallCount = maxBy(items, (e) => e.callCount).callCount;
|
|
|
|
|
const highestCallRate = maxBy(services, (e) => e.callRate).callRate;
|
|
|
|
|
const divNum = Number(
|
|
|
|
|
String(1).padEnd(highestCallCount.toString().length, "0"),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const links = cloneDeep(items).map((node) => {
|
2021-05-09 14:44:14 +05:30
|
|
|
const { parent, child, callCount } = node;
|
|
|
|
|
return {
|
|
|
|
|
source: parent,
|
|
|
|
|
target: child,
|
|
|
|
|
value: (100 - callCount / divNum) * 0.01,
|
|
|
|
|
};
|
|
|
|
|
});
|
2021-05-09 15:41:57 +05:30
|
|
|
const uniqParent = uniqBy(cloneDeep(items), "parent").map((e) => e.parent);
|
|
|
|
|
const uniqChild = uniqBy(cloneDeep(items), "child").map((e) => e.child);
|
2021-05-09 14:44:14 +05:30
|
|
|
const uniqNodes = uniq([...uniqParent, ...uniqChild]);
|
2021-05-09 15:41:57 +05:30
|
|
|
const nodes = uniqNodes.map((node, i) => {
|
|
|
|
|
const service = find(services, (service) => service.serviceName === node);
|
|
|
|
|
let color = "#84ff00";
|
2021-05-09 19:12:54 +05:30
|
|
|
if (!service) {
|
|
|
|
|
return {
|
|
|
|
|
id: node,
|
|
|
|
|
group: i + 1,
|
2021-05-09 20:47:56 +05:30
|
|
|
fontSize: DEFAULT_FONT_SIZE,
|
2021-05-09 19:12:54 +05:30
|
|
|
width: MIN_WIDTH,
|
2021-05-09 20:47:56 +05:30
|
|
|
height: MIN_HEIGHT,
|
2021-05-09 19:12:54 +05:30
|
|
|
color,
|
|
|
|
|
nodeVal: MIN_WIDTH,
|
|
|
|
|
callRate: 0,
|
|
|
|
|
errorRate: 0,
|
|
|
|
|
p99: 0,
|
|
|
|
|
};
|
|
|
|
|
}
|
2021-05-09 15:41:57 +05:30
|
|
|
if (service.errorRate > 0) {
|
|
|
|
|
color = "#f00a0a";
|
|
|
|
|
} else if (service.fourXXRate > 0) {
|
|
|
|
|
color = "#ebeb15";
|
|
|
|
|
}
|
2021-05-09 20:47:56 +05:30
|
|
|
const { fontSize, width, height } = getDimensions(service.callRate, highestCallRate);
|
2021-05-09 18:27:37 +05:30
|
|
|
return {
|
|
|
|
|
id: node,
|
|
|
|
|
group: i + 1,
|
|
|
|
|
fontSize,
|
|
|
|
|
width,
|
2021-05-09 20:47:56 +05:30
|
|
|
height,
|
2021-05-09 18:27:37 +05:30
|
|
|
color,
|
|
|
|
|
nodeVal: width,
|
|
|
|
|
callRate: service.callRate,
|
|
|
|
|
errorRate: service.errorRate,
|
|
|
|
|
p99: service.p99,
|
|
|
|
|
};
|
2021-05-09 15:41:57 +05:30
|
|
|
});
|
2021-05-09 14:44:14 +05:30
|
|
|
return {
|
|
|
|
|
nodes,
|
|
|
|
|
links,
|
|
|
|
|
};
|
|
|
|
|
};
|