Skip to content

Commit

Permalink
fix: upgrade to the latest @google-cloud/common (#187)
Browse files Browse the repository at this point in the history
* fix: upgrade to the latest @google-cloud/common

* pr feedback

* update deps

* 🙄
  • Loading branch information
JustinBeckwith authored and nolanmar511 committed May 2, 2018
1 parent aefa6b2 commit 24bd4dd
Show file tree
Hide file tree
Showing 9 changed files with 1,873 additions and 1,232 deletions.
2,726 changes: 1,849 additions & 877 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
},
"license": "Apache-2.0",
"dependencies": {
"@google-cloud/common": "^0.17.0",
"@google-cloud/common": "^0.18.3",
"bindings": "^1.2.1",
"delay": "^2.0.0",
"extend": "^3.0.1",
Expand Down
7 changes: 3 additions & 4 deletions ts/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@
* limitations under the License.
*/

import {AuthenticationConfig, Common, ServiceConfig} from '../third_party/types/common-types';
import {GoogleAuthOptions} from '@google-cloud/common';

const parseDuration: (str: string) => number = require('parse-duration');
const common: Common = require('@google-cloud/common');
const extend = require('extend');

// Configuration for Profiler.
export interface Config extends AuthenticationConfig {
export interface Config extends GoogleAuthOptions {
// Cloud Console projectId to associate profiles with instead of one read
// from VM metadata server.
projectId?: string;
Expand Down Expand Up @@ -124,7 +123,7 @@ export interface Config extends AuthenticationConfig {
}

// Interface for an initialized config.
export interface ProfilerConfig extends AuthenticationConfig {
export interface ProfilerConfig extends GoogleAuthOptions {
projectId?: string;
logLevel: number;
serviceContext: {service: string; version?: string;};
Expand Down
16 changes: 8 additions & 8 deletions ts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

import {Logger, util} from '@google-cloud/common';
import * as delay from 'delay';
import * as extend from 'extend';
import * as gcpMetadata from 'gcp-metadata';
Expand All @@ -22,12 +23,9 @@ import {normalize} from 'path';
import * as pify from 'pify';
import * as semver from 'semver';

import {AuthenticationConfig, Common, ServiceConfig} from '../third_party/types/common-types';

import {Config, defaultConfig, ProfilerConfig} from './config';
import {Profiler} from './profiler';

const common: Common = require('@google-cloud/common');
const pjson = require('../../package.json');

/**
Expand All @@ -53,7 +51,7 @@ function hasService(config: Config):
* Exported for testing purposes.
*/
export async function initConfig(config: Config): Promise<ProfilerConfig> {
config = common.util.normalizeArguments(null, config);
config = util.normalizeArguments(null, config);

const envConfig: Config = {
projectId: process.env.GCLOUD_PROJECT,
Expand Down Expand Up @@ -141,8 +139,10 @@ export async function start(config: Config = {}): Promise<void> {
}

function logError(msg: string, config: Config) {
const logger = new common.logger(
{level: common.logger.LEVELS[config.logLevel || 2], tag: pjson.name});
const logger = new Logger({
level: Logger.DEFAULT_OPTIONS.levels[config.logLevel || 2],
tag: pjson.name
});
logger.error(msg);
}

Expand All @@ -156,8 +156,8 @@ export async function startLocal(config: Config = {}): Promise<void> {
const profiler = new Profiler(normalizedConfig);

// Set up periodic logging.
const logger = new common.logger({
level: common.logger.LEVELS[normalizedConfig.logLevel],
const logger = new Logger({
level: Logger.DEFAULT_OPTIONS.levels[normalizedConfig.logLevel],
tag: pjson.name
});
let heapProfileCount = 0;
Expand Down
24 changes: 11 additions & 13 deletions ts/src/profiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,19 @@
* limitations under the License.
*/

import {Logger, Service, ServiceObject, util} from '@google-cloud/common';
import * as http from 'http';
import * as path from 'path';
import * as pify from 'pify';
import * as msToStr from 'pretty-ms';
import * as zlib from 'zlib';

import {perftools} from '../../proto/profile';
import {Common, Logger, Service, ServiceObject} from '../third_party/types/common-types';

import {ProfilerConfig} from './config';
import {HeapProfiler} from './profilers/heap-profiler';
import {TimeProfiler} from './profilers/time-profiler';

export const common: Common = require('@google-cloud/common');
const parseDuration: (str: string) => number = require('parse-duration');
const pjson = require('../../package.json');
const SCOPE = 'https://www.googleapis.com/auth/monitoring.write';
Expand Down Expand Up @@ -207,7 +206,7 @@ function responseToProfileOrError(
* Polls profiler server for instructions on behalf of a task and
* collects and uploads profiles as requested
*/
export class Profiler extends common.ServiceObject {
export class Profiler extends ServiceObject {
private config: ProfilerConfig;
private logger: Logger;
private profileLabels: {instance?: string};
Expand All @@ -220,17 +219,17 @@ export class Profiler extends common.ServiceObject {
heapProfiler: HeapProfiler|undefined;

constructor(config: ProfilerConfig) {
config = common.util.normalizeArguments(null, config);
config = util.normalizeArguments(null, config) as ProfilerConfig;
const serviceConfig = {
baseUrl: config.baseApiUrl,
scopes: [SCOPE],
packageJson: pjson,
};
super({parent: new common.Service(serviceConfig, config), baseUrl: '/'});
super({parent: new Service(serviceConfig, config), baseUrl: '/'});
this.config = config;

this.logger = new common.logger({
level: common.logger.LEVELS[config.logLevel as number],
this.logger = new Logger({
level: Logger.DEFAULT_OPTIONS.levels[config.logLevel as number],
tag: pjson.name
});

Expand Down Expand Up @@ -394,12 +393,11 @@ export class Profiler extends common.ServiceObject {
};

try {
const [body, serverResponse] = await this.request(options);
const response = serverResponse as http.ServerResponse;
if (isErrorResponseStatusCode(response.statusCode)) {
let message: number|string = response.statusCode;
if (response.statusMessage) {
message = response.statusMessage;
const res = await this.request(options);
if (isErrorResponseStatusCode(res.statusCode)) {
let message: number|string = res.statusCode;
if (res.statusMessage) {
message = res.statusMessage;
}
this.logger.debug(`Could not upload profile: ${message}.`);
return;
Expand Down
3 changes: 1 addition & 2 deletions ts/test/test-profiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

import * as common from '@google-cloud/common';
import * as assert from 'assert';
import * as extend from 'extend';
import * as nock from 'nock';
Expand All @@ -27,11 +28,9 @@ import {ProfilerConfig} from '../src/config';
import {Profiler, Retryer} from '../src/profiler';
import {HeapProfiler} from '../src/profilers/heap-profiler';
import {TimeProfiler} from '../src/profilers/time-profiler';
import {Common} from '../third_party/types/common-types';

import {decodedHeapProfile, decodedTimeProfile, heapProfile, timeProfile} from './profiles-for-tests';

const common: Common = require('@google-cloud/common');
const v8TimeProfiler = require('bindings')('time_profiler');
const parseDuration: (str: string) => number = require('parse-duration');

Expand Down
202 changes: 0 additions & 202 deletions ts/third_party/types/LICENSE

This file was deleted.

13 changes: 0 additions & 13 deletions ts/third_party/types/README.google

This file was deleted.

Loading

0 comments on commit 24bd4dd

Please sign in to comment.