Skip to content

Commit d452db7

Browse files
committed
fix: cls for scf cant update index, dont throw and use warning
1 parent 25fea99 commit d452db7

File tree

3 files changed

+62
-12
lines changed

3 files changed

+62
-12
lines changed

__tests__/cls/cls.test.ts

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,46 @@ import { Scf } from '../../src';
33
import { Cls } from '../../src';
44
import { sleep } from '@ygkit/request';
55

6-
describe('Cls', () => {
7-
const credentials = {
8-
SecretId: process.env.TENCENT_SECRET_ID,
9-
SecretKey: process.env.TENCENT_SECRET_KEY,
6+
const credentials = {
7+
SecretId: process.env.TENCENT_SECRET_ID,
8+
SecretKey: process.env.TENCENT_SECRET_KEY,
9+
};
10+
11+
describe('Scf Cls', () => {
12+
const client = new Cls(credentials, process.env.REGION);
13+
14+
const inputs: DeployInputs = {
15+
region: 'ap-guangzhou',
16+
name: 'SCF_logset_zyIdCSDW',
17+
topic: 'SCF_logtopic_QExYJrDj',
18+
period: 7,
19+
rule: {
20+
full_text: {
21+
case_sensitive: true,
22+
tokenizer: '!@#%^&*()_="\', <>/?|\\;:\n\t\r[]{}',
23+
},
24+
key_value: {
25+
case_sensitive: true,
26+
keys: ['SCF_RetMsg'],
27+
types: ['text'],
28+
tokenizers: [' '],
29+
},
30+
},
1031
};
32+
33+
test('deploy cls', async () => {
34+
const res = await client.deploy(inputs);
35+
expect(res).toEqual({
36+
region: process.env.REGION,
37+
name: inputs.name,
38+
topic: inputs.topic,
39+
logsetId: expect.any(String),
40+
topicId: expect.any(String),
41+
});
42+
});
43+
});
44+
45+
describe('Normal Cls', () => {
1146
const scf = new Scf(credentials, process.env.REGION);
1247
const client = new Cls(credentials, process.env.REGION);
1348

src/modules/cls/dashboard.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ export class ClsDashboard {
196196

197197
// 获取 dashboard 列表
198198
async getList(): Promise<Dashboard[]> {
199-
console.log(`Getting dashboard list}`);
199+
console.log(`Getting dashboard list`);
200200
const res = await this.cls.clsClient.request({
201201
method: 'GET',
202202
path: '/dashboards',
@@ -248,7 +248,7 @@ export class ClsDashboard {
248248
try {
249249
parseData = JSON.parse(res.data);
250250
} catch (err) {
251-
console.log(`get detail: ${id}, data: ${res.data}`);
251+
console.log(`Get detail failed: ${id}, data: ${res.data}`);
252252
}
253253
const rawPanels: Raw.DashboardChart[] = parseData.panels;
254254

src/modules/cls/index.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,27 @@ export default class Cls {
152152

153153
// 更新索引
154154
async deployIndex(inputs: DeployIndexInputs) {
155-
await updateIndex(this.clsClient, {
156-
topicId: inputs.topicId!,
157-
// FIXME: effective is always true in updateIndex
158-
effective: inputs.effective !== false ? true : false,
159-
rule: inputs.rule,
160-
});
155+
if (inputs.rule) {
156+
console.log('Deploying index');
157+
158+
try {
159+
await updateIndex(this.clsClient, {
160+
topicId: inputs.topicId!,
161+
// FIXME: effective is always true in updateIndex
162+
effective: inputs.effective !== false ? true : false,
163+
rule: inputs.rule,
164+
});
165+
} catch (err) {
166+
console.log('' + err);
167+
if (err.message.includes('403')) {
168+
console.log('Cant update index of CLS for SCF');
169+
} else {
170+
throw err;
171+
}
172+
}
173+
174+
// TODO: SCF Logset 403
175+
}
161176
}
162177

163178
// 部署

0 commit comments

Comments
 (0)