2.10. 创建额外的云功能来收集完成的数据
在月初,Google Cloud 完成了前一个月的计费。创建额外的功能和计划作业,以触发这些报告向红帽发送,以便成本管理能够处理它们。
流程
设置用于发布报告的功能:
- 从 Cloud Functions 中,选择 Create function。
- 为您的功能命名。
- 选择 HTTP trigger。
在 Runtime, build, connections, security settings 中,单击 。
- 点 。
- 选择 exposeed 作为环境变量。
- 选择 Secret version 或 Latest。
- 点 。
- 为其他 secret 重复此过程。
- 点击 。
- 复制您的 Trigger URL。点击 。
- 选择最新的 Python 运行时。
-
将 Entry point 设置为
get_filtered_data
。 -
添加 Google Cloud 功能。更新
INTEGRATION_ID
、BUCKET
、PROJECT_ID
、DATASET
和TABLE_ID
的值。 删除以下行中的注释:
# month_end = now.replace(day=1) - timedelta(days=1) # delta = now.replace(day=1) - timedelta(days=query_range) # year = month_end.strftime("%Y") # month = month_end.strftime("%m") # day = month_end.strftime("%d")
-
选择
requirements.py
文件,并从 requirements.txt 文件中添加要求。 - 单击 。
设置云调度程序以触发您的功能:
- 前往 Cloud Scheduler。
- 单击 。
- 命名您的计划
-
设置频率。例如,以下 cron 将在每月第四天(
0 9 4 *
)运行作业 - 设置时区。
- 点 。
- 粘贴您之前复制的功能 Trigger URL。
-
在请求正文中,添加
{"name": "Scheduler"}
。 - 将 auth 标头设置为 OIDC 令牌。
- 选择或创建具有 Cloud Scheudler Job Runner 和 Cloud Functions Invoker 角色的服务帐户。
- 点 。
- 点击 。