diff --git a/package.json b/package.json index 951cd104..927787d2 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "delay": "^4.0.1", "extend": "^3.0.2", "gcp-metadata": "^4.0.0", - "parse-duration": "^0.1.1", + "parse-duration": "^0.4.4", "pprof": "2.0.0", "pretty-ms": "^7.0.0", "protobufjs": "~6.10.0", @@ -48,7 +48,6 @@ "@types/mocha": "^8.0.0", "@types/nock": "^10.0.0", "@types/node": "^10.0.3", - "@types/parse-duration": "^0.1.0", "@types/pretty-ms": "^4.0.0", "@types/sinon": "^9.0.0", "@types/tmp": "0.2.0", diff --git a/src/config.ts b/src/config.ts index 577e230d..d89c4963 100644 --- a/src/config.ts +++ b/src/config.ts @@ -13,7 +13,7 @@ // limitations under the License. import {GoogleAuthOptions} from '@google-cloud/common'; -import parseDuration = require('parse-duration'); +import parseDuration from 'parse-duration'; // Configuration for Profiler. export interface Config extends GoogleAuthOptions { diff --git a/src/profiler.ts b/src/profiler.ts index 89d9c5fe..61e2f910 100644 --- a/src/profiler.ts +++ b/src/profiler.ts @@ -17,6 +17,7 @@ import { ServiceConfig, ServiceObject, ApiError, + DecorateRequestOptions, } from '@google-cloud/common'; import {heap as heapProfiler, SourceMapper, time as timeProfiler} from 'pprof'; import * as msToStr from 'pretty-ms'; @@ -28,7 +29,7 @@ import {perftools} from '../protos/profile'; import {ProfilerConfig} from './config'; import {createLogger} from './logger'; -import parseDuration = require('parse-duration'); +import parseDuration from 'parse-duration'; // eslint-disable-next-line @typescript-eslint/no-var-requires const pjson = require('../../package.json'); const SCOPE = 'https://www.googleapis.com/auth/monitoring.write'; @@ -110,7 +111,7 @@ function getServerResponseBackoff(body: object): number | undefined { item.retryDelay && typeof item.retryDelay === 'string' ) { - const backoffMillis = parseDuration(item.retryDelay); + const backoffMillis = parseDuration(item.retryDelay)!; if (backoffMillis > 0) { return backoffMillis; } @@ -135,7 +136,7 @@ export function parseBackoffDuration( undefined, ]; if (duration) { - const backoffMillis = parseDuration(duration); + const backoffMillis = parseDuration(duration)!; if (backoffMillis > 0) { return backoffMillis; } @@ -434,7 +435,7 @@ export class Profiler extends ServiceObject { deployment: this.deployment, profileType: this.profileTypes, }; - const options = { + const options: DecorateRequestOptions = { method: 'POST', uri: '/profiles', body: reqBody, @@ -444,7 +445,7 @@ export class Profiler extends ServiceObject { // Default timeout for for a request is 1 minute, but request to create // profile is designed to hang until it is time to collect a profile // (up to one hour). - timeout: parseDuration('1h'), + timeout: parseDuration('1h')!, }; this.logger.debug('Attempting to create profile.'); diff --git a/test/test-profiler.ts b/test/test-profiler.ts index 71565364..9251fb6d 100644 --- a/test/test-profiler.ts +++ b/test/test-profiler.ts @@ -37,7 +37,7 @@ import { timeProfile, } from './profiles-for-tests'; -import parseDuration = require('parse-duration'); +import parseDuration from 'parse-duration'; // eslint-disable-next-line @typescript-eslint/no-var-requires const fakeCredentials = require('../../test/fixtures/gcloud-credentials.json'); @@ -61,9 +61,9 @@ const testConfig: ProfilerConfig = { heapMaxStackDepth: 64, ignoreHeapSamplesPath: '@google-cloud/profiler', initialBackoffMillis: 1000, - backoffCapMillis: parseDuration('1h'), + backoffCapMillis: parseDuration('1h')!, backoffMultiplier: 1.3, - serverBackoffCapMillis: parseDuration('7d'), + serverBackoffCapMillis: parseDuration('7d')!, localProfilingPeriodMillis: 1000, localTimeDurationMillis: 1000, localLogPeriodMillis: 1000,