Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dep): update to be compatible with @google-cloud/common 2.1.X #529

Merged
merged 1 commit into from
Aug 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"
},
Expand Down
42 changes: 26 additions & 16 deletions ts/src/profiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -78,7 +84,8 @@ export interface RequestProfile {
* message.
*/
function getResponseErrorMessage(
response: http.IncomingMessage,
// tslint:disable-next-line: no-any
response: r.Response<any>,
err: Error | null
): string | undefined {
if (err && err.message) {
Expand Down Expand Up @@ -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<any>
): RequestProfile {
// response.statusCode is guaranteed to exist on client requests.
if (response && isErrorResponseStatusCode(response.statusCode!)) {
Expand Down Expand Up @@ -440,20 +448,22 @@ export class Profiler extends ServiceObject {

this.logger.debug(`Attempting to create profile.`);
return new Promise<RequestProfile>((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<any>
) => {
try {
const prof = responseToProfileOrError(err, body, response);
this.logger.debug(
`Successfully created profile ${prof.profileType}.`
);
resolve(prof);
} catch (err) {
reject(err);
}
);
});
});
}

Expand Down
8 changes: 6 additions & 2 deletions ts/test/test-profiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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'
Expand Down