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
取代所有標籤
如要取代所有標籤,請在 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"
}
}
在報表中查看標籤
環境標籤傳播至帳單報表後,您就可以依據這些標籤細分帳單費用:
在「報表」頁面中:
- 按一下「顯示篩選器」。
- 在「Filters」對話方塊中,展開「Labels」部分。
- 依據環境標籤的鍵和值篩選顯示的資料。