googleapis / googleapis/google-cloud-node
Callback is not invoked upon serialization failure
- Dominant language
- TypeScript
- Stars
- 3.2k
- Forks
- 712
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 99
Description
As raised in [732](https://github.com/googleapis/nodejs-logging-winston/issues/732), there is a problem with handling invalid payload in [client-interceptors.ts](https://github.com/grpc/grpc-node/blob/6764dcc79602faee5457243629da520ba08b726f/packages/grpc-js/src/client-interceptors.ts#L373):
1. When `latency` contains a [Duration](https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#HttpRequest) as string (e.g. "1s"), the following failure occurs: **google.logging.type.HttpRequest.latency: object expected**
2. After the failure occurs, provided callback is called only after **all** retries are exhausted (e.g. _error: GoogleError: Exceeded maximum number of retries before any response was received_).
Given a fact that the error is permanent and that payload never sent over network due to invalid encoding, the retries should never occur and original encoding error should be sent to callback so caller would see the issue with encoding immediately.
Here is a problematic payload used to reproduce the problem:
```json
{
"logName": "projects/startup-project-328121/logs/winston_log",
"entries": [
{
"timestamp": {
"seconds": 1666296002,
"nanos": 576999902
},
"httpRequest": {
"requestMethod": "GET",
"requestUrl": "http://some-url.com",
"status": 200,
"latency": "1s"
},
"insertId": "..........9SD68uY6p5Qc1Z0ytHZMsB",
"severity": "INFO",
"jsonPayload": {
"fields": {
"message": {
"stringValue": "Fake request"
},
"metadata": {
"structValue": {
"fields": {}
}
}
}
}
},
{
"timestamp": {
"seconds": 1666296002,
"nanos": 576999902
},
"insertId": "..........5SD68uY6p5Qc1Z0ytHZMsB",
"severity": "INFO",
"jsonPayload": {
"fields": {
"logging.googleapis.com/diagnostic": {
"structValue": {
"fields": {
"instrumentation_source": {
"listValue": {
"values": [
{
"structValue": {
"fields": {
"name": {
"stringValue": "nodejs"
},
"version": {
"stringValue": "10.1.11"
}
}
}
},
{
"structValue": {
"fields": {
"name": {
"stringValue": "nodejs-winston"
},
"version": {
"stringValue": "5.1.6"
}
}
}
}
]
}
}
}
}
}
}
}
}
],
"resource": {
"type": "global"
},
"partialSuccess": true
}
```
The following code snippet is used to repro a problem:
```js
const winston = require('winston');
const { LoggingWinston } = require('@google-cloud/logging-winston');
const logger = winston.createLogger({
level: 'info',
format: winston.format.json(),
transports: [
new winston.transports.Console(),
new LoggingWinston({
projectId: "projectId",
keyFilename: 'key.json',
//inspectMetadata: true,
maxRetries: 1,
defaultCallback: (error: any, apiResponse: any) => {
console.debug('defaultCallback called', {
error,
apiResponse,
});
},
})
]
});
logger.info('Fake request 2', {
httpRequest: {
requestMethod: 'GET',
requestUrl: 'http://some-url.com',
status: 200,
latency: "1s", // Latency in wrong format on purpose so that send fails
// Uncomment following code to make latency working as expected
// latency: {
// seconds: 1,
// nanos: 0
// }
}
});
setTimeout(() => {
console.log('done');
},
6000);
```
Contributor guide
Assessment
This issue has not been assessed yet.