googleapis / google-cloud-node

Google Cloud Client Library for Node.js

Home Page:https://cloud.google.com/nodejs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Creating a task with bufferTask method result on INVALID_ARGUMENT

ddavid67 opened this issue · comments

Environment details

  • which product (packages/*): @google-cloud/tasks
  • OS: Linux/Ubuntu
  • Node.js version: v20.8.1
  • npm version: 10.1.0
  • google-cloud-node version: @google-cloud/tasks@4.0.1

Steps to reproduce

import "dotenv/config";

import { v2beta3 } from "@google-cloud/tasks";

const PROJECT_ID = process.env["PROJECT_ID"] ?? "";
const LOCATION = process.env["LOCATION"] ?? "";
const QUEUE_ID = process.env["QUEUE_ID"] ?? "";
const KEY_FILE = process.env["GOOGLE_APPLICATION_CREDENTIALS"] ?? "";

const client = new v2beta3.CloudTasksClient({ keyFile: KEY_FILE });
const queuePath = client.queuePath(PROJECT_ID, LOCATION, QUEUE_ID);
await client.bufferTask({ queue: queuePath });

Result

(personnal values replaced by XXXXXX on purpose)

node:internal/process/esm_loader:40
      internalBinding('errors').triggerUncaughtException(
                                ^

Error: 3 INVALID_ARGUMENT: "x-goog-request-params" header is either missing or misformatted. "x-goog-request-params" must contain "name=projects/XXXXXXXXX/locations/XXXXXXXX/queues/XXXXXXXXXXX"
    at callErrorFromStatus (/home/david/project1/node_modules/@grpc/grpc-js/build/src/call.js:31:19)
    at Object.onReceiveStatus (/home/david/project1/node_modules/@grpc/grpc-js/build/src/client.js:192:76)
    at Object.onReceiveStatus (/home/david/project1/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:360:141)
    at Object.onReceiveStatus (/home/david/project1/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:323:181)
    at /home/david/project1/node_modules/@grpc/grpc-js/build/src/resolving-call.js:99:78
    at process.processTicksAndRejections (node:internal/process/task_queues:77:11)
for call at
    at ServiceClientImpl.makeUnaryRequest (/home/david/project1/node_modules/@grpc/grpc-js/build/src/client.js:160:32)
    at ServiceClientImpl.<anonymous> (/home/david/project1/node_modules/@grpc/grpc-js/build/src/make-client.js:105:19)
    at /home/david/project1/node_modules/@google-cloud/tasks/build/src/v2beta3/cloud_tasks_client.js:212:29
    at /home/david/project1/node_modules/google-gax/build/src/normalCalls/timeout.js:44:16
    at OngoingCallPromise.call (/home/david/project1/node_modules/google-gax/build/src/call.js:67:27)
    at NormalApiCaller.call (/home/david/project1/node_modules/google-gax/build/src/normalCalls/normalApiCaller.js:34:19)
    at /home/david/project1/node_modules/google-gax/build/src/createApiCall.js:84:30
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  code: 3,
  details: '"x-goog-request-params" header is either missing or misformatted. "x-goog-request-params" must contain "name=projects/XXXXXXXXX/locations/XXXXXXXX/queues/XXXXXXXXXXX"',
  metadata: Metadata {
    internalRepr: Map(2) {
      'endpoint-load-metrics-bin' => [
        Buffer(27) [Uint8Array] [
           49,  48, 167,  39, 214, 245, 148,
          109,  64,  57,   0, 144, 240,  41,
          106, 246,  71,  64,  73, 170,  78,
           92, 129,   9, 130, 197,  63
        ]
      ],
      'grpc-server-stats-bin' => [
        Buffer(10) [Uint8Array] [
          0, 0, 14, 32, 42,
          2, 0,  0,  0,  0
        ]
      ]
    },
    options: {}
  }
}

Node.js v20.8.1

Thank you for the report, I'm going to follow up internally and will get back to you.

It seems like the currently released client library will not properly handle BufferTask without a few tweaks. As a workaround, please use the HTTP fallback instead of gRPC, and supply some task ID since the current client library won't be able to request an auto-generated task ID.

This code worked for me:

const {v2beta3} = require("@google-cloud/tasks");

async function main() {
  const client = new v2beta3.CloudTasksClient({fallback: true}); // enable HTTP fallback instead of gRPC
  // this example uses gcloud application default credentials;
  // if you have `GOOGLE_APPLICATION_CREDENTIALS` set you don't need to pass any extra auth parameters

  const PROJECT_ID = await client.getProjectId(); // this gets project ID from authentication credentials
  const LOCATION = 'us-west1'; // use whatever location you need
  const QUEUE_ID = 'testqueue'; // make sure you enabled HTTP overrides for this queue:
  // gcloud beta tasks queues create testqueue --http-uri-override=host:google.com,path:/ --http-method-override=get --location=us-west1
 
  const queuePath = client.queuePath(PROJECT_ID, LOCATION, QUEUE_ID);
  const response = await client.bufferTask({ queue: queuePath, taskId: 'test' }); // note: we pass some task ID

  console.log(response);
}

main();

We'll release a new version of the library with the fix.

So just to update this issue, after talking to the Cloud Tasks team, based on their explanation, the BufferTask RPC will remember how it was called (with GET, or POST, etc.) and its parameters. This is impossible to achieve in the client library. Also, it won't work via gRPC at all. The decision was made to remove BufferTask from the client libraries since the only valid use case of it is via the HTTP endpoint.