Skip to content

Commit 2b59e42

Browse files
authored
fix: add cloud api request region param (#6)
* fixed bug * fix cloud api RequestLimitExceeded error * fixed ci error * fixed cloud api qps limit * change code style * add TencentCloudClient region param * change code style
1 parent c520127 commit 2b59e42

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

src/client.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@ var defaults = {
1414
}
1515

1616
class TencentCloudClient {
17-
constructor(credentials = {}, service = {}) {
17+
constructor(credentials = {}, service = {}, options = {}) {
1818
this.credentials = credentials
1919
this.service = service
20+
this.options = options
2021
}
2122

2223
async cloudApiGenerateQueryString(data) {
2324
var param = assign(
2425
{
25-
Region: defaults.Region,
26+
Region: this.options.region || defaults.Region,
2627
SecretId: this.credentials.SecretId,
2728
Timestamp: Math.round(Date.now() / 1000),
2829
Nonce: Math.round(Math.random() * 65535),
@@ -618,6 +619,7 @@ class SlsMonitor {
618619
}
619620
}
620621
if (requestHandlers.length == 0) {
622+
console.log('getCustomMetrics', JSON.stringify(responses))
621623
this.aggrCustomDatas(responses, period, metricAttributeHash)
622624
return responses
623625
}
@@ -627,15 +629,22 @@ class SlsMonitor {
627629

628630
results = await getMetricsResponse(requestHandlers)
629631
responses = responses.concat(results)
632+
console.log('getCustomMetrics', JSON.stringify(responses))
630633
this.aggrCustomDatas(responses, period, metricAttributeHash)
631634
return responses
632635
}
633636

634637
async getScfMetrics(region, rangeTime, period, funcName, ns, version) {
635-
const client = new TencentCloudClient(this.credentials, {
636-
host: 'monitor.tencentcloudapi.com',
637-
path: '/'
638-
})
638+
const client = new TencentCloudClient(
639+
this.credentials,
640+
{
641+
host: 'monitor.tencentcloudapi.com',
642+
path: '/'
643+
},
644+
{
645+
region: region
646+
}
647+
)
639648
const req = {
640649
Action: 'GetMonitorData',
641650
Version: '2018-07-24'
@@ -686,11 +695,8 @@ class SlsMonitor {
686695
return new Promise((resolve, reject) => {
687696
Promise.all(requestHandlers)
688697
.then((results) => {
698+
console.log('getScfMetrics', JSON.stringify(results))
689699
this.aggrDurationP(results, durationPeriod, period)
690-
691-
// if (aggrFlag)
692-
// this.aggregationByDay(results)
693-
694700
resolve(results)
695701
})
696702
.catch((error) => {

0 commit comments

Comments
 (0)