本文档介绍了如何设置 Developer Connect 分析洞见,以便 Gemini Cloud Assist 调查和 Cloud Logging 可以使用 Developer Connect 分析洞见。
详细了解 Developer Connect 分析洞见。
准备工作
-
登录您的 Google 账号。
如果您还没有 Google 账号,请 注册新账号。
-
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 Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.-
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 Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. 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 服务代理的 Developer Connect Service Agent 角色 (
roles/developerconnect.serviceAgent) 和 Developer Connect Insights Agent 角色 (roles/developerconnect.insightsAgent)。
如果您使用的是由宿主项目管理的 App Hub 应用:
- 宿主项目的 Developer Connect Insights Admin (
roles/developerconnect.insightsAdmin) 和 App Hub Viewer (roles/apphub.viewer) - 宿主项目的 Developer Connect 服务代理的 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 服务代理授予 Developer Connect Insights 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 分析洞见支持应用的所有 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 版或更高版本, 该操作会自动将出处证明添加到您的映像中。或者,您也可以将
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,以便将 Developer Connect 分析洞见与 Gemini Cloud Assist 调查搭配使用。
如果您的 Developer Connect 分析洞见将限定为 App Hub 应用,则您的分析洞见配置必须与该应用位于同一项目中。
如果分析洞见限定为项目,则配置不需要与范围内的项目位于同一项目中。
建议(但不是必需)将其他适用的资源(例如 Developer Connect 分析洞见、Google Kubernetes Engine 集群、Cloud Run 服务、Cloud Build、Artifact Registry 代码库)放在同一位置。
在 App Hub 中创建应用
这仅在您将 Developer Connect 分析洞见限定为 App Hub 应用时适用。
设置 App Hub。我们建议您使用为应用管理配置的文件夹,以便您可以使用 Gemini Cloud Assist 和其他以应用为中心的功能。
创建 App Hub 应用。
- 如需从现有 Google Cloud 资源创建应用,请参阅 向应用注册资源。
- 如需设计和部署新应用,您可以使用 App Design Center。
为应用配置 Developer Connect 分析洞见
使用以下命令创建 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 是您要将此 Developer Connect 分析洞见配置限定为的项目的 ID 的英文逗号分隔列表。
这仅在您将此分析洞见配置限定为项目 而不是 App Hub 应用时适用。
LOCATION 是您要在其中 创建此分析洞见配置的区域。
此命令会触发自动发现过程,该过程会查找项目中的所有 App Hub 工作负载和服务。此过程还会确认您是否拥有必要的权限。
此命令还会返回 OPERATION_ID,您可以使用 该 ID 检查配置的状态。
您可以检查 Developer Connect 分析洞见配置的状态:
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 分析洞见