[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-08-18 (世界標準時間)。"],[],[],null,["# Overview\n\nThis document provides a brief overview of labels and its features.\n\nWhat are labels?\n----------------\n\nA label is a key-value pair that you can assign to Google Cloud resources.\nThey help you organize these resources and manage your costs at scale, with the\ngranularity you need. You can attach a label to each resource, then filter the\nresources based on their labels. Information about labels is forwarded to the billing system that\nlets you break down your billed charges by label. With built-in [billing reports](/billing/docs/how-to/reports),\nyou can filter and group costs by resource labels. You can also use labels to\nquery [billing data exports](/billing/docs/how-to/bq-examples).\n\nRequirements for labels\n-----------------------\n\nThe labels applied to a resource must meet the following\nrequirements:\n\n- Each resource can have up to 64 labels.\n- Each label must be a key-value pair.\n- Keys have a minimum length of 1 character and a maximum length of 63 characters, and cannot be empty. Values can be empty, and have a maximum length of 63 characters.\n- Keys and values can contain only lowercase letters, numeric characters, underscores, and dashes. All characters must use UTF-8 encoding, and international characters are allowed. Keys must start with a lowercase letter or international character.\n- The key portion of a label must be unique within a single resource. However, you can use the same key with multiple resources.\n\nThese limits apply to the key and value for each label, and to the\nindividual Google Cloud resources that have labels. There\nis no limit on how many labels you can apply across all resources\nwithin a project.\n\nCommon uses of labels\n---------------------\n\nHere are some common use cases for labels:\n\n- **Team or cost center labels** : Add labels based on team or\n cost center to distinguish resources owned by different\n teams (for example, `team:research` and `team:analytics`). You can use this\n type of label for cost accounting or budgeting.\n\n- **Component labels** : For example, `component:redis`,\n `component:frontend`, `component:ingest`, and `component:dashboard`.\n\n- **Environment or stage labels** : For example,\n `environment:production` and `environment:test`.\n\n- **State labels** : For example, `state:active`,\n `state:readytodelete`, and `state:archive`.\n\n- **Ownership labels** : Used to identify the teams that are\n responsible for operations, for example: `team:shopping-cart`.\n\n\n- **Network labels** : A label can be attached to a virtual machine. [Network tags](/vpc/docs/add-remove-network-tags) that you defined in the past will appear as a label without a value.\n\n\u003cbr /\u003e\n\n| **Note:** Don't include sensitive information in labels, including personally identifiable information, such as an individual's name or title. Labels are not designed to handle sensitive information.\n\nWe don't recommend creating large numbers of unique labels, such as\nfor timestamps or individual values for every API call.\nThe problem with this approach is that when the values change frequently or with\nkeys that clutter the catalog, this makes it difficult to effectively filter and\nreport on resources.\n\nLabels and tags\n---------------\n\nLabels can be used as queryable annotations for resources, but can't be used\nto set conditions on policies. Tags provide a way to conditionally allow or\ndeny policies based on whether a resource has a specific tag, by providing fine-grained\ncontrol over policies. For more information, see the\n[Tags overview](/resource-manager/docs/tags/tags-overview).\n\nPermissions\n-----------\n\nThe following permissions are required when you need to add, modify, and view labels for projects:\n\n- You can add or modify a label by calling the [`projects.patch()`](/resource-manager/reference/rest/v3/projects/patch) method. This requires the `resourcemanager.projects.update` permission.\n- You can view a project's label by calling the [`projects.get()`](/resource-manager/reference/rest/v3/projects/get) method. This requires the `resourcemanager.projects.get` permission.\n\nUnderstand costs using labels\n-----------------------------\n\nYou can attach a label to a resource and then filter resources based on\ntheir labels. Information about labels is forwarded to the billing system that\nallows you to [break down your billed charges](/billing/docs/how-to/bq-examples)\nby label.\n\nHere are some ways in which you can use labels to understand costs:\n\n- You can add labels such as `costcenter=`\u003cvar translate=\"no\"\u003ecost_center_name\u003c/var\u003e, `service=`\u003cvar translate=\"no\"\u003eservice_name\u003c/var\u003e, and `environment=`\u003cvar translate=\"no\"\u003eenvironment_name\u003c/var\u003e to your VMs or Cloud Storage buckets. This allows you to understand where your resources are deployed, for what purpose, and the cost center to which they should be charged.\n- You can enable the [export of billing data](/billing/docs/how-to/export-data-bigquery) to BigQuery. Labels are exported to BigQuery with the corresponding Google Cloud resources and their usage. This allows you to monitor aspects such as the cost to run the shopping cart service in the application or the cost of developer test machines.\n- You can use BigQuery in combination with labels to understand the cost of all test system resources versus production resources or how much a particular service costs.\n\n### Example\n\nIn this example, the cost of `playlist` services for a project is determined by\nexporting usage and labels to BigQuery.\nTo do this, start by enabling the billing export to BigQuery. `labels-demo-prj`\nis the source of your resource usage and `labels_demo_bqexport`\nis the destination dataset where usage data is stored. After you export your\nusage and labels to BigQuery, you can determine how much your `playlist`\nservice costs are.\n\nHere are the details of the Compute Engine usage and its associated cost in BigQuery.\n\n| **Note:** When filtering your billing breakdown by label keys, you cannot select labels applied to a project. You can select other user-created labels that you'd set up and applied to Google Cloud services."]]