本文档介绍了如何设置 Developer Connect Insights,以便 Gemini Cloud Assist 调查和 Cloud Logging 可以使用 Insights。
详细了解 Developer Connect Insights。
准备工作
-
登录您的 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
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.-
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。
所需的角色
如果您的 Insights 配置的范围限定为由 管理项目(文件夹边界)管理的 App Hub 应用:
- 配置 Insights 的用户 需要在管理项目上拥有以下角色:
- 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 角色 (
如果您的 Insights 配置的范围限定为由宿主项目管理的 App Hub 应用:
- 配置 Insights 的用户 需要在宿主项目上拥有以下角色:
- 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 角色 (
如果您的 Insights 配置的范围限定为各个目标项目:
- 配置 Insights 的用户 需要在宿主项目上拥有以下角色:
- 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 角色 (
如需从命令行查看 Insights,查看 Insights 的用户 需要:
- 宿主项目上的 Developer Connect Insights Viewer (
roles/developerconnect.insightsViewer)。 - 宿主项目上的 Container Analysis Occurrences Viewer 角色 (
roles/containeranalysis.occurrences.viewer)。
个别工具可能需要额外的 Google Cloud 或非 Google 角色和 权限才能使用,或者在特定用例中需要额外的或非 Google 角色和权限。如果您遇到权限错误,请与管理员联系,确保您拥有正确的角色和权限。
除了这些角色和权限之外,当您使用交互式工作流配置新的 Insights 配置时,您必须拥有访问您指定的所有资源的权限。
其他前提条件
如果您希望将 Developer Connect Insights 的范围限定为 App Hub 应用,则需要拥有或创建该应用。
Developer Connect Insights 支持所有 App Hub 应用设置模型。 我们建议使用为应用管理配置的 文件夹 ,以便您可以使用 Gemini Cloud Assist 和其他 以应用为中心的功能。
您还可以将 Developer Connect Insights 的范围限定为项目,而不是 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 Insights,但 Insights 的实用性会降低
Gemini Cloud Assist
Developer Connect Insights 通过将应用部署事件添加到调查上下文来增强 Gemini Cloud Assist 体验。您可以 启用 Gemini Cloud Assist,以便将 Developer Connect Insights 与 Gemini Cloud Assist 调查搭配使用。
如果您的 Developer Connect Insights 的范围限定为 App Hub 应用,则您的 Insights 配置必须与该应用位于同一项目中。
如果 Insights 的范围限定为项目,则配置不需要与范围内的项目位于同一项目中。
建议(但不是必需)将其他适用的资源(例如 Developer Connect Insights、Google Kubernetes Engine 集群、Cloud Run 服务、Cloud Build、Artifact Registry 代码库)放在同一位置。
在 App Hub 中创建应用
这仅在您将 Developer Connect Insights 的范围限定为 App Hub 应用时适用。
设置 App Hub。我们建议 使用 为应用管理配置的文件夹 ,以便您可以使用 Gemini Cloud Assist 和其他 以应用为中心的功能。
创建 App Hub 应用。
- 如需从现有 Google Cloud 资源创建应用,请参阅 向应用注册资源。
- 如需设计和部署新应用,您可以使用 App Design Center。
为应用配置 Developer Connect Insights
使用以下命令创建 Developer Connect Insights:
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 是将生成的 Insights 配置的名称。
PROJECT_ID 是您要在其中 创建 Developer Connect Insights 配置的项目的 ID。
APP_HUB_APPLICATION_NAME 是您之前创建的 App Hub 应用的完全限定名称。
这仅在您将此 Insights 配置的范围限定为 App Hub 应用(而不是项目)时适用。
TARGET_PROJECT_IDS 是您要将此 Developer Connect Insights 配置的范围限定为的项目的 ID 的逗号分隔列表。
这仅在您将此 Insights 配置的范围限定为项目 (而不是 App Hub 应用)时适用。
LOCATION 是您要在其中 创建此 Insights 配置的区域。
此命令会触发自动发现过程,该过程会查找项目中的所有 App Hub 工作负载和服务。此过程还会确认您是否拥有必要的权限。
此命令还会返回 OPERATION_ID,您可以使用 该 ID 检查配置的状态。
您可以检查 Developer Connect Insights 配置的状态:
gcloud developer-connect operations describe OPERATION_ID
其中 OPERATION_ID 是完全指定的操作 ID
,它是从 gcloud developer-connect insights-configs create
命令返回的。
此操作是初始请求的收据。其中的 response 字段是创建任务被接受时资源的快照。
如需获取发现过程的状态,请运行 insights-configs describe 命令。
自动发现过程完成后,您可以运行以下命令检查此 Developer Connect Insights 的状态:
gcloud developer-connect insights-configs describe DCI_CONFIG_NAME \
--location=REGION
其中:
DCI_CONFIG_NAME 是您用于
gcloud developer-connect insights-configs create命令的名称。REGION 是您在其中创建配置的区域。
后续步骤
- 详细了解 Developer Connect Insights
- 了解如何使用 Developer Connect Insights