Skip to content

Commit c6b9c9a

Browse files
author
dushixiang
committed
修复服务监控历史趋势无法切换探针的 bug
1 parent 7bdb6f9 commit c6b9c9a

File tree

1 file changed

+10
-22
lines changed

1 file changed

+10
-22
lines changed

web/src/components/monitor/ResponseTimeChart.tsx

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -58,24 +58,20 @@ export const ResponseTimeChart = ({monitorId, monitorStats}: ResponseTimeChartPr
5858
// 过滤出响应时间指标的 series
5959
const responseTimeSeries = historyData.series?.filter(s => s.name === 'response_time');
6060

61-
// 根据选择的探针过滤(使用 agent_name,如果没有则fallback到 agent_id)
61+
// 根据选择的探针过滤(使用 agent_id)
6262
const filteredSeries = selectedAgent === 'all'
6363
? responseTimeSeries
64-
: responseTimeSeries.filter(s => {
65-
// 优先使用 agent_name,如果没有则使用 agent_id
66-
const agentIdentifier = s.labels?.agent_name || s.labels?.agent_id;
67-
return agentIdentifier === selectedAgent;
68-
});
64+
: responseTimeSeries.filter(s => s.labels?.agent_id === selectedAgent);
6965

7066
if (filteredSeries.length === 0) return [];
7167

7268
// 按时间戳分组数据
7369
const grouped: Record<number, any> = {};
7470

7571
filteredSeries.forEach(series => {
76-
// 优先使用 agent_name,如果没有则使用 agent_id
77-
const agentIdentifier = series.labels?.agent_name || series.labels?.agent_id || 'unknown';
78-
const agentKey = `agent_${agentIdentifier}`;
72+
// 使用 agent_id 作为标识符
73+
const agentId = series.labels?.agent_id || 'unknown';
74+
const agentKey = `agent_${agentId}`;
7975

8076
series.data.forEach(point => {
8177
if (!grouped[point.timestamp]) {
@@ -114,7 +110,7 @@ export const ResponseTimeChart = ({monitorId, monitorStats}: ResponseTimeChartPr
114110
>
115111
<option value="all">所有探针</option>
116112
{availableAgents.map((agent) => (
117-
<option key={agent.id} value={agent.name}>
113+
<option key={agent.id} value={agent.id}>
118114
{agent.name}
119115
</option>
120116
))}
@@ -128,14 +124,10 @@ export const ResponseTimeChart = ({monitorId, monitorStats}: ResponseTimeChartPr
128124
<AreaChart data={chartData}>
129125
<defs>
130126
{monitorStats
131-
.filter(stat => {
132-
const agentIdentifier = stat.agentName || stat.agentId;
133-
return selectedAgent === 'all' || agentIdentifier === selectedAgent;
134-
})
127+
.filter(stat => selectedAgent === 'all' || stat.agentId === selectedAgent)
135128
.map((stat) => {
136129
const originalIndex = monitorStats.findIndex(s => s.agentId === stat.agentId);
137-
const agentIdentifier = stat.agentName || stat.agentId;
138-
const agentKey = `agent_${agentIdentifier}`;
130+
const agentKey = `agent_${stat.agentId}`;
139131
const color = AGENT_COLORS[originalIndex % AGENT_COLORS.length];
140132
return (
141133
<linearGradient key={agentKey} id={`gradient_${agentKey}`} x1="0" y1="0"
@@ -174,14 +166,10 @@ export const ResponseTimeChart = ({monitorId, monitorStats}: ResponseTimeChartPr
174166
iconType="circle"
175167
/>
176168
{monitorStats
177-
.filter(stat => {
178-
const agentIdentifier = stat.agentName || stat.agentId;
179-
return selectedAgent === 'all' || agentIdentifier === selectedAgent;
180-
})
169+
.filter(stat => selectedAgent === 'all' || stat.agentId === selectedAgent)
181170
.map((stat) => {
182171
const originalIndex = monitorStats.findIndex(s => s.agentId === stat.agentId);
183-
const agentIdentifier = stat.agentName || stat.agentId;
184-
const agentKey = `agent_${agentIdentifier}`;
172+
const agentKey = `agent_${stat.agentId}`;
185173
const color = AGENT_COLORS[originalIndex % AGENT_COLORS.length];
186174
const agentLabel = stat.agentName || stat.agentId.substring(0, 8);
187175
return (

0 commit comments

Comments
 (0)