firebase / firebase-tools

The Firebase Command Line Tools
MIT License
4.02k stars 933 forks source link

v2 Pub/Sub function handler doesn't support `cpu` with a value of 6 or 8 #5563

Closed valeriangalliat closed 1 year ago

valeriangalliat commented 1 year ago

[REQUIRED] Environment info

firebase-tools: 11.24.0

Platform: macOS

[REQUIRED] Test case

import * as functions from 'firebase-functions/v2'

export const myhandler = functions.pubsub.onMessagePublished(
  {
    topic: 'my-topic',
    memory: '4GiB',
    cpu: 8,
  },
 () => {}
)

[REQUIRED] Steps to reproduce

firebase deploy --only functions:myhandler

[REQUIRED] Expected behavior

The function deploys with 8 vCPU.

[REQUIRED] Actual behavior

The deploy fails with the following logs:

[2023-02-28T01:08:29.188Z] Functions deploy failed.
[2023-02-28T01:08:29.188Z] {
  "endpoint": {
    "id": "myhandler",
    "project": "myproject",
    "region": "us-central1",
    "entryPoint": "myhandler",
    "platform": "gcfv2",
    "runtime": "nodejs16",
    "eventTrigger": {
      "eventType": "google.cloud.pubsub.topic.v1.messagePublished",
      "retry": false,
      "eventFilters": {
        "topic": "projects/myproject/topics/my-topic"
      }
    },
    "labels": {
      "deployment-tool": "cli-firebase"
    },
    "availableMemoryMb": 4096,
    "cpu": 8,
    "environmentVariables": {},
    "codebase": "default",
    "concurrency": 80,
    "targetedByOnly": true,
    "hash": "...",
    "uri": "https://myhandler-....run.app"
  },
  "op": "set concurrency",
  "original": {
    "name": "FirebaseError",
    "children": [],
    "exit": 1,
    "message": "Failed to replace Run service projects/myproject/locations/us-central1/services/myhandler",
    "original": {
      "name": "FirebaseError",
      "children": [],
      "context": {
        "body": {
          "error": {
            "code": 400,
            "message": "The feature 'increased CPU' is not supported in the declared launch stage on resource myhandler. The launch stage annotation should be specified at least as BETA. Please visit https://cloud.google.com/run/docs/troubleshooting#launch-stage-validation for in-depth troubleshooting documentation.",
            "status": "FAILED_PRECONDITION"
          }
        },
        "response": {
          "statusCode": 400
        }
      },
      "exit": 1,
      "message": "HTTP Error: 400, The feature 'increased CPU' is not supported in the declared launch stage on resource myhandler. The launch stage annotation should be specified at least as BETA. Please visit https://cloud.google.com/run/docs/troubleshooting#launch-stage-validation for in-depth troubleshooting documentation.",
      "status": 400
    },
    "status": 500
  }
}
[2023-02-28T01:08:29.191Z] Error: Failed to set concurrency function myhandler in region us-central1
    at /opt/homebrew/Cellar/firebase-cli/11.24.0/libexec/lib/node_modules/firebase-tools/lib/deploy/functions/release/fabricator.js:48:11
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Fabricator.setRunTraits (/opt/homebrew/Cellar/firebase-cli/11.24.0/libexec/lib/node_modules/firebase-tools/lib/deploy/functions/release/fabricator.js:430:9)
    at async Fabricator.createV2Function (/opt/homebrew/Cellar/firebase-cli/11.24.0/libexec/lib/node_modules/firebase-tools/lib/deploy/functions/release/fabricator.js:322:13)
    at async Fabricator.createEndpoint (/opt/homebrew/Cellar/firebase-cli/11.24.0/libexec/lib/node_modules/firebase-tools/lib/deploy/functions/release/fabricator.js:132:13)
    at async handle (/opt/homebrew/Cellar/firebase-cli/11.24.0/libexec/lib/node_modules/firebase-tools/lib/deploy/functions/release/fabricator.js:85:17)

Error: There was an error deploying functions

Notes

Setting cpu: 8 works well in functions.https.onRequest. It properly sets the annotation run.googleapis.com/launch-stage: BETA on Cloud Run.

Only in functions.pubsub.onMessagePublished (and possibly in other non-HTTPS handler) this behavior is broken.

Edit: I got this issue with functions.https.onRequest as well so after all it might be common to all v2 functions.

Once I go in the Google Cloud console and update the CPU to 6 or 8 from there though the Firebase CLI has no problem switching around the CPU value.

TheIronDev commented 1 year ago

Hi @valeriangalliat

It looks like setting CPU to 6 or 8 is part of a BETA.

https://cloud.google.com/run/docs/configuring/cpu#setting

Because its a preview setting, having to do something on the GCP platform directly might be your only options.

You're mentioning that updating on Google Cloud console works.

There are docs on updating the launch-stage annotation here.

I don't see any place on firebase's side to update launch-stage annotations to BETA.

valeriangalliat commented 1 year ago

Sounds good, thanks for looking into it! I wasn't sure where the Firebase CLI stood about Google Cloud beta options. We can close this then. 👌

Edit: if that can help anyone, here's the behavior I've noticed so far: