Skip to content

Commit 66fb7c7

Browse files
syzhyugasun
authored andcommitted
change code style
1 parent aaa1c70 commit 66fb7c7

File tree

2 files changed

+22
-34
lines changed

2 files changed

+22
-34
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666
"performance-now": "2.1.0",
6767
"qs": "6.5.2",
6868
"safe-buffer": "5.1.2",
69-
"sleep": "^6.3.0",
7069
"tough-cookie": "2.5.0",
7170
"tunnel-agent": "0.6.0",
7271
"uuid": "3.3.2",

src/client.js

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ const request = require('../lib/request/index')
55
const crypto = require('crypto')
66
const cos = require('../lib/cos/cos')
77
const _ = require('lodash')
8-
const sleep = require('sleep')
98

109
const DEFAULTS = {
1110
signatureMethod: 'HmacSHA1',
@@ -466,7 +465,6 @@ class SlsMonitor {
466465
}
467466

468467
async describeCCMInstanceDatas(id, instances, startTime, endTime, i, limit) {
469-
470468
const client = new TencentCloudClient(this.credentials, {
471469
host: 'monitor.tencentcloudapi.com',
472470
path: '/'
@@ -486,14 +484,15 @@ class SlsMonitor {
486484
if (!((i + 1) % limit)) {
487485
sleep = true
488486
}
489-
return new Promise(function(resolve, rejecte) {
487+
488+
return new Promise(function(resolve) {
490489
if (!sleep) {
491490
return resolve(client.doCloudApiRequest(req))
492491
}
493492
setTimeout(function() {
494493
resolve(client.doCloudApiRequest(req))
495494
}, timeCost)
496-
});
495+
})
497496
}
498497

499498
async describeAttributes(offset, limit) {
@@ -524,18 +523,6 @@ class SlsMonitor {
524523
/^5xx$/i
525524
]
526525

527-
const getMetricsResponse = (promiseHandlers) => {
528-
return new Promise((resolve, reject) => {
529-
Promise.all(promiseHandlers)
530-
.then((results) => {
531-
resolve(results)
532-
})
533-
.catch((error) => {
534-
reject(error)
535-
})
536-
})
537-
}
538-
539526
const filterAttributeName = function(name, mRule) {
540527
const len = mRule.length
541528
for (var i = 0; i < len; i++) {
@@ -547,37 +534,39 @@ class SlsMonitor {
547534
}
548535

549536
const metricAttributeHash = {}
550-
let requestHandlers = []
551-
let responses = []
552-
let results
553-
let firstRequestFlag = true
537+
const responses = []
554538
const attributes = await this.describeAttributes(0, 200)
555539
attributes.Response.Data.Data.push(attributes.Response.Data.Data[10])
556540

557541
let i = 0
558542
const _this = this
559543
function run() {
560-
if(attributes.Response.Data.Data.length > 0) {
544+
if (attributes.Response.Data.Data.length > 0) {
561545
const metricAttribute = attributes.Response.Data.Data.shift()
562546
metricAttributeHash[metricAttribute.AttributeId] = metricAttribute
563-
564-
return _this.describeCCMInstanceDatas(
565-
metricAttribute.AttributeId,
566-
announceInstance,
567-
rangeTime.rangeStart,
568-
rangeTime.rangeEnd,
569-
i++, apiQPSLimit
570-
).then(res => {
571-
responses.push(res)
547+
if (!filterAttributeName(metricAttribute.AttributeName, metricsRule)) {
572548
return run()
573-
})
549+
}
550+
return _this
551+
.describeCCMInstanceDatas(
552+
metricAttribute.AttributeId,
553+
announceInstance,
554+
rangeTime.rangeStart,
555+
rangeTime.rangeEnd,
556+
i++,
557+
apiQPSLimit
558+
)
559+
.then((res) => {
560+
responses.push(res)
561+
return run()
562+
})
574563
}
575564
}
576565

577566
const promiseList = Array(Math.min(apiQPSLimit, attributes.Response.Data.Data.length))
578567
.fill(Promise.resolve())
579-
.map(promise => promise.then(run))
580-
568+
.map((promise) => promise.then(run))
569+
581570
return Promise.all(promiseList).then(() => {
582571
this.aggrCustomDatas(responses, period, metricAttributeHash)
583572
return responses

0 commit comments

Comments
 (0)