diff --git a/CHANGELOG.md b/CHANGELOG.md index baa1372..2e0bfee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## [1.0.2](https://github.com/serverless-tencent/tencent-cloud-sdk/compare/v1.0.1...v1.0.2) (2020-08-10) + + +### Bug Fixes + +* make default to DEFAULTS ([965d6d4](https://github.com/serverless-tencent/tencent-cloud-sdk/commit/965d6d49eb98144892006410eed0c3bd54432532)) + ## [1.0.1](https://github.com/serverless-tencent/tencent-cloud-sdk/compare/v1.0.0...v1.0.1) (2020-08-07) diff --git a/package.json b/package.json index 1a817cd..aa5d967 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "tencent-cloud-sdk", "description": "Tencent Cloud SDK For Serverless Framework", - "version": "1.0.1", + "version": "1.0.2", "main": "./index.js", "publishConfig": { "access": "public" diff --git a/src/client.js b/src/client.js index e44a276..02a22fd 100644 --- a/src/client.js +++ b/src/client.js @@ -6,7 +6,7 @@ const crypto = require('crypto') const cos = require('../lib/cos/cos') const _ = require('lodash') -var defaults = { +const DEFAULTS = { signatureMethod: 'HmacSHA1', method: 'GET', Region: 'ap-guangzhou', @@ -23,7 +23,7 @@ class TencentCloudClient { async cloudApiGenerateQueryString(data) { var param = assign( { - Region: this.options.region || defaults.Region, + Region: this.options.region || DEFAULTS.Region, SecretId: this.credentials.SecretId, Timestamp: Math.round(Date.now() / 1000), Nonce: Math.round(Math.random() * 65535), @@ -38,7 +38,7 @@ class TencentCloudClient { if (this.credentials.token) { param.token = this.credentials.token } - param.SignatureMethod = defaults.signatureMethod + param.SignatureMethod = DEFAULTS.signatureMethod param = dotQs.flatten(param) const { host, path } = this.service var keys = Object.keys(param) @@ -59,7 +59,7 @@ class TencentCloudClient { const hmac = crypto.createHmac('sha1', this.credentials.SecretKey || '') param.Signature = hmac - .update(new Buffer.from(defaults.method.toUpperCase() + host + path + '?' + qstr, 'utf8')) + .update(new Buffer.from(DEFAULTS.method.toUpperCase() + host + path + '?' + qstr, 'utf8')) .digest('base64') return qs.stringify(param) @@ -829,6 +829,41 @@ class SlsMonitor { } } + aggrApigwDatas(responses) { + for (let i = 0; i < responses.length; i++) { + const response = responses[i].Response + if (response.Error) { + console.log(JSON.stringify(response.Error), response.RequestId) + continue + } + if (response.DataPoints[0].Timestamps.length == 0) { + continue + } + + const startTime = new Date(response.StartTime) + + let offset = 0 + if (startTime.getTimezoneOffset() == 0) { + offset = 8 * 60 * 60 + } + const startTimestamp = startTime.getTime() / 1000 - offset + + const startPads = this.padPart( + startTimestamp, + response.DataPoints[0].Timestamps[0], + response.Period + ) + if (startPads.timestamp.length > 0) { + response.DataPoints[0].Timestamps = startPads.timestamp.concat( + response.DataPoints[0].Timestamps + ) + } + if (startPads.values.length > 0) { + response.DataPoints[0].Values = startPads.values.concat(response.DataPoints[0].Values) + } + } + } + async getApigwMetrics(region, rangeTime, period, serviceId, env) { const metricName = ['NumOfReq', 'ResponseTime'] const client = new TencentCloudClient( @@ -875,6 +910,7 @@ class SlsMonitor { return new Promise((resolve, reject) => { Promise.all(requestHandlers) .then((results) => { + this.aggrApigwDatas(results) resolve(results) }) .catch((error) => {