Skip to content

Commit f236089

Browse files
syzhyugasun
authored andcommitted
bugfix: fixed response data error
1 parent 02148d9 commit f236089

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/client.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,41 @@ class SlsMonitor {
829829
}
830830
}
831831

832+
aggrApigwDatas(responses) {
833+
for (let i = 0; i < responses.length; i++) {
834+
const response = responses[i].Response
835+
if (response.Error) {
836+
console.log(JSON.stringify(response.Error), response.RequestId)
837+
continue
838+
}
839+
if (response.DataPoints[0].Timestamps.length == 0) {
840+
continue
841+
}
842+
843+
const startTime = new Date(response.StartTime)
844+
845+
let offset = 0
846+
if (startTime.getTimezoneOffset() == 0) {
847+
offset = 8 * 60 * 60
848+
}
849+
const startTimestamp = startTime.getTime() / 1000 - offset
850+
851+
const startPads = this.padPart(
852+
startTimestamp,
853+
response.DataPoints[0].Timestamps[0],
854+
response.Period
855+
)
856+
if (startPads.timestamp.length > 0) {
857+
response.DataPoints[0].Timestamps = startPads.timestamp.concat(
858+
response.DataPoints[0].Timestamps
859+
)
860+
}
861+
if (startPads.values.length > 0) {
862+
response.DataPoints[0].Values = startPads.values.concat(response.DataPoints[0].Values)
863+
}
864+
}
865+
}
866+
832867
async getApigwMetrics(region, rangeTime, period, serviceId, env) {
833868
const metricName = ['NumOfReq', 'ResponseTime']
834869
const client = new TencentCloudClient(
@@ -875,6 +910,7 @@ class SlsMonitor {
875910
return new Promise((resolve, reject) => {
876911
Promise.all(requestHandlers)
877912
.then((results) => {
913+
this.aggrApigwDatas(results)
878914
resolve(results)
879915
})
880916
.catch((error) => {

0 commit comments

Comments
 (0)