Skip to content

Commit dd82924

Browse files
committed
fix: update dashboard api
1 parent e57ed1f commit dd82924

File tree

4 files changed

+27
-12
lines changed

4 files changed

+27
-12
lines changed

__tests__/cls/dashboard.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ describe('Cls dashboard', () => {
3636

3737
const inputs: DeployDashboardInputs = {
3838
name: 'serverless-unit-test-dashboard',
39-
chartList: [chart1Config, chart2Config],
39+
charts: [chart1Config, chart2Config],
4040
};
4141

4242
let dashboardId = '';
@@ -46,7 +46,7 @@ describe('Cls dashboard', () => {
4646
expect(res).toEqual({
4747
id: expect.stringContaining('dashboard-'),
4848
name: inputs.name,
49-
chartList: expect.any(Array),
49+
charts: expect.any(Array),
5050
});
5151

5252
dashboardId = res.id;
@@ -60,7 +60,7 @@ describe('Cls dashboard', () => {
6060
createTime: expect.any(String),
6161
id: expect.stringContaining('dashboard-'),
6262
name: expect.any(String),
63-
chartList: expect.any(Array),
63+
charts: expect.any(Array),
6464
});
6565
});
6666

@@ -73,7 +73,7 @@ describe('Cls dashboard', () => {
7373
id: expect.stringContaining('dashboard-'),
7474
name: expect.any(String),
7575
createTime: expect.any(String),
76-
chartList: expect.any(Array),
76+
charts: expect.any(Array),
7777
});
7878
});
7979

@@ -85,7 +85,7 @@ describe('Cls dashboard', () => {
8585
createTime: expect.any(String),
8686
id: expect.stringContaining('dashboard-'),
8787
name: expect.any(String),
88-
chartList: expect.any(Array),
88+
charts: expect.any(Array),
8989
});
9090
});
9191

src/modules/cls/dashboard.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -177,15 +177,15 @@ export type DeployDashChartInputs = Omit<DashboardChart, 'id'>;
177177

178178
export interface DeployDashboardInputs {
179179
name: string;
180-
chartList: DeployDashChartInputs[];
180+
charts: DeployDashChartInputs[];
181181
}
182182

183183
// camelCase 的 dashboard 结构,并作了简化
184184
export interface Dashboard {
185185
createTime: string;
186186
id: string;
187187
name: string;
188-
chartList: DashboardChart[];
188+
charts: DashboardChart[];
189189
}
190190

191191
export class ClsDashboard {
@@ -213,7 +213,7 @@ export class ClsDashboard {
213213
createTime: CreateTime,
214214
name: DashboardName,
215215
id: DashboardId,
216-
chartList: parseData.panels,
216+
charts: parseData.panels,
217217
};
218218

219219
return dashboard;
@@ -244,7 +244,7 @@ export class ClsDashboard {
244244
id,
245245
createTime: res.CreateTime,
246246
name: res.DashboardName,
247-
chartList: rawPanels.map((v) => ({
247+
charts: rawPanels.map((v) => ({
248248
id: v.id,
249249
title: v.title,
250250
description: v.description,
@@ -309,9 +309,9 @@ export class ClsDashboard {
309309

310310
// 创建 dashboard
311311
async deploy(inputs: DeployDashboardInputs, logsetConfig: LogsetConfig) {
312-
const { name, chartList } = inputs;
312+
const { name, charts } = inputs;
313313
const data = JSON.stringify({
314-
panels: chartList.map((v) => {
314+
panels: charts.map((v) => {
315315
const panel: Raw.DashboardChart = {
316316
id: 'chart-' + uuid.v4(),
317317
title: v.title,
@@ -376,7 +376,7 @@ export class ClsDashboard {
376376
return {
377377
id: dashboardId,
378378
name,
379-
chartList: inputs.chartList,
379+
charts: inputs.charts,
380380
};
381381
}
382382
}

src/modules/cls/index.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,19 @@ export default class Cls {
188188
}
189189
}
190190

191+
const { dashboards = [] } = inputs;
192+
if (dashboards.length > 0) {
193+
outputs.dashboards = [];
194+
for (let i = 0; i < dashboards.length; i++) {
195+
const res = await this.dashboard.deploy(dashboards[i], {
196+
region: outputs.region,
197+
logsetId: outputs.logsetId,
198+
topicId: outputs.topicId,
199+
});
200+
outputs.dashboards.push(res);
201+
}
202+
}
203+
191204
return outputs;
192205
}
193206

src/modules/cls/interface.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { IndexRule } from '@tencent-sdk/cls/dist/typings';
22
import { RegionType, CamelCasedProps } from './../interface';
3+
import { DeployDashboardInputs } from './dashboard';
34

45
export interface CreateAlarmOptions {
56
// 告警 ID
@@ -197,6 +198,7 @@ export interface DeployInputs extends DeployLogsetInputs, DeployTopicInputs, Dep
197198
name?: string;
198199
topic?: string;
199200
alarms?: AlarmInputs[];
201+
dashboards?: DeployDashboardInputs[];
200202
}
201203

202204
export interface DeployOutputs extends Partial<DeployInputs> {

0 commit comments

Comments
 (0)