从同一模板启动多个数据流作业时如何避免 "IN_USED_ADDRESSES" 错误?
How can I avoid "IN_USED_ADDRESSES" error when starting multiple Dataflow jobs from the same template?
我创建了一个 Dataflow 模板,它允许我将 Cloud Storage 中的 CSV 文件中的数据导入 BigQuery。我每天在特定时间使用 Cloud Function for Firebase 从该模板创建作业。这是函数中的代码(删除了一些不相关的部分)。
const filePath = object.name?.replace(".csv", "");
// Exit function if file changes are in temporary or staging folder
if (
filePath?.includes("staging") ||
filePath?.includes("temp") ||
filePath?.includes("templates")
)
return;
const dataflow = google.dataflow("v1b3");
const auth = await google.auth.getClient({
scopes: ["https://www.googleapis.com/auth/cloud-platform"],
});
let request = {
auth,
projectId: process.env.GCLOUD_PROJECT,
location: "asia-east1",
gcsPath: "gs://my_project_bucket/templates/csv_to_bq",
requestBody: {
jobName: `csv-to-bq-${filePath?.replace(/\//g, "-")}`,
environment: {
tempLocation: "gs://my_project_bucket/temp",
},
parameters: {
input: `gs://my_project_bucket/${object.name}`,
output: biqQueryOutput,
},
},
};
return dataflow.projects.locations.templates.launch(request);
每次在云存储中写入任何文件时都会触发此函数。我正在使用传感器,所以至少我必须在 15 分钟内导入 89 个不同的数据,即不同的 CSV 文件。
如果只有 4 个工作同时工作,整个过程工作正常。但是,当该函数尝试创建第五个作业时,API 返回了许多不同类型的错误。
错误 1(不准确,因为不知何故我再也找不到错误):
Error Response: [400] The following quotas were exceeded: IN_USE_ADDRESSES
错误 2:
Dataflow quota error for jobs-per-project quota. Project *** is running 25 jobs.
Please check the quota usage via GCP Console.
If it exceeds the limit, please wait for a workflow to finish or contact Google Cloud Support to request an increase in quota.
If it does not, contact Google Cloud Support.
错误 3:
Quota exceeded for quota metric 'Job template requests' and limit 'Job template requests per minute per user' of service 'dataflow.googleapis.com' for consumer 'project_number:****'.
我知道我可以 space 开始工作以避免错误 2 和 3。但是,我不知道如何以不会填满地址的方式开始工作。那么,我该如何避免呢?如果我不能,那我应该使用什么方法?
我已经在另一个 post 中回答了这个问题 - 。
如果有帮助请告诉我。
这是一个 GCP 外部 IP 配额问题,最好的解决方案是不要将任何 public IP 用于数据流作业,只要您的管道资源位于 GCP 网络内即可。
要在数据流作业中启用 public IP:
创建或更新您的子网以允许 Private google access
。使用控制台非常简单 - VPC > networks > subnetworks > tick enable private google access
在 Cloud Dataflow 作业的参数中,指定 --usePublicIps=false
和 --network=[NETWORK]
或 --subnetwork=[SUBNETWORK]
。
注意:- 对于内部 IP IN_USED 错误,只需更改您的子网 CIDR 范围以容纳更多地址,例如 20.0.0.0/16
将为您提供接近 60k 的内部 IP 地址。
这样,您将永远不会超出您的内部 IP 范围
我创建了一个 Dataflow 模板,它允许我将 Cloud Storage 中的 CSV 文件中的数据导入 BigQuery。我每天在特定时间使用 Cloud Function for Firebase 从该模板创建作业。这是函数中的代码(删除了一些不相关的部分)。
const filePath = object.name?.replace(".csv", "");
// Exit function if file changes are in temporary or staging folder
if (
filePath?.includes("staging") ||
filePath?.includes("temp") ||
filePath?.includes("templates")
)
return;
const dataflow = google.dataflow("v1b3");
const auth = await google.auth.getClient({
scopes: ["https://www.googleapis.com/auth/cloud-platform"],
});
let request = {
auth,
projectId: process.env.GCLOUD_PROJECT,
location: "asia-east1",
gcsPath: "gs://my_project_bucket/templates/csv_to_bq",
requestBody: {
jobName: `csv-to-bq-${filePath?.replace(/\//g, "-")}`,
environment: {
tempLocation: "gs://my_project_bucket/temp",
},
parameters: {
input: `gs://my_project_bucket/${object.name}`,
output: biqQueryOutput,
},
},
};
return dataflow.projects.locations.templates.launch(request);
每次在云存储中写入任何文件时都会触发此函数。我正在使用传感器,所以至少我必须在 15 分钟内导入 89 个不同的数据,即不同的 CSV 文件。
如果只有 4 个工作同时工作,整个过程工作正常。但是,当该函数尝试创建第五个作业时,API 返回了许多不同类型的错误。
错误 1(不准确,因为不知何故我再也找不到错误):
Error Response: [400] The following quotas were exceeded: IN_USE_ADDRESSES
错误 2:
Dataflow quota error for jobs-per-project quota. Project *** is running 25 jobs.
Please check the quota usage via GCP Console.
If it exceeds the limit, please wait for a workflow to finish or contact Google Cloud Support to request an increase in quota.
If it does not, contact Google Cloud Support.
错误 3:
Quota exceeded for quota metric 'Job template requests' and limit 'Job template requests per minute per user' of service 'dataflow.googleapis.com' for consumer 'project_number:****'.
我知道我可以 space 开始工作以避免错误 2 和 3。但是,我不知道如何以不会填满地址的方式开始工作。那么,我该如何避免呢?如果我不能,那我应该使用什么方法?
我已经在另一个 post 中回答了这个问题 -
如果有帮助请告诉我。
这是一个 GCP 外部 IP 配额问题,最好的解决方案是不要将任何 public IP 用于数据流作业,只要您的管道资源位于 GCP 网络内即可。 要在数据流作业中启用 public IP:
创建或更新您的子网以允许
Private google access
。使用控制台非常简单 - VPC > networks > subnetworks > tick enable private google access在 Cloud Dataflow 作业的参数中,指定
--usePublicIps=false
和--network=[NETWORK]
或--subnetwork=[SUBNETWORK]
。
注意:- 对于内部 IP IN_USED 错误,只需更改您的子网 CIDR 范围以容纳更多地址,例如 20.0.0.0/16
将为您提供接近 60k 的内部 IP 地址。
这样,您将永远不会超出您的内部 IP 范围