From 6a1330f4c8fb34bcb40b548e7a115d21d763d087 Mon Sep 17 00:00:00 2001 From: Maggie Nolan Date: Wed, 14 Aug 2019 10:41:17 -0700 Subject: [PATCH] fix(dep): update to be compatible with @google-cloud/common 2.1.X --- package.json | 3 ++- ts/src/profiler.ts | 42 +++++++++++++++++++++++++--------------- ts/test/test-profiler.ts | 8 ++++++-- 3 files changed, 34 insertions(+), 19 deletions(-) diff --git a/package.json b/package.json index 27933abb..a7644431 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ }, "license": "Apache-2.0", "dependencies": { - "@google-cloud/common": "^2.0.0", + "@google-cloud/common": "^2.1.2", "@types/console-log-level": "^1.4.0", "@types/semver": "^6.0.0", "console-log-level": "^1.4.0", @@ -65,6 +65,7 @@ "nyc": "^14.1.0", "sinon": "^7.3.2", "source-map-support": "^0.5.6", + "teeny-request": "^5.2.0", "tmp": "0.1.0", "typescript": "~3.5.0" }, diff --git a/ts/src/profiler.ts b/ts/src/profiler.ts index a9ce9d39..bb495edd 100644 --- a/ts/src/profiler.ts +++ b/ts/src/profiler.ts @@ -14,12 +14,18 @@ * limitations under the License. */ -import {Service, ServiceConfig, ServiceObject} from '@google-cloud/common'; +import { + Service, + ServiceConfig, + ServiceObject, + ApiError, +} from '@google-cloud/common'; import * as http from 'http'; import {heap as heapProfiler, SourceMapper, time as timeProfiler} from 'pprof'; import * as msToStr from 'pretty-ms'; import {promisify} from 'util'; import * as zlib from 'zlib'; +import * as r from 'teeny-request'; import {perftools} from '../../proto/profile'; @@ -78,7 +84,8 @@ export interface RequestProfile { * message. */ function getResponseErrorMessage( - response: http.IncomingMessage, + // tslint:disable-next-line: no-any + response: r.Response, err: Error | null ): string | undefined { if (err && err.message) { @@ -244,7 +251,8 @@ export class Retryer { function responseToProfileOrError( err: Error | null, body?: object, - response?: http.IncomingMessage + // tslint:disable-next-line: no-any + response?: r.Response ): RequestProfile { // response.statusCode is guaranteed to exist on client requests. if (response && isErrorResponseStatusCode(response.statusCode!)) { @@ -440,20 +448,22 @@ export class Profiler extends ServiceObject { this.logger.debug(`Attempting to create profile.`); return new Promise((resolve, reject) => { - this.request( - options, - (err: Error | null, body?: object, response?: http.IncomingMessage) => { - try { - const prof = responseToProfileOrError(err, body, response); - this.logger.debug( - `Successfully created profile ${prof.profileType}.` - ); - resolve(prof); - } catch (err) { - reject(err); - } + this.request(options, ( + err: Error | ApiError | null, + body?: object, + // tslint:disable-next-line: no-any + response?: r.Response + ) => { + try { + const prof = responseToProfileOrError(err, body, response); + this.logger.debug( + `Successfully created profile ${prof.profileType}.` + ); + resolve(prof); + } catch (err) { + reject(err); } - ); + }); }); } diff --git a/ts/test/test-profiler.ts b/ts/test/test-profiler.ts index 8a290caf..8ebe2cb3 100644 --- a/ts/test/test-profiler.ts +++ b/ts/test/test-profiler.ts @@ -297,7 +297,9 @@ describe('Profiler', () => { const profiler = new Profiler(testConfig); await profiler.profileAndUpload(requestProf); - const uploaded = requestStub.firstCall.args[0].body; + const uploaded = requestStub.firstCall.args[0].body as { + profileBytes?: string; + }; const decodedBytes = Buffer.from( uploaded.profileBytes as string, 'base64' @@ -326,7 +328,9 @@ describe('Profiler', () => { const profiler = new Profiler(testConfig); await profiler.profileAndUpload(requestProf); - const uploaded = requestStub.firstCall.args[0].body; + const uploaded = requestStub.firstCall.args[0].body as { + profileBytes?: string; + }; const decodedBytes = Buffer.from( uploaded.profileBytes as string, 'base64'