Manage environment labels and break down environment costs (original) (raw)

Cloud Composer 3 | Cloud Composer 2 | Cloud Composer 1

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

Environment labels are key-value pairs that you can assign to your environments. For example, if owner:engineering-team is a custom label, thenowner 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.

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.

Assign labels to existing environments

Console

  1. Go to the Environments page in the Google Cloud console:
    Go to 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 command, the following arguments specify labels for the environment:

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

Update or create labels

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

Remove specified labels

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

Remove all labels

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

Replace:

Example

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

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 Environmentresource, 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.

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

{
  "labels":{
      "LABEL_KEY": "LABEL_VALUE"
    }
}

Replace:

Example:

// 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, includelabels.LABEL_KEY in the updateMask query parameter and provide a replacement in the request body.

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

{
  "labels":{
      "LABEL_KEY": "LABEL_VALUE"
    }
}

Replace:

Example:

// 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 runterraform apply.

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

  labels = {
    LABEL_KEY = "LABEL_VALUE"
  }

}

Replace:

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 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 based on keys and values of your environment labels.

What's next