创建可观测性存储分区

您可以在项目接收跟踪记录数据之前手动创建 _Trace 可观测性存储桶,以自定义其存储位置和客户管理的加密密钥 (CMEK) 设置。如果您的 Google Cloud 项目 在此存储桶存在之前提取跟踪记录数据,则 Google Cloud Observability 会使用项目的 可观测性存储桶的默认设置自动 预配该存储桶。

如需了解 Google Cloud Observability 如何存储数据,请参阅 存储概览

与组织政策互动

创建可观测性存储桶的请求会验证命令参数是否符合组织政策。例如,如果组织政策限制了资源位置,那么如果您指定了受限位置,则创建存储桶会失败。

与可观测性存储桶的默认设置互动

当 Google Cloud Observability 因提取数据而自动创建可观测性存储桶时,它会使用适用于存储桶父资源的可观测性存储桶的默认设置。这些默认设置可能在父资源中或父资源的分层祖先中定义,它们指定了以下内容:

  • 存储位置。
  • 用于存储数据的 Cloud KMS 密钥。

创建可观测性存储桶时,您必须指定位置 。 除非您在创建请求中明确指定其他密钥,否则 Google Cloud Observability 会应用在默认设置中定义的 Cloud KMS 密钥。

如果适用的默认设置指定了 Cloud KMS 密钥,则您无法使用 Google 默认加密创建存储桶。如需使用 Google 默认加密,请确保您的默认设置中未配置 Cloud KMS 密钥。

如需了解可观测性存储桶的默认设置,请参阅 设置可观测性存储桶的默认值

限制

需要遵循以下限制:

  • 您必须指定受 支持的位置
  • BUCKET_ID 必须是 _Trace
  • 显示名称不得超过 100 个编码字节。
  • 说明不得超过 1000 个编码字节。
  • 数据存储 30 天。您必须省略保留期限,或将其设置为 30
  • 如果您提供 Cloud KMS 密钥,则密钥的位置必须与可观测性存储桶的父位置完全一致。
  • 您只能在 Google Cloud 项目中创建可观测性存储桶。
  • 一个 Google Cloud 项目最多只能有一个名为_Trace的可观测性存储桶。

准备工作

配置项目和 IAM 角色,然后选择您计划使用的界面。

配置项目和角色

  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. Enable the Observability API.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. 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.

    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 Observability API.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. 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.

    Enable the API

  8. 如要获得创建可观测性存储桶所需的权限,请让您的管理员为您授予项目的 Observability Editor (roles/observability.editor) IAM 角色。如需详细了解如何授予角色,请参阅管理对项目、文件夹和组织的访问权限

    您也可以通过自定义 角色或其他预定义 角色来获取所需的权限。

配置界面

gcloud

在 Google Cloud 控制台中,激活 Cloud Shell。

激活 Cloud Shell

Cloud Shell 会话随即会在控制台 Google Cloud 的底部启动,并显示命令行提示符。Cloud Shell 是一个已安装 Google Cloud CLI 且已为当前项目设置值的 Shell 环境 。该会话可能需要几秒钟来完成初始化。

REST

如需在本地开发环境中使用本页面上的 REST API 示例,请使用您提供给 gcloud CLI 的 凭证。

    安装 Google Cloud CLI。

    如果您使用的是外部身份提供方 (IdP),则必须先 使用联合身份登录 gcloud CLI

如需了解详情,请参阅 身份验证文档 中的 Google Cloud 使用 REST 时进行身份验证。

配置 Cloud KMS 密钥

可选。如果您计划创建可观测性存储桶并指定 Cloud KMS 密钥,请执行以下操作:

  1. 启用 Cloud Key Management Service API。

    启用 API 所需的角色

    如需启用 API,您需要拥有 serviceusage.services.enable 权限。如果您创建了项目,则可能已通过 Owner 角色 (roles/owner) 拥有此权限。否则,您可以通过 Service Usage Admin 角色 (roles/serviceusage.serviceUsageAdmin) 获取此权限。了解如何授予角色

    启用 API