diff --git a/src/createApiCall.ts b/src/createApiCall.ts index 9b785960a..7ed95e537 100644 --- a/src/createApiCall.ts +++ b/src/createApiCall.ts @@ -88,7 +88,8 @@ export function createApiCall( return retryable( func, thisSettings.retry!, - thisSettings.otherArgs as GRPCCallOtherArgs + thisSettings.otherArgs as GRPCCallOtherArgs, + thisSettings.apiName ); } return addTimeoutArg( diff --git a/src/gax.ts b/src/gax.ts index 2c566bc51..22a4a8e17 100644 --- a/src/gax.ts +++ b/src/gax.ts @@ -124,6 +124,7 @@ export interface CallOptions { bundleOptions?: BundleOptions | null; isBundling?: boolean; longrunning?: BackoffSettings; + apiName?: string; } export class CallSettings { @@ -138,6 +139,7 @@ export class CallSettings { bundleOptions?: BundleOptions | null; isBundling: boolean; longrunning?: BackoffSettings; + apiName?: string; /** * @param {Object} settings - An object containing parameters of this settings. @@ -170,6 +172,7 @@ export class CallSettings { this.isBundling = 'isBundling' in settings ? settings.isBundling! : true; this.longrunning = 'longrunning' in settings ? settings.longrunning : undefined; + this.apiName = settings.apiName ?? undefined; } /** @@ -193,6 +196,7 @@ export class CallSettings { let otherArgs = this.otherArgs; let isBundling = this.isBundling; let longrunning = this.longrunning; + let apiName = this.apiName; if ('timeout' in options) { timeout = options.timeout!; } @@ -239,6 +243,9 @@ export class CallSettings { if ('longrunning' in options) { longrunning = options.longrunning; } + if ('apiName' in options) { + apiName = options.apiName; + } return new CallSettings({ timeout, @@ -251,6 +258,7 @@ export class CallSettings { maxResults, otherArgs, isBundling, + apiName, }); } } @@ -650,7 +658,7 @@ export function constructSettings( )! ); } - + const apiName = serviceName; defaults[jsName] = new CallSettings({ timeout, retry, @@ -658,6 +666,7 @@ export function constructSettings( ? createBundleOptions(bundlingConfig) : null, otherArgs, + apiName, }); } diff --git a/src/normalCalls/retries.ts b/src/normalCalls/retries.ts index 31c50e7cd..18bc1f3fb 100644 --- a/src/normalCalls/retries.ts +++ b/src/normalCalls/retries.ts @@ -45,7 +45,8 @@ import {addTimeoutArg} from './timeout'; export function retryable( func: GRPCCall, retry: RetryOptions, - otherArgs: GRPCCallOtherArgs + otherArgs: GRPCCallOtherArgs, + apiName?: string ): SimpleCallbackFunction { const delayMult = retry.backoffSettings.retryDelayMultiplier; const maxDelay = retry.backoffSettings.maxRetryDelayMillis; @@ -81,7 +82,7 @@ export function retryable( timeoutId = null; if (deadline && now.getTime() >= deadline) { const error = new GoogleError( - 'Retry total timeout exceeded before any response was received' + `Total timeout of API ${apiName} exceeded ${retry.backoffSettings.totalTimeoutMillis} milliseconds before any response was received.` ); error.code = Status.DEADLINE_EXCEEDED; callback(error); diff --git a/test/unit/apiCallable.ts b/test/unit/apiCallable.ts index 6f9d0876e..21e1d4b56 100644 --- a/test/unit/apiCallable.ts +++ b/test/unit/apiCallable.ts @@ -213,7 +213,9 @@ describe('Promise', () => { describe('retryable', () => { const retryOptions = utils.createRetryOptions(0, 0, 0, 0, 0, 0, 100); - const settings = {settings: {timeout: 0, retry: retryOptions}}; + const settings = { + settings: {timeout: 0, retry: retryOptions, apiName: 'TestApi'}, + }; it('retries the API call', done => { let toAttempt = 3; @@ -364,6 +366,20 @@ describe('retryable', () => { }); }); + it('retry fails for exceeding total timeout', done => { + const spy = sinon.spy(fail); + const apiCall = createApiCall(spy, settings); + apiCall({}, undefined, err => { + assert.ok(err instanceof GoogleError); + assert.strictEqual( + err.message, + 'Total timeout of API TestApi exceeded 100 milliseconds before any response was received.' + ); + assert.strictEqual(err!.code, status.DEADLINE_EXCEEDED); + done(); + }); + }); + // maxRetries is unsupported, and intended for internal use only. it('errors when totalTimeoutMillis and maxRetries set', done => { const maxRetries = 5; diff --git a/test/unit/gax.ts b/test/unit/gax.ts index 0ce57cdf9..3744dac12 100644 --- a/test/unit/gax.ts +++ b/test/unit/gax.ts @@ -110,6 +110,7 @@ describe('gax construct settings', () => { ); let settings = defaults.bundlingMethod; assert.strictEqual(settings.timeout, 40000); + assert.strictEqual(settings.apiName, SERVICE_NAME); expectRetryOptions(settings.retry); assert.deepStrictEqual(settings.retry.retryCodes, [1, 2]); assert.strictEqual(settings.otherArgs, otherArgs);