Skip to content

Commit bb3e2d0

Browse files
committed
gaarf-js@2.11.3 Fix: GoogleAdsRpcApiClient: removed gRPC error codes parsing, all errors not from the API are treated as transient with enabled retry
Change-Id: I853748bc53f1b28e3d317a2ce7d9671c1c554911
1 parent 08aed30 commit bb3e2d0

File tree

9 files changed

+54
-26
lines changed

9 files changed

+54
-26
lines changed

js/dist/lib/ads-api-client.js

Lines changed: 14 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/dist/lib/ads-api-client.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/dist/lib/logger-factory.js

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/dist/lib/logger-factory.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/dist/lib/logger.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "google-ads-api-report-fetcher",
3-
"version": "2.11.2",
3+
"version": "2.11.3",
44
"description": "Google Ads API Report Fetcher (gaarf)",
55
"main": "./dist/index.js",
66
"types": "./src/index.ts",

js/src/lib/ads-api-client.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -240,16 +240,15 @@ export class GoogleAdsRpcApiClient
240240
} else {
241241
// it could be an error from gRPC
242242
// we expect an Error instance with interface of ServiceError from @grpc/grpc-js library
243-
// see status codes: https://grpc.github.io/grpc/core/md_doc_statuscodes.html
244-
if (
245-
(<any>error).code === 14 /* UNAVAILABLE */ ||
246-
(<any>error).details === "The service is currently unavailable" ||
247-
(<any>error).code === 8 /* RESOURCE_EXHAUSTED */ ||
248-
(<any>error).code === 4 /* DEADLINE_EXCEEDED */ ||
249-
(<any>error).code === 13 /* INTERNAL */
250-
) {
251-
(<any>error).retryable = true;
252-
}
243+
// We used to handle only a subset of error by error code
244+
// (see status codes: https://grpc.github.io/grpc/core/md_doc_statuscodes.html)
245+
// particularly 14 (unavailble), 13 (internal server error),
246+
// 8(RESOURCE_EXHAUSTED), 4 (DEADLINE_EXCEEDED)
247+
// But there was always something new that we didn't expect, so
248+
// in the end it seems much safer to treat any error not from the API
249+
// server as transient and allow retrying.
250+
(<any>error).retryable = true;
251+
return error;
253252
}
254253
}
255254

@@ -292,13 +291,17 @@ export class GoogleAdsRpcApiClient
292291
}
293292

294293
async *executeQueryStream(query: string, customerId: string) {
295-
const customer = this.getCustomer(customerId);
296294
try {
295+
const customer = this.getCustomer(customerId);
297296
// As we return an AsyncGenerator here we can't use executeWithRetry,
298297
// instead usages of the method should be wrapped with executeWithRetry
299298
// NOTE: we're iterating over the stream instead of returning it
300299
// for the sake of error handling
301300
const stream = customer.queryStream(query);
301+
this.logger.debug(`Created AsyncGenerator from queryStream`, {
302+
customerId,
303+
query,
304+
});
302305
for await (const row of stream) {
303306
yield row;
304307
}

js/src/lib/logger-factory.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,16 @@ export function createCloudLogger(): winston.Logger {
106106
type: "cloud_function",
107107
},
108108
useMessageField: false,
109+
// setting redirectToStdout:true actually disables using Logging API,
110+
// and simply dumps entries to stdout where the logger agent
111+
// parses them and redirect to Logging.
112+
// It's the only way to overcome sparodic errors
113+
// during calling Logging API:
114+
// "GoogleError: Total timeout of API google.logging.v2.LoggingServiceV2
115+
// exceeded 60000 milliseconds before any response was received"
116+
// See https://github.com/googleapis/nodejs-logging/issues/1185
117+
// And even recommended in
118+
// https://cloud.google.com/nodejs/docs/reference/logging-winston/latest#alternative-way-to-ingest-logs-in-google-cloud-managed-environments
109119
redirectToStdout: true,
110120
handleRejections: LOG_LEVEL === "debug",
111121
}),

0 commit comments

Comments
 (0)