Firebase Function Deploy 시 maxScale, maxInstances 에러

햄스터아저씨·2023년 5월 13일
1

환경

Firebase Function 를 윈도우에서 사용

초기 테스트 코드(기본 튜토리얼 따라함)

import {onRequest} from "firebase-functions/v2/https";
import * as logger from "firebase-functions/logger";

export const helloWorld = onRequest((request, response) => {
  logger.info("Hello logs!", {structuredData: true});
  response.send("Hello from Firebase!");
});

이후 firebase deploy --only functions

에러 발생

튜토리얼을 따라했음에도 에러가 발생했다.
에러 내용은 다음과 같다

!  functions: HTTP Error: 400, Could not create Cloud Run service helloworld. spec.template.spec.containers.resources.limits.cpu: Invalid value specified for cpu. For the
value, maxScale may not exceed 10.
Consider running your workload in a region with greater capacity, decreasing your requested cpu-per-instance, or requesting an increase in quota for this region if you arstained usage near this limit, see https://cloud.google.com/run/quotas. Your project may gain access to further scaling by adding billing information to your account.
!  functions: failed to create function projects/~~~/locations/us-central1/functions/helloWorld
Failed to create function projects/~~~/locations/us-central1/functions/helloWorld

요약하자면

  • us-central1 에서 인스턴스 수에 제약이 있다.

관련 정보를 탐색해 본 결과

  • Firebase의 functions는 기본적으로 us-central1 에서 동작한다.
  • 즉 instance 수를 제한한다면 해결 가능.

몇번의 시행착오 끝에, 아래와 같이 수정

2차 테스트 코드

import * as logger from "firebase-functions/logger";
import {region} from "firebase-functions";

export const helloworld = region("us-central1")
  .runWith({
    maxInstances: 1,
    timeoutSeconds: 540,
    memory: "1GB",
  }).https.onRequest(async (request, response) => {
    logger.info("Hello logs!", {structuredData: true});
    response.send("Hello from Firebase!");
  });

결과: 성공

콘솔에서 deploy 된 function이 보이며 접속시 성공한다.

v1 후기 - 성공

  1. Function은 v1, v2 로 나뉘는데 위 코드는 v1 방식이다.
    그래서 호출할 수 있는 시간이 9분 밖에 안된다.
    v2로도 해법을 찾아야 함.

  2. Function 의 Billing 은 리전마다 다르다.
    기본값인 us-central1 은 좋은 편.
    https://firebase.google.com/docs/functions/locations?hl=ko

v2 후기 - 실패

v2 문서를 보니, 아직은 beta 버전이다. (2023-05-14)
https://firebase.google.com/docs/functions/beta?hl=ko

아래는 v2 에서 환경 설정방법. maxInstance 설정방법이 v1과는 좀 다르다.
https://firebase.google.com/docs/functions/beta/config-env?hl=ko

문서를 보고 시도한 코드:

import * as functionsV2 from "firebase-functions/v2";

export const pingv2 = functionsV2.https.onRequest(
  {
    region: "us-central1",
    timeoutSeconds: 5,
    maxInstances: 1,
    memory: "1GiB",
  },
  (request, response) => {
    response.send("Hello from Firebase!");
  });

Deploy 시도결과

Could not create or update Cloud Run service pingv2, Container Healthcheck failed. The user-provided container failed to start and listen on the port defined provided by the PORT=8080 environment variable. Logs for this revision might contain more information.

이를 탐색해보니 아래 code run 에 명시된 에러 내용과 유사하다.
https://cloud.google.com/run/docs/troubleshooting?hl=ko

Container failed to start. Failed to start and then listen on the port defined by the PORT environment variable.

왜 8080포트로..?
이를 환경변수에서 설정할 수 있는가 찾아보자

...응?

PORT는 내부 예약어니까 설정하지 말라고?
아직 베타버전이라 그런가?
좀 더 시도해보고 싶지만 SLA가 제공되지 않는다고 하니,
지금이 삽질이 결국 시간낭비로 끝날 가능성이 존재하므로 이만 줄인다.

나중에 beta가 아닐 때 다시보자

profile
서버도 하고 웹도 하고 시스템이나 인프라나 네트워크나 그냥 다 함.

0개의 댓글