Skip to content

Commit ff342c8

Browse files
committed
bugfix: fixed response data error
1 parent 02148d9 commit ff342c8

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

src/client.js

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

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

0 commit comments

Comments
 (0)