Skip to content

Commit

Permalink
Merge pull request #434 from bartoval/add_metrics_topology_sidebar_pr…
Browse files Browse the repository at this point in the history
…ocess

Add metrics topology sidebar process
  • Loading branch information
bartoval authored Aug 5, 2024
2 parents 5767b5a + 1770c56 commit eaa2660
Show file tree
Hide file tree
Showing 18 changed files with 559 additions and 359 deletions.
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@
"@patternfly/react-core": "^5.3.4",
"@patternfly/react-icons": "^5.3.2",
"@patternfly/react-table": "5.3.4",
"@tanstack/react-query": "^5.51.15",
"axios": "^1.7.2",
"@tanstack/react-query": "^5.51.21",
"axios": "^1.7.3",
"date-fns": "^3.6.0",
"framer-motion": "^11.3.19",
"framer-motion": "^11.3.21",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-error-boundary": "^4.0.13",
"react-router-dom": "^6.25.1"
"react-router-dom": "^6.26.0"
},
"devDependencies": {
"@commitlint/cli": "^19.3.0",
Expand All @@ -62,8 +62,8 @@
"@types/jest": "^29.5.12",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@typescript-eslint/eslint-plugin": "^7.17.0",
"@typescript-eslint/parser": "^7.17.0",
"@typescript-eslint/eslint-plugin": "^7.18.0",
"@typescript-eslint/parser": "^7.18.0",
"commitizen": "^4.3.0",
"copy-webpack-plugin": "^12.0.2",
"css-loader": "^7.1.2",
Expand All @@ -74,11 +74,11 @@
"eslint-config-prettier": "^9.1.0",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jest": "^28.6.0",
"eslint-plugin-jest": "^28.7.0",
"eslint-plugin-react": "^7.35.0",
"eslint-plugin-react-hooks": "^4.6.2",
"html-webpack-plugin": "^5.6.0",
"husky": "^9.1.3",
"husky": "^9.1.4",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"mini-css-extract-plugin": "^2.9.0",
Expand All @@ -87,7 +87,7 @@
"start-server-and-test": "^2.0.5",
"style-loader": "^4.0.0",
"terser-webpack-plugin": "^5.3.10",
"ts-jest": "^29.2.3",
"ts-jest": "^29.2.4",
"ts-loader": "^9.5.1",
"ts-node": "^10.9.2",
"ts-prune": "^0.10.3",
Expand Down
2 changes: 1 addition & 1 deletion src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ export const IDS_GROUP_SEPARATOR = '~';
export const IDS_MULTIPLE_SELECTION_SEPARATOR = ',';
export const PAIR_SEPARATOR = '-to-';

export const MIN_DRAWER_WIDTH = 450;
export const MIN_DRAWER_WIDTH = 500;
export const MAX_DRAWER_WIDTH = 800;
13 changes: 0 additions & 13 deletions src/core/components/SKSanckeyChart/SkSankeyChart.interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
import { VarColors } from '@config/colors';

export interface ThemesProps {
labelTextColor: VarColors;
fontFamily: string;
fontSize: number;
tooltip: { container: { color: string } };
}

export interface Themes {
[key: string]: ThemesProps;
}

export interface SkSankeyChartNode {
id: string;
nodeColor?: string;
Expand Down
4 changes: 2 additions & 2 deletions src/core/components/SkGraph/Graph.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export const NODE_LABEL_TEXT_COLOR = HexColors.Black900;
export const NODE_LABEL_BACKGROUND_COLOR = HexColors.White;
export const NODE_SELECT_BORDER = HexColors.DefaultHighLight;
export const NODE_HIGHLIGHT_BORDER = HexColors.DefaultHighLight;
export const NODE_BADGE_GROUP_ELEMENTS_BACKGROUND = HexColors.DefaultStatusBackground;
export const NODE_BADGE_GROUP_ELEMENTS_TEXT = HexColors.DefaultStatusText;
export const NODE_BADGE_GROUP_ELEMENTS_BACKGROUND = HexColors.Black500;
export const NODE_BADGE_GROUP_ELEMENTS_TEXT = HexColors.White;

export const EDGE_LINE_COLOR = HexColors.DefaultEdge;
export const EDGE_TERMINAL_COLOR = HexColors.DefaultEdge;
Expand Down
2 changes: 1 addition & 1 deletion src/core/components/SkGraph/Graph.interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { LayoutOptions } from '@antv/g6';

export type GraphIconKeys = 'component' | 'process' | 'site' | 'podman' | 'kubernetes' | 'skupper';
type GraphIconKeys = 'component' | 'process' | 'site' | 'podman' | 'kubernetes' | 'skupper';

export type GraphIconsMap = {
[key in GraphIconKeys]: HTMLImageElement;
Expand Down
2 changes: 1 addition & 1 deletion src/core/components/SkGraph/components/CustomElements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ const DEFAULT_NODE_CONFIG: NodeOptions = {
};

// EDGE
export const DEFAULT_DATA_EDGE_CONFIG: EdgeOptions = {
const DEFAULT_DATA_EDGE_CONFIG: EdgeOptions = {
style: {
visibility: 'visible',
opacity: 1,
Expand Down
17 changes: 2 additions & 15 deletions src/core/components/SkGraph/services/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { ComboData, EdgeData, NodeData } from '@antv/g6';

import { ellipsisInTheMiddle } from '@core/utils/EllipsisInTheMiddle';

import { graphIconsMap } from '../Graph.config';
import {
GraphCombo,
Expand Down Expand Up @@ -249,21 +251,6 @@ function markPairs(data: GraphEdge[]) {
});
}

function ellipsisInTheMiddle(str: string) {
const maxLength = 20;
const leftPartLength = 15;
const rightPartLength = 5;

if (str.length <= maxLength) {
return str;
}

const leftPart = str.substring(0, leftPartLength);
const rightPart = str.substring(str.length - rightPartLength);

return `${leftPart}...${rightPart}`;
}

/**
* Normalizes a given metric value (such as bitrate) to a line thickness value
* for visual representations like graphs or charts. The normalization is done
Expand Down
17 changes: 17 additions & 0 deletions src/core/utils/EllipsisInTheMiddle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export function ellipsisInTheMiddle(
str: string,
options?: { maxLength?: number; leftPartLenth?: number; rightPartLength?: number }
) {
const maxLength = options?.maxLength || 20;
const leftPartLength = options?.leftPartLenth || 15;
const rightPartLength = options?.rightPartLength || 5;

if (str.length <= maxLength) {
return str;
}

const leftPart = str.substring(0, leftPartLength);
const rightPart = str.substring(str.length - rightPartLength);

return `${leftPart}...${rightPart}`;
}
2 changes: 1 addition & 1 deletion src/pages/Processes/Processes.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ export enum ProcessesLabels {
Latency = 'Latency',
Name = 'Name',
Component = 'Component',
ByteRateRx = 'Rx byte rate',
ByteRateRx = 'Byte rate In',
Exposed = 'Exposed'
}
15 changes: 1 addition & 14 deletions src/pages/Topology/Topology.interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
import { PrometheusMetric, PrometheusLabels } from '@API/Prometheus.interfaces';
import { ProcessPairsResponse, ProcessResponse } from '@API/REST.interfaces';
import { CustomItemsProps, GraphIconKeys } from '@core/components/SkGraph/Graph.interfaces';

export interface Entity {
id: string;
combo?: string;
comboName?: string;
groupId?: string;
groupName?: string;
label: string;
iconName: GraphIconKeys;
type?: CustomItemsProps;
groupedNodeCount?: number;
}

export interface TopologyMetrics {
bytesByProcessPairs: PrometheusMetric<'vector'>[];
Expand Down Expand Up @@ -56,7 +43,7 @@ export interface DisplayOptions {
export interface NodeOrEdgeListProps {
ids?: string[];
items: ProcessResponse[] | ProcessPairsResponse[];
metrics: TopologyMetrics | null;
metrics: TopologyMetrics;
modalType: 'process' | 'processPair';
}

Expand Down
94 changes: 87 additions & 7 deletions src/pages/Topology/__tests__/NodeOrEdgeList.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import processesPairsData from '@mocks/data/PROCESS_PAIRS.json';
import processesData from '@mocks/data/PROCESSES.json';
import { loadMockServer } from '@mocks/server';

import NodeOrEdgeList from '../components/NodeOrEdgeList';
import TopologyDetails from '../components/TopologyDetails';

const processesResults = processesData.results as ProcessResponse[];
const processPairsResults = processesPairsData.results as ProcessPairsResponse[];
Expand All @@ -31,12 +31,58 @@ describe('NodeOrEdgeList', () => {

render(
<Wrapper>
<NodeOrEdgeList ids={ids} items={items} modalType="process" metrics={null} />
<TopologyDetails
ids={ids}
items={items}
modalType="process"
metrics={{
bytesByProcessPairs: [
{
metric: {
destProcess: processesResults[0].name,
direction: 'incoming',
sourceProcess: processesResults[1].name
},
value: [1722715709.263, 38],
values: [] as never
},
{
metric: {
destProcess: processesResults[1].name,
direction: 'incoming',
sourceProcess: processesResults[0].name
},
value: [1722715709.263, 38],
values: [] as never
}
],
byteRateByProcessPairs: [
{
metric: {
destProcess: processesResults[0].name,
direction: 'incoming',
sourceProcess: processesResults[1].name
},
value: [1722715709.263, 38],
values: [] as never
},
{
metric: {
destProcess: processesResults[1].name,
direction: 'incoming',
sourceProcess: processesResults[0].name
},
value: [1722715709.263, 38],
values: [] as never
}
],
latencyByProcessPairs: []
}}
/>
</Wrapper>
);

expect(screen.getByText(processesResults[0].name)).toBeInTheDocument();
expect(screen.getByText(`${processesResults[0].sourceHost}/${processesResults[0].hostName}`)).toBeInTheDocument();
expect(screen.getAllByText(processesResults[0].groupName)[0]).toBeInTheDocument();
expect(screen.getAllByText(processesResults[0].parentName)[0]).toBeInTheDocument();
expect(
Expand All @@ -48,17 +94,51 @@ describe('NodeOrEdgeList', () => {

it('should render a list of process pairs when modalType is "process-pair"', () => {
const items = processPairsResults;
const ids = [processPairsResults[3].identity, processPairsResults[2].identity];
const ids = [processPairsResults[2].identity];

render(
<Wrapper>
<NodeOrEdgeList ids={ids} items={items} modalType="processPair" metrics={null} />
<TopologyDetails
ids={ids}
items={items}
modalType="processPair"
metrics={{
bytesByProcessPairs: [
{
metric: {
destProcess: processPairsResults[2].destinationName,
sourceProcess: processPairsResults[2].sourceName
},
value: [1722715709.263, 38],
values: [] as never
}
],
byteRateByProcessPairs: [
{
metric: {
destProcess: processPairsResults[2].destinationName,
sourceProcess: processPairsResults[2].sourceName
},
value: [1722715709.263, 38],
values: [] as never
}
],
latencyByProcessPairs: [
{
metric: {
destProcess: processPairsResults[2].destinationName,
sourceProcess: processPairsResults[2].sourceName
},
value: [1722715709.263, 38],
values: [] as never
}
]
}}
/>
</Wrapper>
);

expect(screen.getByText(processPairsResults[2].sourceName)).toBeInTheDocument();
expect(screen.getByText(processPairsResults[2].destinationName)).toBeInTheDocument();
expect(screen.getByText(processPairsResults[3].sourceName)).toBeInTheDocument();
expect(screen.getByText(processPairsResults[3].destinationName)).toBeInTheDocument();
});
});
Loading

0 comments on commit eaa2660

Please sign in to comment.