Skip to content

Commit c6ae4c9

Browse files
authored
fix: cloud api qps limit (#5)
* fixed bug * fix cloud api RequestLimitExceeded error * fixed ci error * fixed cloud api qps limit * change code style
1 parent 39d745b commit c6ae4c9

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/client.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ class SlsMonitor {
550550
}
551551

552552
async getCustomMetrics(region, announceInstance, rangeTime, period) {
553-
const apiQPSLimit = 8
553+
const apiQPSLimit = 100
554554
const metricsRule = [
555555
/^(GET|POST|DEL|DELETE|PUT|OPTIONS|HEAD)_([a-zA-Z0-9]+)_latency$/i,
556556
/^(GET|POST|DEL|DELETE|PUT|OPTIONS|HEAD)_([a-zA-Z0-9]+)_(\d+)$/i,
@@ -588,7 +588,9 @@ class SlsMonitor {
588588
let requestHandlers = []
589589
let responses = []
590590
let results
591-
const attributes = await this.describeAttributes(0, 100)
591+
let firstRequestFlag = true
592+
593+
const attributes = await this.describeAttributes(0, 200)
592594
for (var i = 0; i < attributes.Response.Data.TotalCount; i++) {
593595
const metricAttribute = attributes.Response.Data.Data[i]
594596

@@ -605,10 +607,11 @@ class SlsMonitor {
605607
)
606608
)
607609

608-
if (i > 0 && !(i % apiQPSLimit)) {
609-
if (i != apiQPSLimit) {
610+
if (!((i + 1) % apiQPSLimit)) {
611+
if (i + 1 != apiQPSLimit) {
610612
await SlsMonitor.sleep(1000)
611613
}
614+
firstRequestFlag = false
612615
results = await getMetricsResponse(requestHandlers)
613616
responses = responses.concat(results)
614617
requestHandlers = []
@@ -618,7 +621,10 @@ class SlsMonitor {
618621
this.aggrCustomDatas(responses, period, metricAttributeHash)
619622
return responses
620623
}
621-
await SlsMonitor.sleep(600)
624+
if (!firstRequestFlag) {
625+
await SlsMonitor.sleep(1000)
626+
}
627+
622628
results = await getMetricsResponse(requestHandlers)
623629
responses = responses.concat(results)
624630
this.aggrCustomDatas(responses, period, metricAttributeHash)

0 commit comments

Comments
 (0)