Skip to content

Commit 2fd3aca

Browse files
committed
merge code
2 parents 9b29a80 + 378c0c4 commit 2fd3aca

File tree

3 files changed

+45
-48
lines changed

3 files changed

+45
-48
lines changed

package.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "tencent-cloud-sdk",
33
"description": "Tencent Cloud SDK For Serverless Framework",
4-
"version": "0.0.5",
4+
"version": "0.0.7",
55
"main": "./index.js",
66
"publishConfig": {
77
"access": "public"
@@ -18,13 +18,10 @@
1818
"author": "Dfounderliu",
1919
"license": "Apache",
2020
"dependencies": {
21-
"configstore": "3.1.2",
22-
"dot-qs": "0.2.0",
23-
"mime-types": "2.1.24",
24-
"object-assign": "3.0.0",
25-
"xml2js": "0.4.19",
2621
"caseless": "0.12.0",
2722
"combined-stream": "1.0.6",
23+
"configstore": "3.1.2",
24+
"dot-qs": "0.2.0",
2825
"extend": "3.0.2",
2926
"forever-agent": "0.6.1",
3027
"form-data": "2.3.2",
@@ -33,13 +30,17 @@
3330
"is-typedarray": "1.0.0",
3431
"isstream": "0.1.2",
3532
"json-stringify-safe": "5.0.1",
33+
"mime-types": "2.1.24",
34+
"moment": "^2.24.0",
3635
"oauth-sign": "0.9.0",
36+
"object-assign": "3.0.0",
3737
"performance-now": "2.1.0",
3838
"qs": "6.5.2",
3939
"safe-buffer": "5.1.2",
4040
"tough-cookie": "2.5.0",
4141
"tunnel-agent": "0.6.0",
42-
"uuid": "3.3.2"
42+
"uuid": "3.3.2",
43+
"xml2js": "0.4.19"
4344
},
4445
"devDependencies": {
4546
"babel-eslint": "9.0.0",

src/client.js

Lines changed: 34 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,18 @@ class TagClient {
127127
}
128128
}
129129

130+
class TcbClient {
131+
constructor(credentials = {}) {
132+
this.credentials = credentials
133+
}
134+
async request(data) {
135+
return await new TencentCloudClient(this.credentials, {
136+
host: 'tcb.tencentcloudapi.com',
137+
path: '/'
138+
}).doCloudApiRequest(data)
139+
}
140+
}
141+
130142
class ApigwClient {
131143
constructor(credentials = {}) {
132144
this.credentials = credentials
@@ -151,6 +163,18 @@ class CamClient {
151163
}
152164
}
153165

166+
class CamV2Client {
167+
constructor(credentials = {}) {
168+
this.credentials = credentials
169+
}
170+
async request(data) {
171+
return await new TencentCloudClient(this.credentials, {
172+
host: 'cam.api.qcloud.com',
173+
path: '/v2/index.php'
174+
}).doCloudApiRequest(data)
175+
}
176+
}
177+
154178
class CnsClient {
155179
constructor(credentials = {}) {
156180
this.credentials = credentials
@@ -182,23 +206,6 @@ class SlsMonitor {
182206
this.credentials = credentials
183207
}
184208

185-
static rfc3339(t) {
186-
const year = t.getFullYear()
187-
const month = t.getMonth() + 1
188-
const day = t.getDate()
189-
const hours = t.getHours()
190-
const minutes = t.getMinutes()
191-
const sec = t.getSeconds()
192-
193-
const offset = Math.abs(t.getTimezoneOffset())
194-
const offsetH = Math.floor(offset / 60)
195-
const offsetM = offset % 60
196-
197-
return util.format('%d-%s-%sT%s:%s:%s+%s:%s', year, month.toString().padStart(2, 0),
198-
day.toString().padStart(2, 0), hours.toString().padStart(2, 0), minutes.toString().padStart(2, 0), sec.toString().padStart(2, 0), offsetH.toString().padStart(2, 0),
199-
offsetM.toString().padStart(2, 0))
200-
}
201-
202209
async request(data) {
203210
return await new TencentCloudClient(this.credentials, {
204211
host: 'monitor.tencentcloudapi.com',
@@ -231,7 +238,7 @@ class SlsMonitor {
231238
}
232239
}
233240

234-
async getScfMetrics(region, rangeTime, funcName, ns, version) {
241+
async getScfMetrics(region, rangeTime, period, funcName, ns, version) {
235242
const client = new TencentCloudClient(this.credentials, {
236243
host: 'monitor.tencentcloudapi.com',
237244
path: '/'
@@ -240,32 +247,17 @@ class SlsMonitor {
240247
Action: 'GetMonitorData',
241248
Version: '2018-07-24',
242249
}
243-
if (rangeTime.rangeEnd <= rangeTime.rangeStart) {
244-
throw new Error('The rangeStart provided is after the rangeEnd')
245-
}
246250

247251
const metrics = ['Duration', 'Invocation', 'Error', 'ConcurrentExecutions', 'ConfigMem', 'FunctionErrorPercentage', 'Http2xx', 'Http432', 'Http433', 'Http434', 'Http4xx', 'Mem', 'MemDuration', 'Syserr'];
248252

249-
const diffMinutes = (rangeTime.rangeEnd - rangeTime.rangeStart) / 1000 / 60
250-
let period,
251-
aggrFlag = false
252-
253-
if (diffMinutes <= 16) {
254-
// 16 mins
255-
period = 60 // 1 min
256-
} else if (diffMinutes <= 61) {
257-
// 1 hour
258-
period = 300 // 5 mins
259-
} else if (diffMinutes <= 1500) {
260-
// 24 hours
261-
period = 3600 // hour
262-
} else {
253+
let aggrFlag = false
254+
if (period == 86400) {
263255
period = 3600 // day
264256
aggrFlag = true
265257
}
266258
const result = {
267-
rangeStart: SlsMonitor.rfc3339(rangeTime.rangeStart),
268-
rangeEnd: SlsMonitor.rfc3339(rangeTime.rangeEnd),
259+
rangeStart: rangeTime.rangeStart,
260+
rangeEnd: rangeTime.rangeEnd,
269261
metrics: []
270262
}
271263

@@ -274,8 +266,8 @@ class SlsMonitor {
274266
req.Namespace = 'qce/scf_v2';
275267
req.MetricName = metrics[i];
276268
req.Period = period;
277-
req.StartTime = SlsMonitor.rfc3339(rangeTime.rangeStart);
278-
req.EndTime = SlsMonitor.rfc3339(rangeTime.rangeEnd);
269+
req.StartTime = rangeTime.rangeStart;
270+
req.EndTime = rangeTime.rangeEnd;
279271
req.Instances = [{
280272
Dimensions: [
281273
{
@@ -311,9 +303,11 @@ module.exports = {
311303
ScfClient,
312304
TagClient,
313305
CamClient,
306+
CamV2Client,
314307
CnsClient,
315308
ApigwClient,
316309
DomainClient,
317310
CosClient,
318-
SlsMonitor
311+
SlsMonitor,
312+
TcbClient
319313
}

src/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
module.exports = {
22
scf: require('./client').ScfClient,
33
cam: require('./client').CamClient,
4+
camv2: require('./client').CamV2Client,
45
cns: require('./client').CnsClient,
56
tag: require('./client').TagClient,
67
apigw: require('./client').ApigwClient,
78
domain: require('./client').DomainClient,
89
cos: require('./client').CosClient,
9-
slsMonitor: require('./client').SlsMonitor
10+
slsMonitor: require('./client').SlsMonitor,
11+
tcb: require('./client').TcbClient
1012
}

0 commit comments

Comments
 (0)