本文档介绍了如何设置 Developer Connect 洞见,以便在 Gemini Cloud Assist 调查和 Cloud Logging 中使用 Developer Connect 洞见。
详细了解 Developer Connect 数据分析。
准备工作
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
Enable the Developer Connect API.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.- 安装 Google Cloud CLI。
如果您之前已安装该工具,请运行
gcloud components update以确保您安装的是最新版本。 -
创建 Developer Connect 服务代理:
gcloud beta services identity create \ --service=developerconnect.googleapis.com \ --project=PROJECT_NUM
系统会自动向此服务代理添加
roles/developerconnect.serviceAgent角色。
启用 Developer Connect 也会启用 Secret Manager API。
所需的角色
如果您的数据洞见配置范围限定为由管理项目(文件夹边界)管理的 App Hub 应用,则:
- 配置数据洞见的用户需要在管理项目上拥有以下角色:
- Developer Connect Insights Admin (
roles/developerconnect.insightsAdmin) - App Hub Viewer (
roles/apphub.viewer)
- Developer Connect Insights Admin (
- Developer Connect Service Agent 需要以下角色:
- 管理项目中的 Developer Connect Service Agent 角色 (
roles/developerconnect.serviceAgent) 和 Developer Connect Insights Agent 角色 (roles/developerconnect.insightsAgent)。 - 包含管理项目的文件夹中的 Developer Connect Insights Agent 角色 (
roles/developerconnect.insightsAgent)。
- 管理项目中的 Developer Connect Service Agent 角色 (
如果您的分析洞见配置范围限定为由宿主项目管理的 App Hub 应用,则:
- 配置数据洞见的用户需要在宿主项目中拥有以下角色:
- Developer Connect Insights Admin (
roles/developerconnect.insightsAdmin) - App Hub Viewer (
roles/apphub.viewer)
- Developer Connect Insights Admin (
- Developer Connect Service Agent 需要以下角色:
- 宿主项目中的 Developer Connect Service Agent 角色 (
roles/developerconnect.serviceAgent) 和 Developer Connect Insights Agent 角色 (roles/developerconnect.insightsAgent)。 - 所有服务项目中的 Developer Connect Insights Agent 角色 (
roles/developerconnect.insightsAgent)。 - 如果您使用的是不在同一文件夹中的现有资源(例如来自 Cloud Build 或 Artifact Registry 的资源),请在这些项目中向宿主项目的 Developer Connect Service Agent 授予 Developer Connect Insights Agent 角色。
- 宿主项目中的 Developer Connect Service Agent 角色 (
如果您的数据洞见配置范围限定为各个目标项目,请执行以下操作:
- 配置数据洞见的用户需要在宿主项目中拥有以下角色:
- Developer Connect Insights Admin (
roles/developerconnect.insightsAdmin)。
- Developer Connect Insights Admin (
- Developer Connect Service Agent 需要以下角色:
- 宿主项目中的 Developer Connect Service Agent 角色 (
roles/developerconnect.serviceAgent) 和 Developer Connect Insights Agent 角色 (roles/developerconnect.insightsAgent)。 - 所有目标项目的 Developer Connect Insights Agent 角色 (
roles/developerconnect.insightsAgent)。
- 宿主项目中的 Developer Connect Service Agent 角色 (
如需从命令行查看数据洞见,查看数据洞见的用户需要:
- 宿主项目中的 Developer Connect Insights Viewer (
roles/developerconnect.insightsViewer)。 - 宿主项目中的 Container Analysis Occurrences Viewer 角色 (
roles/containeranalysis.occurrences.viewer)。
个别工具可能需要额外的 Google Cloud 或非 Google 角色和 权限才能使用,或者在特定用例中需要额外的或非 Google 角色和权限。如果您遇到权限错误,请与您的管理员联系,确保您拥有正确的角色和权限。
除了这些角色和权限之外,当您使用交互式工作流配置新的数据洞见配置时,您必须有权访问您指定的所有资源。
其他前提条件
如果您希望 Developer Connect 洞见仅针对某个 App Hub 应用,则需要拥有或创建该应用。
Developer Connect Insights 支持所有 App Hub 应用设置模型。我们建议您使用已配置为支持应用管理的文件夹,以便使用 Gemini Cloud Assist 和其他以应用为中心的功能。
您还可以将 Developer Connect 分析洞见限定为项目范围,而不是 App Hub 应用范围。
您必须使用 Cloud Build 和受支持的源代码管理系统(GitHub、GitLab 或 Bitbucket)。
您的 build 必须生成来源,才能在日志中包含来源信息。
这些数据可以来自以下任何来源:
使用 Cloud Build 和 Artifact Registry。
您可以使用 Cloud Build 来构建映像。build 必须使用触发器启动,并且构建流程必须生成来源。由 build 生成的制品存储在 Artifact Registry 中。
使用 GitHub 证明。
如果您使用的是
docker/build-push-action的 4.0 版或更高版本,该操作会自动向图片添加来源证明。或者,您也可以使用
actions/attest-build-provenance和push-to-registry选项将来源证明发布到 Container Registry 中,这样无论注册表提供方是谁,Developer Connect 分析洞见都可以读取该证明。使用
docker buildx provenance标志。使用
docker buildx注册表导出器。并将
oci-artifact设置为true。 了解详情
GitHub 证明必须来自公开提供的代码库。
docker buildx制品必须在容器注册表中公开提供。即使没有来源信息,您仍可使用 Developer Connect 分析洞见,但这些洞见的实用性会降低
Gemini Cloud Assist
Developer Connect 洞见通过将应用部署事件添加到调查上下文,增强了 Gemini Cloud Assist 体验。您可以启用 Gemini Cloud Assist,以便在 Gemini Cloud Assist 调查中使用 Developer Connect 洞见。
如果您的 Developer Connect 数据洞见将限定为 App Hub 应用,那么您的数据洞见配置必须与该应用位于同一项目中。
如果配置的范围限定为项目,则该配置无需与范围内的项目位于同一项目中。
建议(但并非必须)将其他适用的资源(例如 Developer Connect 洞见、Google Kubernetes Engine 集群、Cloud Run 服务、Cloud Build、Artifact Registry 代码库)放在同一位置。
限制
以下限制适用于 Developer Connect 效果分析配置:
单个项目中最多可以有 50 个数据洞见配置。
对于项目级配置,单个配置最多可以跟踪 5 个项目。
单个洞见配置最多可跟踪 3,000 个运行时。
在 App Hub 中创建应用
只有在您将 Developer Connect 分析洞见限定为 App Hub 应用时,此参数才相关。
设置 App Hub。我们建议您使用配置为用于应用管理的文件夹,以便使用 Gemini Cloud Assist 和其他以应用为中心的功能。
创建 App Hub 应用。
- 如需从现有 Google Cloud 资源创建应用,请参阅将资源注册到应用。
- 如需设计和部署新应用,您可以使用 App Design Center。
为应用配置 Developer Connect Insights
使用以下命令创建 Developer Connect 洞见:
gcloud developer-connect insights-configs create DCI_CONFIG_NAME \
--project PROJECT_ID \
--app-hub-application APP_HUB_APPLICATION_NAME \
--target-projects TARGET_PROJECT_IDS \
--location LOCATION
其中:
DCI_CONFIG_NAME 是将生成的分析配置的名称。
PROJECT_ID 是您要在其中创建 Developer Connect 数据分析配置的项目的 ID。
APP_HUB_APPLICATION_NAME 是您之前创建的 App Hub 应用的完全限定名称。
如果您将此数据洞见配置的范围限定为 App Hub 应用,而不是项目,则此参数才适用。
TARGET_PROJECT_IDS 是以英文逗号分隔的项目 ID 列表,用于指定此 Developer Connect 洞见配置的范围。
如果您将此数据洞见配置的范围限定为项目,而不是 App Hub 应用,则此参数才适用。单个配置最多可以跟踪 5 个项目。
LOCATION 是您要创建此数据洞见配置的区域。
此命令会触发自动发现流程,该流程会查找项目中的所有 App Hub 工作负载和服务。此过程还会确认您是否拥有必要的权限。
此命令还会返回一个 OPERATION_ID,您可以使用该 ID 来检查配置的状态。
您可以查看 Developer Connect Insights 配置的状态:
gcloud developer-connect operations describe OPERATION_ID
其中 OPERATION_ID 是从 gcloud developer-connect insights-configs create 命令返回的完全指定的操作 ID。
此操作表示收到了初始请求。其中的 response 字段是接受创建任务那一刻的资源快照。如需获取发现过程的状态,请运行 insights-configs describe 命令。
自动发现过程完成后,您可以运行以下命令来检查此 Developer Connect 洞见的状况:
gcloud developer-connect insights-configs describe DCI_CONFIG_NAME \
--location=REGION
其中:
DCI_CONFIG_NAME 是您为
gcloud developer-connect insights-configs create命令使用的名称。REGION 是您创建配置的区域。
后续步骤
- 详细了解 Developer Connect 效果分析
- 了解如何使用 Developer Connect 洞见