在 BigQuery 引擎上執行追蹤查詢

設定 Observability Analytics 在 BigQuery 引擎上執行 Cloud Trace 查詢,即可使用保留的時段,避免預設時段遭佔用時發生佇列延遲。建立以 SQL 為基礎的快訊政策,或是儲存查詢會將可觀測性資料與其他業務資料合併的資訊主頁圖表時,也必須使用 BigQuery 引擎。

除非修改設定,否則「可觀測性分析」頁面會在預設查詢引擎上執行查詢,而該引擎會使用預設時段。這兩個引擎都可讓您查詢可觀測性檢視區塊、記錄檔 bucket 檢視區塊和分析檢視區塊。

事前準備

  1. 登入 Google Cloud 帳戶。如果您是 Google Cloud新手,歡迎 建立帳戶,親自評估產品在實際工作環境中的成效。新客戶還能獲得價值 $300 美元的免費抵免額,可用於執行、測試及部署工作負載。
  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. 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

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

  6. 如要取得使用 BigQuery 引擎從可觀測性分析執行查詢所需的權限,請要求管理員授予您下列 IAM 角色:

    • 觀測能力檢視畫面存取子 (roles/observability.viewAccessor) 在要查詢的觀測能力檢視畫面中。這個角色支援 IAM 條件,可讓您將授權限制在特定檢視區塊。如果未將條件附加至角色授予作業,主體就能存取所有可觀測性檢視畫面。
    • 專案的 BigQuery 使用者 (roles/bigquery.user)
    • 專案的 BigQuery 工作使用者 (roles/bigquery.jobUser)

    如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和組織的存取權」。

    您或許也能透過自訂角色或其他預先定義的角色,取得必要權限。

  7. 確認您在儲存追蹤資料的可觀測性資料集上,有連結的 BigQuery 資料集。如果連結的 BigQuery 資料集不存在,請建立該資料集。

如果您將「可觀測性分析」頁面設定為使用受 Virtual Private Cloud (VPC) Service Controls 保護的專案中的 BigQuery 引擎,請使用 BigQuery Enterprise 版。 Google Cloud 詳情請參閱瞭解 BigQuery 版本的相關說明。

在 BigQuery 引擎上執行查詢

如要在使用「可觀測性分析」頁面時,透過 BigQuery 引擎執行查詢,請按照下列步驟操作:

  1. 在 Google Cloud 控制台中,前往 「Observability Analytics」(觀測能力分析) 頁面:

    前往「Observability Analytics」(觀測能力分析) 頁面

    如果您是使用搜尋列尋找這個頁面,請選取子標題為「Logging」的結果。

  2. 輸入或載入查詢。詳情請參閱「查詢及分析追蹤記錄」。

    您可以將圖表儲存至資訊主頁,圖表會顯示可觀測性資料和其他業務資料的聯結結果。在這種情況下,FROM 子句必須指定可觀測性資料集或記錄 bucket 的檢視區塊,且必須有連結的資料集,才能查詢資料。JOIN 陳述式可以指定 BigQuery 資料表。 不過,您必須具備必要的 IAM 權限,才能查詢 BigQuery 資料表。

  3. 前往工具列,確認是否顯示標示為「在 BigQuery 上執行」的按鈕。

    如果工具列顯示「執行查詢」,請按一下「設定」圖示 ,然後選取「BigQuery」。

    如果「在 BigQuery 中執行」按鈕已停用,表示沒有連結的資料集。如要解決這項失敗問題,請建立連結的 BigQuery 資料集。

  4. 按一下「在 BigQuery 執行」。

定價

如要瞭解使用 BigQuery 的相關費用,請參閱 BigQuery 定價。

後續步驟