Skip to content

Commit d46ac60

Browse files
committed
[#12419] Cleanup duplicate Agent field in ServerMap
1 parent c5c6d54 commit d46ac60

File tree

6 files changed

+123
-113
lines changed

6 files changed

+123
-113
lines changed

web-frontend/src/main/v3/packages/ui/src/constants/types/FilteredMap.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
22
export namespace FilteredMapType {
3+
export interface Agent {
4+
id: string;
5+
name: string;
6+
}
37
export interface FilterState {
48
fromApplication?: SearchParameters['fa']; // from applicationName
59
fromServiceType?: SearchParameters['fst']; // from serviceType
@@ -106,10 +110,12 @@ export namespace FilteredMapType {
106110
key: string;
107111
from: string;
108112
to: string;
109-
fromAgent?: string[];
110-
toAgent?: string[];
111-
fromAgentIdNameMap?: FromAgentIdNameMap;
112-
toAgentIdNameMap?: ToAgentIdNameMap;
113+
// fromAgent?: string[]; // Deprecated;
114+
// toAgent?: string[]; // Deprecated;
115+
fromAgents: Agent[];
116+
toAgents: Agent[];
117+
// fromAgentIdNameMap?: FromAgentIdNameMap;
118+
// toAgentIdNameMap?: ToAgentIdNameMap;
113119
sourceInfo: SourceInfo;
114120
targetInfo: TargetInfo;
115121
filterApplicationName: string;
@@ -221,8 +227,8 @@ export namespace FilteredMapType {
221227
agentTimeSeriesHistogram: AgentTimeSeriesHistogram;
222228
instanceCount: number;
223229
instanceErrorCount: number;
224-
agentIds: string[];
225-
agentIdNameMap: AgentIdNameMap;
230+
// agentIds: string[];
231+
agents: Agent[];
226232
serverList: ServerList;
227233
}
228234

web-frontend/src/main/v3/packages/ui/src/constants/types/GetServerMap.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,19 @@ export namespace GetServerMap {
3030
toDateTime: string;
3131
}
3232

33+
export interface Agent {
34+
id: string;
35+
name: string;
36+
}
37+
3338
export interface LinkData {
3439
key: string;
3540
from: string;
3641
to: string;
37-
fromAgent?: string[];
38-
toAgent?: string[];
39-
fromAgentIdNameMap?: FromAgentIdNameMap;
40-
toAgentIdNameMap?: ToAgentIdNameMap;
42+
// fromAgent?: string[]; // Deprecated
43+
// toAgent?: string[]; // Deprecated
44+
fromAgents: Agent[];
45+
toAgents: Agent[];
4146
sourceInfo: SourceInfo;
4247
targetInfo: TargetInfo;
4348
filterApplicationName: string;
@@ -121,8 +126,8 @@ export namespace GetServerMap {
121126
timeSeriesHistogram: TimeSeriesHistogram[];
122127
instanceCount: number;
123128
instanceErrorCount: number;
124-
agentIds: string[];
125-
agentIdNameMap: AgentIdNameMap;
129+
// agentIds: string[]; // Deprecated
130+
agents: Agent[];
126131
isMerged?: boolean;
127132
mergedNodes?: any[];
128133
topCountNodes?: any[];

web-frontend/src/main/v3/packages/ui/src/pages/FilteredMap.tsx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,9 @@ export const FilteredMapPage = ({
106106
if (prevFilter.applicationName && prevFilter.serviceType) {
107107
return {
108108
...prevFilter,
109-
agents: (
110-
serverMapData?.applicationMapData.nodeDataArray as FilteredMap.NodeData[]
111-
)?.find((n) => n.key === `${prevFilter.applicationName}^${prevFilter.serviceType}`)
112-
?.agentIds,
109+
agents: (serverMapData?.applicationMapData.nodeDataArray as FilteredMap.NodeData[])
110+
?.find((n) => n.key === `${prevFilter.applicationName}^${prevFilter.serviceType}`)
111+
?.agents?.map((agent) => agent.id),
113112
};
114113
} else if (
115114
prevFilter.fromApplication &&
@@ -127,8 +126,8 @@ export const FilteredMapPage = ({
127126

128127
return {
129128
...prevFilter,
130-
fromAgents: linkData?.fromAgent,
131-
toAgents: linkData?.toAgent,
129+
fromAgents: linkData?.fromAgents?.map((agent) => agent.id),
130+
toAgents: linkData?.toAgents?.map((agent) => agent.id),
132131
};
133132
}
134133
return prevFilter;
@@ -354,7 +353,7 @@ export const FilteredMapPage = ({
354353
.nodeDataArray as FilteredMap.NodeData[]
355354
).find((n) => n.key === nodeData.id);
356355
serverInfos = {
357-
agents: node?.agentIds,
356+
agents: node?.agents?.map((agent) => agent.id),
358357
};
359358
} else if ('source' in data) {
360359
const edgeData = data as Edge;
@@ -363,8 +362,8 @@ export const FilteredMapPage = ({
363362
.linkDataArray as FilteredMap.LinkData[]
364363
).find((l) => l.key === edgeData.id);
365364
serverInfos = {
366-
fromAgents: link?.fromAgent,
367-
toAgents: link?.toAgent,
365+
fromAgents: link?.fromAgents?.map((agent) => agent.id),
366+
toAgents: link?.toAgents?.map((agent) => agent.id),
368367
};
369368
}
370369
setFilter(getDefaultFilters(data, serverInfos));

web-frontend/src/main/v3/packages/ui/src/pages/ServerMap.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ export const ServerMapPage = ({
332332
.nodeDataArray as GetServerMap.NodeData[]
333333
).find((n) => n.key === nodeData.id);
334334
serverInfos = {
335-
agents: node?.agentIds,
335+
agents: node?.agents?.map((agent) => agent?.id),
336336
};
337337
} else if ('source' in data) {
338338
const edgeData = data as Edge;
@@ -341,8 +341,8 @@ export const ServerMapPage = ({
341341
.linkDataArray as GetServerMap.LinkData[]
342342
).find((l) => l.key === edgeData.id);
343343
serverInfos = {
344-
fromAgents: link?.fromAgent,
345-
toAgents: link?.toAgent,
344+
fromAgents: link?.fromAgents?.map((agent) => agent?.id),
345+
toAgents: link?.toAgents?.map((agent) => agent?.id),
346346
};
347347
}
348348
setShowFilter(true);

web-frontend/src/main/v3/packages/ui/src/utils/helper/filteredMap/merge.ts

Lines changed: 17 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const mergeFilteredMapNodeData = (
2121
acc.instanceErrorCount = Math.max(acc.instanceErrorCount, neo.instanceErrorCount);
2222

2323
mergeAgentIds(acc, neo);
24-
mergeNodeAgentIdNameMap(acc, neo);
24+
// mergeNodeAgentIdNameMap(acc, neo);
2525
mergeHistogram(acc, neo);
2626
mergeResponseStatistics(acc, neo);
2727
mergeAgentHistogram(acc, neo);
@@ -59,11 +59,11 @@ export const mergeFilteredMapLinkData = (
5959
acc.errorCount += neo.errorCount;
6060
acc.totalCount += neo.totalCount;
6161

62-
mergeLinkAgentIdNameMap(acc, neo, 'fromAgentIdNameMap');
63-
mergeLinkAgentIdNameMap(acc, neo, 'toAgentIdNameMap');
62+
// mergeLinkAgentIdNameMap(acc, neo, 'fromAgentIdNameMap');
63+
// mergeLinkAgentIdNameMap(acc, neo, 'toAgentIdNameMap');
6464
mergeHistogram(acc, neo);
65-
mergeLinkAgentIds(acc, neo, 'fromAgent');
66-
mergeLinkAgentIds(acc, neo, 'toAgent');
65+
mergeLinkAgentIds(acc, neo, 'fromAgents');
66+
mergeLinkAgentIds(acc, neo, 'toAgents');
6767
mergeResponseStatistics(acc, neo);
6868
mergeTimeSeriesHistogram(current, newNode);
6969
mergeAgentTimeSeriesHistogramByType(
@@ -85,54 +85,26 @@ export const mergeFilteredMapLinkData = (
8585
};
8686

8787
function mergeAgentIds(old: FilteredMap.NodeData, neo: FilteredMap.NodeData): void {
88-
neo.agentIds.forEach((agentId: string) => {
89-
if (old.agentIds.indexOf(agentId) === -1) {
90-
old.agentIds.push(agentId);
88+
neo.agents.forEach((agent: FilteredMap.Agent) => {
89+
const oldAgentIndex = old.agents.findIndex((oldAgent) => oldAgent.id === agent.id);
90+
if (oldAgentIndex === -1) {
91+
old.agents.push(agent);
9192
}
9293
});
9394
}
9495

95-
function mergeLinkAgentIdNameMap(
96-
old: FilteredMap.LinkData,
97-
neo: FilteredMap.LinkData,
98-
type: keyof FilteredMap.LinkData,
99-
): void {
100-
const oldMap = old[type] as FilteredMap.FromAgentIdNameMap | FilteredMap.ToAgentIdNameMap;
101-
const newMap = neo[type] as FilteredMap.FromAgentIdNameMap | FilteredMap.ToAgentIdNameMap;
102-
if (newMap) {
103-
const oldIds = Object.keys(oldMap!);
104-
const newIds = Object.keys(newMap);
105-
newIds.forEach((agentId: string) => {
106-
if (oldIds.indexOf(agentId) === -1) {
107-
oldMap[agentId] = newMap[agentId];
108-
}
109-
});
110-
}
111-
}
112-
113-
function mergeNodeAgentIdNameMap(old: FilteredMap.NodeData, neo: FilteredMap.NodeData): void {
114-
if (neo.agentIdNameMap) {
115-
const oldIds = Object.keys(old.agentIdNameMap);
116-
const newIds = Object.keys(neo.agentIdNameMap);
117-
newIds.forEach((agentId: string) => {
118-
if (oldIds.indexOf(agentId) === -1) {
119-
old.agentIdNameMap[agentId] = neo.agentIdNameMap[agentId];
120-
}
121-
});
122-
}
123-
}
124-
12596
function mergeLinkAgentIds(
12697
old: FilteredMap.LinkData,
12798
neo: FilteredMap.LinkData,
128-
type: 'fromAgent' | 'toAgent',
99+
type: 'fromAgents' | 'toAgents',
129100
): void {
130-
const oldIds = old[type];
131-
const newIds = neo[type];
132-
if (newIds) {
133-
newIds?.forEach((agentId: string) => {
134-
if (oldIds?.indexOf(agentId) === -1) {
135-
old[type]?.push(agentId);
101+
const oldAgents = old[type];
102+
const newAgents = neo[type];
103+
if (newAgents) {
104+
newAgents?.forEach((agent: FilteredMap.Agent) => {
105+
const oldAgentIndex = oldAgents.findIndex((oldAgent) => oldAgent.id === agent.id);
106+
if (oldAgentIndex === -1) {
107+
old[type]?.push(agent);
136108
}
137109
});
138110
}

0 commit comments

Comments
 (0)