Skip to content

Commit

Permalink
feat: 【专项】APM 应用拓扑(请求数缩略图)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaolicheng-github committed Jul 25, 2024
1 parent 1d88269 commit e4fd092
Show file tree
Hide file tree
Showing 4 changed files with 296 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,13 @@ $header-height: 52px;
margin: 0 0 0 auto;
}
}

.content-table-wrap {
margin-top: 16px;

.chart-wrap {
position: relative;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,25 @@ import { Component as tsc } from 'vue-tsx-support';

import TimeRange, { type TimeRangeType } from 'monitor-pc/components/time-range/time-range';
import { getDefaultTimezone, updateTimezone } from 'monitor-pc/i18n/dayjs';
import CommonTable from 'monitor-pc/pages/monitor-k8s/components/common-table';

import MiniChart from './mini-chart';

import type { ITableColumn, ITablePagination, TableRow } from 'monitor-pc/pages/monitor-k8s/typings/table';

import './details-side.scss';

enum EColumn {
Chart = 'chart',
CompareCount = 'compare-count',
DiffCount = 'diff-count',
InitiativeCount = 'initiative-count',
InitiativeService = 'initiative-service',
Operate = 'operate',
ReferCount = 'refer-count',
ServerName = 'service_name',
}

interface IProps {
show: boolean;
onClose?: () => void;
Expand All @@ -43,19 +59,19 @@ export default class DetailsSide extends tsc<IProps> {
/* 时间 */
timeRange: TimeRangeType = ['now-1d', 'now'];
timezone: string = getDefaultTimezone();
/* */
/* 主体切换 */
selectOptions = [
{ id: 'avg', name: '平均响应耗时' },
{ id: 'error', name: '总错误数' },
];
selected = 'avg';

/* 类型切换 */
typeOptions = [
{ id: 'initiative', name: '主调' },
{ id: 'passive', name: '被调' },
];
curType = 'initiative';

/* 对比时间 */
compareTimeInfo = [
{
id: 'refer',
Expand All @@ -70,11 +86,114 @@ export default class DetailsSide extends tsc<IProps> {
color: '#7B29FF',
},
];

/* 对比开关 */
isCompare = false;

/* 搜索 */
searchValue = '';

tableColumns: ITableColumn[] = [
{
type: 'link',
id: EColumn.ServerName,
name: window.i18n.tc('服务名称'),
},
{
type: 'string',
id: EColumn.InitiativeService,
name: window.i18n.tc('调用服务'),
},
{
type: 'number',
id: EColumn.InitiativeCount,
name: window.i18n.tc('调用数'),
},
{
id: EColumn.CompareCount,
type: 'number',
name: window.i18n.tc('对比'),
},
{
id: EColumn.ReferCount,
name: window.i18n.tc('参照'),
type: 'number',
},
{
id: EColumn.DiffCount,
name: window.i18n.tc('差异值'),
type: 'scoped_slots',
},
{
type: 'scoped_slots',
id: EColumn.Chart,
name: window.i18n.tc('缩略图'),
},
{
type: 'scoped_slots',
id: EColumn.Operate,
name: window.i18n.tc('操作'),
},
];
tableData: TableRow[] = [
{
[EColumn.ServerName]: {
icon: '',
key: '',
target: 'null_event',
url: '',
value: 'test1',
},
[EColumn.InitiativeService]: {
icon: '',
type: '',
text: 'test01',
},
[EColumn.InitiativeCount]: 10,
[EColumn.CompareCount]: 10,
[EColumn.ReferCount]: 10,
[EColumn.DiffCount]: 0.45,
[EColumn.Chart]: null,
[EColumn.Operate]: null,
},
{
[EColumn.ServerName]: {
icon: '',
key: '',
target: 'null_event',
url: '',
value: 'test2',
},
[EColumn.InitiativeService]: {
icon: '',
type: '',
text: 'test02',
},
[EColumn.InitiativeCount]: 10,
[EColumn.CompareCount]: 20,
[EColumn.ReferCount]: 20,
[EColumn.DiffCount]: -0.45,
[EColumn.Chart]: null,
[EColumn.Operate]: null,
},
];
/** 分页数据 */
pagination: ITablePagination = {
current: 1,
count: 2,
limit: 10,
showTotalCount: true,
};

get filterTableColumns() {
return this.tableColumns.filter(item => {
if (this.isCompare) {
return ![EColumn.InitiativeCount].includes(item.id as EColumn);
}
return [EColumn.ServerName, EColumn.InitiativeService, EColumn.InitiativeCount, EColumn.Chart].includes(
item.id as EColumn
);
});
}

handleClose() {
this.$emit('close');
}
Expand Down Expand Up @@ -189,6 +308,37 @@ export default class DetailsSide extends tsc<IProps> {
/>
</div>
</div>
<div class='content-table-wrap'>
<CommonTable
scopedSlots={{
[EColumn.DiffCount]: row => {
return row[EColumn.DiffCount];
},
[EColumn.Chart]: _row => {
return (
<div class='chart-wrap'>
<MiniChart />
</div>
);
},
[EColumn.Operate]: _row => {
return (
<bk-button
type='primary'
text
>
{this.$t('查看拓扑')}
</bk-button>
);
},
}}
checkable={false}
columns={this.filterTableColumns}
data={this.tableData}
pagination={this.pagination}
paginationType={'simple'}
/>
</div>
</div>
</bk-sideslider>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* stylelint-disable declaration-no-important */
.details-side-mini-chart {
width: 100%;
min-width: 111px;
min-height: 24px;

& > div {
cursor: crosshair !important;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*
* Tencent is pleased to support the open source community by making
* 蓝鲸智云PaaS平台 (BlueKing PaaS) available.
*
* Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
*
* 蓝鲸智云PaaS平台 (BlueKing PaaS) is licensed under the MIT License.
*
* License for 蓝鲸智云PaaS平台 (BlueKing PaaS):
*
* ---------------------------------------------------
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of
* the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
* THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/

import { Component, Ref } from 'vue-property-decorator';
import { Component as tsc } from 'vue-tsx-support';

import { type MonitorEchartOptions, echarts } from '../../../typings/index';
// import { CommonSimpleChart } from '../../common-simple-chart';

import './mini-chart.scss';

interface IProps {
data?: any;
}

@Component
export default class MiniChart extends tsc<IProps> {
@Ref('chartInstance') chartRef: HTMLDivElement;

// 当前图表配置取消监听函数
unwatchOptions: () => void = null;

options: MonitorEchartOptions = {
xAxis: {
show: false,
type: 'value',
max: 'dataMax',
min: 'dataMin',
},
yAxis: {
show: false,
type: 'value',
max: 'dataMax',
min: 0,
},
tooltip: {
show: true,
trigger: 'axis',
appendToBody: true,
},
series: [
{
type: 'line',
lineStyle: {
color: '#3A84FF',
width: 0.5,
},
cursor: 'auto',
symbol: 'none',
areaStyle: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{
offset: 0,
color: '#A4C6FD',
},
{
offset: 1,
color: '#FFFFFF',
},
]),
},
smooth: true,
data: [
[2, 1721894460000],
[41, 1721894520000],
[0, 1721894580000],
[16, 1721894640000],
[4, 1721894700000],
[0, 1721894760000],
[70, 1721894820000],
[58, 1721894880000],
[65, 1721894940000],
[71, 1721895000000],
].map(item => ({
value: [item[1], item[0]],
})),
},
],
};

mounted() {
this.initChart();
}

initChart() {
if (!(this as any).instance) {
(this as any).instance = echarts.init(this.chartRef);
(this as any).instance.setOption(this.options);
}
}

render() {
return (
<div
ref='chartInstance'
class='details-side-mini-chart'
/>
);
}
}

0 comments on commit e4fd092

Please sign in to comment.