Cloud Composer 3 | Cloud Composer 2 | Cloud Composer 1
本頁說明如何為 Cloud Composer 環境指派標籤,然後根據這些標籤細分帳單費用。
關於環境標籤
環境標籤是您可以指派給環境的鍵/值組合。舉例來說,如果 owner:engineering-team
是自訂標籤,則 owner
是鍵,而 engineering-team
是值。
每個環境可以有多個標籤,但單一環境的標籤鍵不得重複。您可以將相同鍵和值指派給多個環境。
帳單報表中的環境標籤
您指派給環境的環境標籤會顯示在帳單報表中,因此您可以根據標籤中的鍵和值細分費用。
標籤不會溯及既往。舉例來說,如果您在 5 月 15 日指派標籤,5 月 14 日的帳單費用就不會包含指派的標籤。
為新環境指派標籤
建立環境時,您可以指派標籤。詳情請參閱「建立環境」。
為現有環境指派標籤
主控台
前往 Google Cloud 控制台的「Environments」(環境) 頁面:
選取環境。
前往「標籤」分頁。
依序按一下「編輯」和「新增標籤」。
新增標籤的鍵/值組合,然後按一下「儲存」。
等待環境更新。
gcloud
使用 gcloud composer
指令更新環境時,下列引數會指定環境的標籤:
--clear-labels
移除所有標籤。--update-labels
會更新指定標籤,並在標籤不存在時建立新標籤。--remove-labels
移除指定標籤;系統會忽略不存在的指定標籤。
如果您使用多個這類引數,系統會依下列順序套用:--clear-labels
、--update-labels
、--remove-labels
。
更新或建立標籤
gcloud composer environments update ENVIRONMENT_NAME \
--location LOCATION \
--update-labels LABEL_KEY=LABEL_VALUE
移除指定標籤
gcloud composer environments update ENVIRONMENT_NAME \
--location LOCATION \
--remove-labels LABEL_KEY
移除所有標籤
gcloud composer environments update ENVIRONMENT_NAME \
--location LOCATION \
--clear-labels
取代:
- 將
ENVIRONMENT_NAME
替換為環境的名稱。 LOCATION
改成環境所在的地區。LABEL_KEY
,並提供要建立、更新或移除的環境標籤鍵。LABEL_VALUE
,並填入環境標籤值。
示例
以下範例會更新 owner
標籤、建立新的 env
標籤,並移除 misc
標籤:
gcloud composer environments update example-environment \
--location us-central1 \
--update-labels owner=engineering-team,env=production \
--remove-labels misc
API
更新環境時,請在「Environment」資源中指定環境的新標籤。
取代所有標籤
如要取代所有標籤,請在 updateMask
查詢參數中加入 labels
,並在要求主體中提供取代標籤。
// PATCH https://composer.googleapis.com/v1/
// ?{name=projects/*/locations/*/environments/*}
// &updateMask.fieldPaths=labels
{
"labels":{
"LABEL_KEY": "LABEL_VALUE"
}
}
取代:
LABEL_KEY
,並以環境標籤做為鍵。LABEL_VALUE
,並為環境標籤提供新值。
範例:
// PATCH https://composer.googleapis.com/v1/
// ?{name=projects/*/locations/*/environments/*}
// &updateMask.fieldPaths=labels
{
"labels": {
"owner": "engineering-team",
"env": "production"
}
}
移除所有標籤
如要移除所有標籤,請在 updateMask
查詢參數中加入 labels
,且不要提供取代值。
更新個別標籤
如要更新標籤或為現有標籤新增標籤,請在 updateMask
查詢參數中加入 labels.LABEL_KEY
,並在要求主體中提供替代項目。
// PATCH https://composer.googleapis.com/v1/
// ?{name=projects/*/locations/*/environments/*}
// &updateMask=labels.LABEL_KEY
{
"labels":{
"LABEL_KEY": "LABEL_VALUE"
}
}
取代:
LABEL_KEY
,並以環境標籤做為鍵。LABEL_VALUE
,並為環境標籤提供新值。
範例:
// 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"
}
}
移除個別標籤
如要移除標籤,請在 updateMask
查詢參數中加入 labels.LABEL_KEY
,且不要提供取代值。
Terraform
如要在指定位置建立含有預設參數的環境,請編輯 Terraform 設定中的 labels
區塊,然後執行 terraform apply
。
resource "google_composer_environment" "example" {
name = "example-environment"
region = "us-central1"
labels = {
LABEL_KEY = "LABEL_VALUE"
}
}
取代:
LABEL_KEY
改為您要建立或更新的環境標籤鍵。如要移除標籤,請刪除標籤的欄位。LABEL_VALUE
,並填入環境標籤值。
範例:
resource "google_composer_environment" "example" {
name = "example-environment"
region = "us-central1"
labels = {
owner = "engineering-team"
env = "production"
}
}
在報表中查看標籤
環境標籤傳播至帳單報表後,您就可以根據這些標籤細分帳單費用:
查看 Cloud Billing 帳戶的 Cloud Billing 報表。
在「報表」頁面中:
- 按一下「顯示篩選器」。
- 在「篩選器」對話方塊中,展開「標籤」部分。
- 根據環境標籤的鍵和值篩選顯示的資料。