Reporting usage with labels Stay organized with collections Save and categorize content based on your preferences.
Labels in Pub/Sub help you with cost management and resourceorganization. For example, imagine you have multiple subscriptions for differenttypes of news updates. You can label each subscription with a relevant category,such asnews_category=sports ornews_category=entertainment.
What are labels?
A label is a key-value pair that you can assign to Google Cloud resources.They help you organize these resources and manage your costs at scale, with thegranularity you need. You can attach a label to each resource, then filter theresources based on their labels. Information about labels is forwarded to the billing system thatlets you break down your billed charges by label. With built-inbilling reports,you can filter and group costs by resource labels. You can also use labels toquerybilling data exports.
Requirements for labels
The labels applied to a resource must meet the followingrequirements:
- Each resource can have up to 64 labels.
- Each label must be a key-value pair.
- Keys have a minimum length of 1 character and a maximum length of 63characters, and cannot be empty. Values can be empty, and have a maximum lengthof 63 characters.
- Keys and values can contain only lowercase letters, numeric characters,underscores, and dashes. All characters must use UTF-8 encoding, andinternational characters are allowed. Keys must start with a lowercase letter orinternational character.
- The key portion of a label must be unique within a single resource.However, you can use the same key with multiple resources.
These limits apply to the key and value for each label, and to theindividual Google Cloud resources that have labels. Thereis no limit on how many labels you can apply across all resourceswithin a project.
Common uses of labels
Here are some common use cases for labels:
Team or cost center labels: Add labels based on team orcost center to distinguish resources owned by differentteams (for example,
team:researchandteam:analytics). You can use thistype of label for cost accounting or budgeting.Component labels: For example,
component:redis,component:frontend,component:ingest, andcomponent:dashboard.Environment or stage labels: For example,
environment:productionandenvironment:test.State labels: For example,
state:active,state:readytodelete, andstate:archive.Ownership labels: Used to identify the teams that areresponsible for operations, for example:
team:shopping-cart.
We don't recommend creating large numbers of unique labels, such asfor timestamps or individual values for every API call.The problem with this approach is that when the values change frequently or withkeys that clutter the catalog, this makes it difficult to effectively filter andreport on resources.
Labels and tags
Labels can be used as queryable annotations for resources, but can't be usedto set conditions on policies. Tags provide a way to conditionally allow ordeny policies based on whether a resource has a specific tag, by providing fine-grainedcontrol over policies. For more information, see theTags overview.
Managing labels in Pub/Sub
In Pub/Sub, labels are often used to organizefees for a given billing account. Fees are associated withthe billing account of the project that contains the requested resource, but youmight want to establish additional associations. For example, a subscriptionthat belongs to one project might be created for a topic that belongs to adifferent project. You can use labels to associate that topicand subscription with a common cost center.
Note: While you can use labels to organizefees by billing account, no additional fees are charged for the use ofPub/Sub labels.Pub/Sub resources don't inherit labels from each other. In thepreceding example, you would set the same label on both the topic and thesubscription in order to associate those charges.
You can use the following features to apply labels to Pub/Subresources:
- TheGoogle Cloud console:Select a resource and change to theLABELS tab.
- Pub/Sub Client Libraries(specificallyJavaandPython).
- TheGoogle Cloud CLI for Pub/Sub.For example, see thecreate topiccommand.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2026-02-19 UTC.