nodejs-monitoring icon indicating copy to clipboard operation
nodejs-monitoring copied to clipboard

Error handling breaks when using rest fallback

Open jekozyra opened this issue 1 year ago • 0 comments

We're currently creating our MetricServiceClient using the rest fallback method, since we're building our code with esbuild and using protos does not seem to be supported. However, if the createTimeSeries call fails, the the error is not handled and emitted by the library. Instead, it causes a crash and an unhelpful error message is emitted.

Stacktrace:

⚠  functions: Error: googleProtobufAnyFromProto3JSON: cannot find type google.monitoring.v3.CreateTimeSeriesSummary: Error: no such type: google.monitoring.v3.CreateTimeSeriesSummary
    at googleProtobufAnyFromProto3JSON (/poggio/node_modules/proto3-json-serializer/build/src/any.js:70:15)
    at fromProto3JSONToInternalRepresentation (/poggio/node_modules/proto3-json-serializer/build/src/fromproto3json.js:58:58)
    at /poggio/node_modules/proto3-json-serializer/build/src/fromproto3json.js:105:48
    at Array.map (<anonymous>)
    at fromProto3JSONToInternalRepresentation (/poggio/node_modules/proto3-json-serializer/build/src/fromproto3json.js:105:33)
    at Object.fromProto3JSON (/poggio/node_modules/proto3-json-serializer/build/src/fromproto3json.js:149:26)
    at GoogleErrorDecoder.decodeHTTPError (/poggio/node_modules/@google-cloud/monitoring/node_modules/google-gax/build/src/googleError.js:198:41)
    at Function.parseHttpError (/poggio/node_modules/@google-cloud/monitoring/node_modules/google-gax/build/src/googleError.js:71:37)
    at decodeResponse (/poggio/node_modules/@google-cloud/monitoring/node_modules/google-gax/build/src/fallbackRest.js:69:49)
    at /poggio/node_modules/@google-cloud/monitoring/node_modules/google-gax/build/src/fallbackServiceStub.js:101:42
⚠  Your function was killed because it raised an unhandled error.

This is roughly how we're using the library:

const client = new MetricServiceClient({ fallback: "rest" });
const dataPoint = {
  interval: {
    endTime: {
      seconds: Date.now() / 1000,
    },
  },
  value: {
    int64Value: 1,
  },
};

const requestArgs = {
  name: metricServiceClient().projectPath('project-name'),
  timeSeries: [
    {
      metric: {
        type: 'custom.googleapis.com/connectors/fivetran_sync_start',
        metricKind: 'GAUGE',
        valueType: 'INT64',
        labels: [
            runId: 'abc1234'
        ],
      },
      resource: {
        type: "global",
        labels: {
          project_id: 'project-name',
        },
      },
      points: [dataPoint],
    },
  ],
};
await metricServiceClient().createTimeSeries(requestArgs);

Environment details

  • OS: Ubuntu 18.04
  • Node.js version: 16
  • npm version:
  • @google-cloud/monitoring version: 3.0.2

Steps to reproduce

  1. Create a MetricServiceClient with the rest fallback option, e.g. new MetricServiceClient({ fallback: "rest" })
  2. Do something that causes createTimeSeries to error (in our case, I believe we were exceeding the rate limit).
  3. Instead of an error message (which is what you get if you use the proto fallback), you get the following error: Error: googleProtobufAnyFromProto3JSON: cannot find type google.monitoring.v3.CreateTimeSeriesSummary: Error: no such type: google.monitoring.v3.CreateTimeSeriesSummary.

jekozyra avatar Oct 07 '22 21:10 jekozyra