設定 Developer Connect 洞察

本文說明如何設定 Developer Connect 洞察,讓 Gemini Cloud Assist 調查作業和 Cloud Logging 都能使用 Developer Connect 洞察。

進一步瞭解 Developer Connect 洞察資料

事前準備

  1. 登入 Google 帳戶。

    如果沒有帳戶,請 申請新帳戶

  2. 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 the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  3. Verify that billing is enabled for your Google Cloud project.

  4. 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 the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the API

  5. 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 the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  6. Verify that billing is enabled for your Google Cloud project.

  7. 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 the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the API

  8. 啟用 Developer Connect 時,系統也會啟用 Secret Manager API

  9. 安裝 Google Cloud CLI

    如果先前已安裝,請執行 gcloud components update,確認安裝的是最新版本。

  10. 建立 Developer Connect 服務代理:
    gcloud beta services identity create \
    --service=developerconnect.googleapis.com \
    --project=PROJECT_NUM

    系統會自動將 roles/developerconnect.serviceAgent 角色新增至這項服務代理。

必要的角色

如果您使用的是由管理專案管理的 App Hub 應用程式:

  • 管理專案的 Developer Connect 洞察管理員 (roles/developerconnect.insightsAdmin) 和 App Hub 檢視者 (roles/apphub.viewer)。
  • 將 Developer Connect 服務代理角色 (roles/developerconnect.serviceAgent) 和 Developer Connect 洞察代理角色 (roles/developerconnect.insightsAgent) 授予管理專案中的 Developer Connect 服務代理。

如果您使用的是由主專案管理的 App Hub 應用程式:

  • 主專案的 Developer Connect 洞察管理員 (roles/developerconnect.insightsAdmin) 和 App Hub 檢視者 (roles/apphub.viewer)
  • 將 Developer Connect 服務代理角色 (roles/developerconnect.serviceAgent) 和 Developer Connect 洞察代理角色 (roles/developerconnect.insightsAgent) 授予主專案的 Developer Connect 服務代理
  • 所有服務專案的 Developer Connect Insights 代理 (roles/developerconnect.insightsAgent)
    • 如果您使用不在同一資料夾中的現有資源 (例如 Cloud Build 或 Artifact Registry),請在這些專案中將 Developer Connect Insights Agent 角色授予 Developer Connect 服務代理程式

如要透過指令列查看洞察資料,請按照下列步驟操作:

  • 主專案的 Developer Connect Insights 檢視者 (roles/developerconnect.insightsViewer)
  • 主機專案的「容器分析例項檢視者」角色 (roles/containeranalysis.occurrences.viewer)

使用個別工具或特定用途時,可能需要額外 Google Cloud 或非 Google 角色和權限。如果遇到權限錯誤,請洽詢管理員,確認您具備正確的角色和權限。

除了這些角色和權限,使用互動式工作流程設定新的洞察設定時,您必須有權存取指定的所有資源。

其他必要條件

  • 如要將 Developer Connect 洞察資料的範圍限定在 App Hub 應用程式,您必須擁有或建立該應用程式。

    開發人員連結洞察資料支援應用程式的所有 App Hub 設定模型。建議您使用已設定應用程式管理的資料夾,以便使用 Gemini Cloud Assist 和其他以應用程式為中心的功能

    您也可以將 Developer Connect 洞察資料的範圍設為專案,而非 App Hub 應用程式。

  • 您必須使用 Cloud Build 和支援的原始碼管理系統 (GitHub、GitLab 或 Bitbucket)。

  • 建構作業必須產生出處資訊,才能在記錄中加入出處資訊。

    這可能來自下列任一來源:

    • 使用 Cloud Build 和 Artifact Registry。

      您可以使用 Cloud Build 建構映像檔。建構作業必須使用觸發條件啟動,且建構程序必須產生出處資訊。建構作業產生的構件會儲存在 Artifact Registry 中。

    • 使用 GitHub 認證。

      如果您使用 4 以上版本的 docker/build-push-action,這項動作會自動在圖片中加入出處認證。

      或者,您也可以使用 actions/attest-build-provenancepush-to-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 存放區) 放在相同位置,但這並非必要條件。

在 App Hub 建立應用程式

只有在將 Developer Connect 洞察資料範圍限定為 App Hub 應用程式時,這項資訊才適用。

  1. 設定 App Hub。建議您使用已設定應用程式管理功能的資料夾,這樣就能使用 Gemini Cloud Assist 和其他以應用程式為中心的功能

  2. 建立 App Hub 應用程式。

為應用程式設定 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 是以逗號分隔的專案 ID 清單,您要將 Developer Connect 洞察資料設定的範圍限定於這些專案。

    如果將這項洞察資料設定的範圍限定為專案,而非 App Hub 應用程式,則僅適用於這種情況。

  • LOCATION 是您要建立這項洞察設定的地區。

這個指令會觸發自動探索程序,找出專案中的所有 App Hub 工作負載和服務。這個程序也會確認您是否具備必要權限。

這個指令也會傳回 OPERATION_ID,您可以用來檢查設定狀態。

您可以查看 Developer Connect 洞察資料設定的狀態:

gcloud developer-connect operations describe OPERATION_ID

其中 OPERATION_IDgcloud 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 是您建立設定的區域。

後續步驟