Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Callback is not invoked upon serialization failure #1376

Open
losalex opened this issue Oct 24, 2022 · 0 comments
Open

Callback is not invoked upon serialization failure #1376

losalex opened this issue Oct 24, 2022 · 0 comments
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@losalex
Copy link

losalex commented Oct 24, 2022

As raised in 732, there is a problem with handling invalid payload in client-interceptors.ts:

  1. When latency contains a Duration 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:

{
    "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:

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);
@losalex losalex added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Oct 24, 2022
@alexander-fenster alexander-fenster removed their assignment May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

2 participants