<br />

<br />


[Managed Airflow (Gen 3)](https://docs.cloud.google.com/composer/docs/composer-3/manage-environment-labels.md.txt "View this page for Managed Airflow (Gen 3)") \| [Managed Airflow (Gen 2)](https://docs.cloud.google.com/composer/docs/composer-2/manage-environment-labels.md.txt "View this page for Managed Airflow (Gen 2)") \| **Managed Airflow (Legacy Gen 1)**

<br />

<br />

<br />

<br />

<br />

<br />

This page explains how to assign labels to your Managed Airflow environments and then break down billing costs based on these labels.

## About environment labels

Environment labels are key-value pairs that you can assign to your
environments. For example, if `owner:engineering-team` is a custom label, then
`owner` is the key, and `engineering-team` is the value.

Each environment can have multiple labels, but the label keys for a single
environment must be unique. You can assign a same key and value to several
environments.

## Environment labels in billing reports

Environment labels that you assign to your environments are visible in billing
reports, so you can break down costs based on both keys and values from the
labels.

> [!IMPORTANT]
> **Important:** It might take **up to 1 day** for environment labels to propagate to billing reports. However, the billing costs are labeled starting from the moment when you assigned the label to your environment.

Labels don't apply retroactively. For example, if you assign a label on
May 15, billing costs for May 14 do not contain the assigned label.

## Assign labels to new environments

You can assign labels when you create an environment. For more information,
see [Creating environments](https://docs.cloud.google.com/composer/docs/composer-1/create-environments.md.txt#labels).

## Assign labels to existing environments

### Console

1. Go to the **Environments** page in the Google Cloud console:

   [Go to Environments](https://console.cloud.google.com/composer/environments)
2. Select your environment.

3. Go to the **Labels** tab.

4. Click **Edit** , then click **Add label**.

5. Add a key-value pair for the label, then click **Save**.

6. Wait until the environment updates.

### gcloud

When you update an environment using
the [`gcloud composer`](https://docs.cloud.google.com/sdk/gcloud/reference/composer/environments/update.md.txt) command, the following arguments
specify labels for the environment:

- `--clear-labels` removes all labels.

- `--update-labels` updates specified labels; creates new labels if they
  don't already exist.

- `--remove-labels` removes specified labels; specified label that do not
  exist are ignored.

If you use several of these arguments, they are applied in the following
order: `--clear-labels`, `--update-labels`, `--remove-labels`.

**Update or create labels**

```bash
gcloud composer environments update ENVIRONMENT_NAME \
    --location LOCATION \
    --update-labels LABEL_KEY=LABEL_VALUE
```

**Remove specified labels**

```bash
gcloud composer environments update ENVIRONMENT_NAME \
    --location LOCATION \
    --remove-labels LABEL_KEY
```

**Remove all labels**

```bash
gcloud composer environments update ENVIRONMENT_NAME \
    --location LOCATION \
    --clear-labels
```

Replace:

- `ENVIRONMENT_NAME` with the name of the environment.
- `LOCATION` with the region where the environment is located.
- `LABEL_KEY` with the environment label key that you want to create, update, or remove.
- `LABEL_VALUE` with the environment label value.

**Example**

The following example updates the `owner` label, creates the new `env`
label, and removes the `misc` label:

```bash
gcloud composer environments update example-environment \
    --location us-central1 \
    --update-labels owner=engineering-team,env=production \
    --remove-labels misc
```

### API

When you update an environment, in the [Environment](https://docs.cloud.google.com/composer/docs/reference/rest/v1/projects.locations.environments.md.txt#Environment)
resource, specify new labels of your environment.

**Replace all labels**

To replace all labels, include `labels` in the `updateMask` query parameter
and provide a replacement in the request body.

```json
// PATCH https://composer.googleapis.com/v1/
// ?{name=projects/*/locations/*/environments/*}
// &updateMask.fieldPaths=labels

{
  "labels":{
      &quot;LABEL_KEY": &quot;LABEL_VALUE"
    }
}
```

Replace:

- `LABEL_KEY` with a key of the environment label.
- `LABEL_VALUE` with a new value for the environment label.

Example:

```json
// PATCH https://composer.googleapis.com/v1/
// ?{name=projects/*/locations/*/environments/*}
// &updateMask.fieldPaths=labels

{
  "labels": {
    "owner": "engineering-team",
    "env": "production"
  }
}
```

**Remove all labels**

To remove all labels, include `labels` in the `updateMask` query parameter
and do not provide the replacement value.

**Update individual labels**

To update a label or add a new label to existing labels, include
`labels.LABEL_KEY` in the `updateMask` query parameter and provide a
replacement in the request body.

```json
// PATCH https://composer.googleapis.com/v1/
// ?{name=projects/*/locations/*/environments/*}
// &updateMask=labels.LABEL_KEY

{
  "labels":{
      &quot;LABEL_KEY": &quot;LABEL_VALUE"
    }
}
```

Replace:

- `LABEL_KEY` with a key of the environment label.
- `LABEL_VALUE` with a new value for the environment label.

Example:

```json
// PATCH https://composer.googleapis.com/v1/
// ?name=projects/example-project/locations/
// us-central1/environments/example-environment
// &updateMask=labels.owner,labels.env

{
  "labels": {
    "owner": "engineering-team",
    "env": "production"
  }
}
```

**Remove individual labels**

To remove labels, include `labels.LABEL_KEY` in the `updateMask` query
parameter and do not provide the replacement value.

### Terraform

To create an environment with default parameters is a specified location,
edit the `labels` block in your Terraform configuration and run
`terraform apply`.

    resource "google_composer_environment" "example" {
      name = "example-environment"
      region = "us-central1"

      labels = {
        LABEL_KEY = "LABEL_VALUE"
      }

    }

Replace:

- `LABEL_KEY` with the environment label key that you want to create or update. To remove labels, delete their fields.
- `LABEL_VALUE` with the environment label value.

Example:

    resource "google_composer_environment" "example" {
      name = "example-environment"
      region = "us-central1"

      labels = {
        owner = "engineering-team"
        env = "production"
      }
    }

## View labels in reports

After the labels for your environment propagate to billing reports, you can break down billing costs based on these labels:

1. [View Cloud Billing reports](https://docs.cloud.google.com/billing/docs/how-to/reports.md.txt#getting_started) for your
   Cloud Billing account.

2. On the **Reports** page:

   1. Click **Show filters**.
   2. In the **Filters** dialog, expand the **Labels** section.
   3. [Filter the displayed data](https://docs.cloud.google.com/billing/docs/how-to/reports.md.txt#filters) based on keys and values of your environment labels.

## What's next

- [Managed Airflow pricing](https://docs.cloud.google.com/composer/pricing)