사용자 지정 할당 규칙 업데이트
https://api.datadoghq.com/api/v2/cost/arbitrary_rule/{rule_id}https://api.us3.datadoghq.com/api/v2/cost/arbitrary_rule/{rule_id}https://api.us5.datadoghq.com/api/v2/cost/arbitrary_rule/{rule_id}https://api.datadoghq.eu/api/v2/cost/arbitrary_rule/{rule_id}https://api.ap1.datadoghq.com/api/v2/cost/arbitrary_rule/{rule_id}https://api.ap2.datadoghq.com/api/v2/cost/arbitrary_rule/{rule_id}https://api.uk1.datadoghq.com/api/v2/cost/arbitrary_rule/{rule_id}https://api.ddog-gov.com/api/v2/cost/arbitrary_rule/{rule_id}https://api.us2.ddog-gov.com/api/v2/cost/arbitrary_rule/{rule_id}개요
새 필터와 할당 전략으로 기존 사용자 지정 할당 규칙을 업데이트합니다.
전략 방법:
- PROPORTIONAL/EVEN: 기존 비용을 기준으로 비용을 비례/균등하게 할당합니다. 필수 항목: granularity, allocated_by_tag_keys. 선택 항목: based_on_costs, allocated_by_filters, evaluate_grouped_by_tag_keys, evaluate_grouped_by_filters.
- PROPORTIONAL_TIMESERIES/EVEN_TIMESERIES: 시계열 데이터를 기준으로 할당합니다. 필수 항목: granularity, based_on_timeseries. 선택 항목: evaluate_grouped_by_tag_keys.
- PERCENT: 특정 태그에 고정된 비율을 할당합니다. 필수 항목: allocated_by(비율 할당 배열)
- USAGE_METRIC: 사용량 메트릭을 기반으로 할당합니다(구현 방식은 다를 수 있음).
필터 조건:
- 단일 값 조건에는 value를 사용합니다: "is", "is not", "contains", "=", "!=", "like", "not like"
- 다중 값 조건에는 values를 사용합니다: "in", "not in"
- value와 values는 동시에 사용할 수 없습니다.
지원되는 연산자: is, is not, contains, in, not in, =, !=, like, not like
OAuth apps require the cloud_cost_management_write authorization scope to access this endpoint.
인수
경로 파라미터
rule_id [required]The unique identifier of the custom allocation rule
요청
Body Data (required)
dataArbitraryCostUpsertRequest 객체의 정의입니다.
attributesThe definition of ArbitraryCostUpsertRequestDataAttributes object.
costs_to_allocate [required]The attributes costs_to_allocate.
condition [required]The items condition.
tag [required]The items tag.
valueThe items value.
valuesThe items values.
enabledThe attributes enabled.
order_idThe attributes order_id.
provider [required]The attributes provider.
rejectedThe attributes rejected.
rule_name [required]The attributes rule_name.
strategy [required]The definition of ArbitraryCostUpsertRequestDataAttributesStrategy object.
allocated_byThe strategy allocated_by.
allocated_tags [required]The items allocated_tags.
key [required]The items key.
value [required]The items value.
percentage [required]The items percentage. The numeric value format should be a 32bit float value.
allocated_by_filtersThe strategy allocated_by_filters.
condition [required]The items condition.
tag [required]The items tag.
valueThe items value.
valuesThe items values.
allocated_by_tag_keysThe strategy allocated_by_tag_keys.
based_on_costsThe strategy based_on_costs.
condition [required]The items condition.
tag [required]The items tag.
valueThe items value.
valuesThe items values.
based_on_timeseriesThe strategy based_on_timeseries.
evaluate_grouped_by_filtersThe strategy evaluate_grouped_by_filters.
condition [required]The items condition.
tag [required]The items tag.
valueThe items value.
valuesThe items values.
evaluate_grouped_by_tag_keysThe strategy evaluate_grouped_by_tag_keys.
granularityThe strategy granularity.
method [required]The strategy method.
type [required]The attributes type.
idThe ArbitraryCostUpsertRequestData id.
type [required]Upsert arbitrary rule resource type.
upsert_arbitrary_ruleupsert_arbitrary_rule{
"data": {
"attributes": {
"costs_to_allocate": [
{
"condition": "is",
"tag": "account_id",
"value": "123456789",
"values": []
},
{
"condition": "in",
"tag": "environment",
"value": "",
"values": [
"production",
"staging"
]
}
],
"enabled": true,
"order_id": 1,
"provider": [
"aws",
"gcp"
],
"rule_name": "example-arbitrary-cost-rule",
"strategy": {
"allocated_by_tag_keys": [
"team",
"environment"
],
"based_on_costs": [
{
"condition": "is",
"tag": "service",
"value": "web-api",
"values": []
},
{
"condition": "not in",
"tag": "team",
"value": "",
"values": [
"legacy",
"deprecated"
]
}
],
"granularity": "daily",
"method": "proportional"
},
"type": "shared"
},
"type": "upsert_arbitrary_rule"
}
}응답
OK
The definition of ArbitraryRuleResponse object.
dataThe definition of ArbitraryRuleResponseData object.
attributesThe definition of ArbitraryRuleResponseDataAttributes object.
costs_to_allocate [required]The attributes costs_to_allocate.
condition [required]The items condition.
tag [required]The items tag.
valueThe items value.
valuesThe items values.
created [required]The attributes created.
enabled [required]The attributes enabled.
last_modified_user_uuid [required]The attributes last_modified_user_uuid.
order_id [required]The attributes order_id.
processing_statusThe attributes processing_status.
provider [required]The attributes provider.
rejectedThe attributes rejected.
rule_name [required]The attributes rule_name.
strategy [required]The definition of ArbitraryRuleResponseDataAttributesStrategy object.
allocated_byThe strategy allocated_by.
allocated_tags [required]The items allocated_tags.
key [required]The items key.
value [required]The items value.
percentage [required]The items percentage. The numeric value format should be a 32bit float value.
allocated_by_filtersThe strategy allocated_by_filters.
condition [required]The items condition.
tag [required]The items tag.
valueThe items value.
valuesThe items values.
allocated_by_tag_keysThe strategy allocated_by_tag_keys.
based_on_costsThe strategy based_on_costs.
condition [required]The items condition.
tag [required]The items tag.
valueThe items value.
valuesThe items values.
based_on_timeseriesThe rule strategy based_on_timeseries.
evaluate_grouped_by_filtersThe strategy evaluate_grouped_by_filters.
condition [required]The items condition.
tag [required]The items tag.
valueThe items value.
valuesThe items values.
evaluate_grouped_by_tag_keysThe strategy evaluate_grouped_by_tag_keys.
granularityThe strategy granularity.
method [required]The strategy method.
type [required]The attributes type.
updated [required]The attributes updated.
version [required]The attributes version.
idThe ArbitraryRuleResponseData id.
type [required]Arbitrary rule resource type.
arbitrary_rulearbitrary_rule{
"data": {
"attributes": {
"costs_to_allocate": [
{
"condition": "is",
"tag": "account_id",
"value": "123456789",
"values": null
},
{
"condition": "in",
"tag": "environment",
"value": "",
"values": [
"production",
"staging"
]
}
],
"created": "2023-01-01T12:00:00Z",
"enabled": true,
"last_modified_user_uuid": "user-123-uuid",
"order_id": 1,
"provider": [
"aws",
"gcp"
],
"rule_name": "Example custom allocation rule",
"strategy": {
"allocated_by_tag_keys": [
"team",
"environment"
],
"based_on_costs": [
{
"condition": "is",
"tag": "service",
"value": "web-api",
"values": null
},
{
"condition": "not in",
"tag": "team",
"value": "",
"values": [
"legacy",
"deprecated"
]
}
],
"granularity": "daily",
"method": "proportional"
},
"type": "shared",
"updated": "2023-01-01T12:00:00Z",
"version": 1
},
"id": "123",
"type": "arbitrary_rule"
}
}Too many requests
API error response.
errors [required]A list of errors.
{
"errors": [
"Bad Request"
]
}코드 예시
# Path parameters
export rule_id="CHANGE_ME"
# Set your Datadog site and credentials
export DD_SITE="datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"
curl -X PATCH "https://api.${DD_SITE}/api/v2/cost/arbitrary_rule/${rule_id}" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"data": {
"attributes": {
"costs_to_allocate": [
{
"condition": "is",
"tag": "account_id",
"value": "123456789",
"values": []
},
{
"condition": "in",
"tag": "environment",
"value": "",
"values": [
"production",
"staging"
]
}
],
"enabled": true,
"order_id": 1,
"provider": [
"aws",
"gcp"
],
"rule_name": "example-arbitrary-cost-rule",
"strategy": {
"allocated_by_tag_keys": [
"team",
"environment"
],
"based_on_costs": [
{
"condition": "is",
"tag": "service",
"value": "web-api",
"values": []
},
{
"condition": "not in",
"tag": "team",
"value": "",
"values": [
"legacy",
"deprecated"
]
}
],
"granularity": "daily",
"method": "proportional"
},
"type": "shared"
},
"type": "upsert_arbitrary_rule"
}
}
EOF# Path parameters
export rule_id="CHANGE_ME"
# Set your Datadog site and credentials
export DD_SITE="us3.datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"
curl -X PATCH "https://api.${DD_SITE}/api/v2/cost/arbitrary_rule/${rule_id}" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"data": {
"attributes": {
"costs_to_allocate": [
{
"condition": "is",
"tag": "account_id",
"value": "123456789",
"values": []
},
{
"condition": "in",
"tag": "environment",
"value": "",
"values": [
"production",
"staging"
]
}
],
"enabled": true,
"order_id": 1,
"provider": [
"aws",
"gcp"
],
"rule_name": "example-arbitrary-cost-rule",
"strategy": {
"allocated_by_tag_keys": [
"team",
"environment"
],
"based_on_costs": [
{
"condition": "is",
"tag": "service",
"value": "web-api",
"values": []
},
{
"condition": "not in",
"tag": "team",
"value": "",
"values": [
"legacy",
"deprecated"
]
}
],
"granularity": "daily",
"method": "proportional"
},
"type": "shared"
},
"type": "upsert_arbitrary_rule"
}
}
EOF# Path parameters
export rule_id="CHANGE_ME"
# Set your Datadog site and credentials
export DD_SITE="us5.datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"
curl -X PATCH "https://api.${DD_SITE}/api/v2/cost/arbitrary_rule/${rule_id}" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"data": {
"attributes": {
"costs_to_allocate": [
{
"condition": "is",
"tag": "account_id",
"value": "123456789",
"values": []
},
{
"condition": "in",
"tag": "environment",
"value": "",
"values": [
"production",
"staging"
]
}
],
"enabled": true,
"order_id": 1,
"provider": [
"aws",
"gcp"
],
"rule_name": "example-arbitrary-cost-rule",
"strategy": {
"allocated_by_tag_keys": [
"team",
"environment"
],
"based_on_costs": [
{
"condition": "is",
"tag": "service",
"value": "web-api",
"values": []
},
{
"condition": "not in",
"tag": "team",
"value": "",
"values": [
"legacy",
"deprecated"
]
}
],
"granularity": "daily",
"method": "proportional"
},
"type": "shared"
},
"type": "upsert_arbitrary_rule"
}
}
EOF# Path parameters
export rule_id="CHANGE_ME"
# Set your Datadog site and credentials
export DD_SITE="datadoghq.eu"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"
curl -X PATCH "https://api.${DD_SITE}/api/v2/cost/arbitrary_rule/${rule_id}" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"data": {
"attributes": {
"costs_to_allocate": [
{
"condition": "is",
"tag": "account_id",
"value": "123456789",
"values": []
},
{
"condition": "in",
"tag": "environment",
"value": "",
"values": [
"production",
"staging"
]
}
],
"enabled": true,
"order_id": 1,
"provider": [
"aws",
"gcp"
],
"rule_name": "example-arbitrary-cost-rule",
"strategy": {
"allocated_by_tag_keys": [
"team",
"environment"
],
"based_on_costs": [
{
"condition": "is",
"tag": "service",
"value": "web-api",
"values": []
},
{
"condition": "not in",
"tag": "team",
"value": "",
"values": [
"legacy",
"deprecated"
]
}
],
"granularity": "daily",
"method": "proportional"
},
"type": "shared"
},
"type": "upsert_arbitrary_rule"
}
}
EOF# Path parameters
export rule_id="CHANGE_ME"
# Set your Datadog site and credentials
export DD_SITE="ap1.datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"
curl -X PATCH "https://api.${DD_SITE}/api/v2/cost/arbitrary_rule/${rule_id}" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"data": {
"attributes": {
"costs_to_allocate": [
{
"condition": "is",
"tag": "account_id",
"value": "123456789",
"values": []
},
{
"condition": "in",
"tag": "environment",
"value": "",
"values": [
"production",
"staging"
]
}
],
"enabled": true,
"order_id": 1,
"provider": [
"aws",
"gcp"
],
"rule_name": "example-arbitrary-cost-rule",
"strategy": {
"allocated_by_tag_keys": [
"team",
"environment"
],
"based_on_costs": [
{
"condition": "is",
"tag": "service",
"value": "web-api",
"values": []
},
{
"condition": "not in",
"tag": "team",
"value": "",
"values": [
"legacy",
"deprecated"
]
}
],
"granularity": "daily",
"method": "proportional"
},
"type": "shared"
},
"type": "upsert_arbitrary_rule"
}
}
EOF# Path parameters
export rule_id="CHANGE_ME"
# Set your Datadog site and credentials
export DD_SITE="ap2.datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"
curl -X PATCH "https://api.${DD_SITE}/api/v2/cost/arbitrary_rule/${rule_id}" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"data": {
"attributes": {
"costs_to_allocate": [
{
"condition": "is",
"tag": "account_id",
"value": "123456789",
"values": []
},
{
"condition": "in",
"tag": "environment",
"value": "",
"values": [
"production",
"staging"
]
}
],
"enabled": true,
"order_id": 1,
"provider": [
"aws",
"gcp"
],
"rule_name": "example-arbitrary-cost-rule",
"strategy": {
"allocated_by_tag_keys": [
"team",
"environment"
],
"based_on_costs": [
{
"condition": "is",
"tag": "service",
"value": "web-api",
"values": []
},
{
"condition": "not in",
"tag": "team",
"value": "",
"values": [
"legacy",
"deprecated"
]
}
],
"granularity": "daily",
"method": "proportional"
},
"type": "shared"
},
"type": "upsert_arbitrary_rule"
}
}
EOF# Path parameters
export rule_id="CHANGE_ME"
# Set your Datadog site and credentials
export DD_SITE="uk1.datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"
curl -X PATCH "https://api.${DD_SITE}/api/v2/cost/arbitrary_rule/${rule_id}" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"data": {
"attributes": {
"costs_to_allocate": [
{
"condition": "is",
"tag": "account_id",
"value": "123456789",
"values": []
},
{
"condition": "in",
"tag": "environment",
"value": "",
"values": [
"production",
"staging"
]
}
],
"enabled": true,
"order_id": 1,
"provider": [
"aws",
"gcp"
],
"rule_name": "example-arbitrary-cost-rule",
"strategy": {
"allocated_by_tag_keys": [
"team",
"environment"
],
"based_on_costs": [
{
"condition": "is",
"tag": "service",
"value": "web-api",
"values": []
},
{
"condition": "not in",
"tag": "team",
"value": "",
"values": [
"legacy",
"deprecated"
]
}
],
"granularity": "daily",
"method": "proportional"
},
"type": "shared"
},
"type": "upsert_arbitrary_rule"
}
}
EOF# Path parameters
export rule_id="CHANGE_ME"
# Set your Datadog site and credentials
export DD_SITE="ddog-gov.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"
curl -X PATCH "https://api.${DD_SITE}/api/v2/cost/arbitrary_rule/${rule_id}" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"data": {
"attributes": {
"costs_to_allocate": [
{
"condition": "is",
"tag": "account_id",
"value": "123456789",
"values": []
},
{
"condition": "in",
"tag": "environment",
"value": "",
"values": [
"production",
"staging"
]
}
],
"enabled": true,
"order_id": 1,
"provider": [
"aws",
"gcp"
],
"rule_name": "example-arbitrary-cost-rule",
"strategy": {
"allocated_by_tag_keys": [
"team",
"environment"
],
"based_on_costs": [
{
"condition": "is",
"tag": "service",
"value": "web-api",
"values": []
},
{
"condition": "not in",
"tag": "team",
"value": "",
"values": [
"legacy",
"deprecated"
]
}
],
"granularity": "daily",
"method": "proportional"
},
"type": "shared"
},
"type": "upsert_arbitrary_rule"
}
}
EOF# Path parameters
export rule_id="CHANGE_ME"
# Set your Datadog site and credentials
export DD_SITE="us2.ddog-gov.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"
curl -X PATCH "https://api.${DD_SITE}/api/v2/cost/arbitrary_rule/${rule_id}" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"data": {
"attributes": {
"costs_to_allocate": [
{
"condition": "is",
"tag": "account_id",
"value": "123456789",
"values": []
},
{
"condition": "in",
"tag": "environment",
"value": "",
"values": [
"production",
"staging"
]
}
],
"enabled": true,
"order_id": 1,
"provider": [
"aws",
"gcp"
],
"rule_name": "example-arbitrary-cost-rule",
"strategy": {
"allocated_by_tag_keys": [
"team",
"environment"
],
"based_on_costs": [
{
"condition": "is",
"tag": "service",
"value": "web-api",
"values": []
},
{
"condition": "not in",
"tag": "team",
"value": "",
"values": [
"legacy",
"deprecated"
]
}
],
"granularity": "daily",
"method": "proportional"
},
"type": "shared"
},
"type": "upsert_arbitrary_rule"
}
}
EOF// Update custom allocation rule returns "OK" response
package main
import (
"context"
"encoding/json"
"fmt"
"os"
"github.com/DataDog/datadog-api-client-go/v2/api/datadog"
"github.com/DataDog/datadog-api-client-go/v2/api/datadogV2"
)
func main() {
body := datadogV2.ArbitraryCostUpsertRequest{
Data: &datadogV2.ArbitraryCostUpsertRequestData{
Attributes: &datadogV2.ArbitraryCostUpsertRequestDataAttributes{
CostsToAllocate: []datadogV2.ArbitraryCostUpsertRequestDataAttributesCostsToAllocateItems{
{
Condition: "is",
Tag: "account_id",
Value: datadog.PtrString("123456789"),
Values: *datadog.NewNullableList(&[]string{}),
},
{
Condition: "in",
Tag: "environment",
Value: datadog.PtrString(""),
Values: *datadog.NewNullableList(&[]string{
"production",
"staging",
}),
},
},
Enabled: datadog.PtrBool(true),
OrderId: datadog.PtrInt64(1),
Provider: []string{
"aws",
"gcp",
},
RuleName: "example-arbitrary-cost-rule",
Strategy: datadogV2.ArbitraryCostUpsertRequestDataAttributesStrategy{
AllocatedByTagKeys: []string{
"team",
"environment",
},
BasedOnCosts: []datadogV2.ArbitraryCostUpsertRequestDataAttributesStrategyBasedOnCostsItems{
{
Condition: "is",
Tag: "service",
Value: datadog.PtrString("web-api"),
Values: *datadog.NewNullableList(&[]string{}),
},
{
Condition: "not in",
Tag: "team",
Value: datadog.PtrString(""),
Values: *datadog.NewNullableList(&[]string{
"legacy",
"deprecated",
}),
},
},
Granularity: datadog.PtrString("daily"),
Method: "proportional",
},
Type: "shared",
},
Type: datadogV2.ARBITRARYCOSTUPSERTREQUESTDATATYPE_UPSERT_ARBITRARY_RULE,
},
}
ctx := datadog.NewDefaultContext(context.Background())
ctx = context.WithValue(ctx, datadog.ContextAccessToken, os.Getenv("DD_BEARER_TOKEN"))
configuration := datadog.NewConfiguration()
apiClient := datadog.NewAPIClient(configuration)
api := datadogV2.NewCloudCostManagementApi(apiClient)
resp, r, err := api.UpdateCustomAllocationRule(ctx, 683, body)
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `CloudCostManagementApi.UpdateCustomAllocationRule`: %v\n", err)
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
}
responseContent, _ := json.MarshalIndent(resp, "", " ")
fmt.Fprintf(os.Stdout, "Response from `CloudCostManagementApi.UpdateCustomAllocationRule`:\n%s\n", responseContent)
}
Instructions
First install the library and its dependencies and then save the example to main.go and run following commands:
DD_SITE="datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" go run "main.go"DD_SITE="us3.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" go run "main.go"DD_SITE="us5.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" go run "main.go"DD_SITE="datadoghq.eu" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" go run "main.go"DD_SITE="ap1.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" go run "main.go"DD_SITE="ap2.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" go run "main.go"DD_SITE="uk1.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" go run "main.go"DD_SITE="ddog-gov.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" go run "main.go"DD_SITE="us2.ddog-gov.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" go run "main.go"// Update custom allocation rule returns "OK" response
import com.datadog.api.client.ApiClient;
import com.datadog.api.client.ApiException;
import com.datadog.api.client.v2.api.CloudCostManagementApi;
import com.datadog.api.client.v2.model.ArbitraryCostUpsertRequest;
import com.datadog.api.client.v2.model.ArbitraryCostUpsertRequestData;
import com.datadog.api.client.v2.model.ArbitraryCostUpsertRequestDataAttributes;
import com.datadog.api.client.v2.model.ArbitraryCostUpsertRequestDataAttributesCostsToAllocateItems;
import com.datadog.api.client.v2.model.ArbitraryCostUpsertRequestDataAttributesStrategy;
import com.datadog.api.client.v2.model.ArbitraryCostUpsertRequestDataAttributesStrategyBasedOnCostsItems;
import com.datadog.api.client.v2.model.ArbitraryCostUpsertRequestDataType;
import com.datadog.api.client.v2.model.ArbitraryRuleResponse;
import java.util.Arrays;
public class Example {
public static void main(String[] args) {
ApiClient defaultClient = ApiClient.getDefaultApiClient();
defaultClient.setAccessToken(System.getenv("DD_BEARER_TOKEN"));
CloudCostManagementApi apiInstance = new CloudCostManagementApi(defaultClient);
ArbitraryCostUpsertRequest body =
new ArbitraryCostUpsertRequest()
.data(
new ArbitraryCostUpsertRequestData()
.attributes(
new ArbitraryCostUpsertRequestDataAttributes()
.costsToAllocate(
Arrays.asList(
new ArbitraryCostUpsertRequestDataAttributesCostsToAllocateItems()
.condition("is")
.tag("account_id")
.value("123456789"),
new ArbitraryCostUpsertRequestDataAttributesCostsToAllocateItems()
.condition("in")
.tag("environment")
.value("")
.values(Arrays.asList("production", "staging"))))
.enabled(true)
.orderId(1L)
.provider(Arrays.asList("aws", "gcp"))
.ruleName("example-arbitrary-cost-rule")
.strategy(
new ArbitraryCostUpsertRequestDataAttributesStrategy()
.allocatedByTagKeys(Arrays.asList("team", "environment"))
.basedOnCosts(
Arrays.asList(
new ArbitraryCostUpsertRequestDataAttributesStrategyBasedOnCostsItems()
.condition("is")
.tag("service")
.value("web-api"),
new ArbitraryCostUpsertRequestDataAttributesStrategyBasedOnCostsItems()
.condition("not in")
.tag("team")
.value("")
.values(Arrays.asList("legacy", "deprecated"))))
.granularity("daily")
.method("proportional"))
.type("shared"))
.type(ArbitraryCostUpsertRequestDataType.UPSERT_ARBITRARY_RULE));
try {
ArbitraryRuleResponse result = apiInstance.updateCustomAllocationRule(683L, body);
System.out.println(result);
} catch (ApiException e) {
System.err.println(
"Exception when calling CloudCostManagementApi#updateCustomAllocationRule");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}
Instructions
First install the library and its dependencies and then save the example to Example.java and run following commands:
DD_SITE="datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" java "Example.java"DD_SITE="us3.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" java "Example.java"DD_SITE="us5.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" java "Example.java"DD_SITE="datadoghq.eu" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" java "Example.java"DD_SITE="ap1.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" java "Example.java"DD_SITE="ap2.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" java "Example.java"DD_SITE="uk1.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" java "Example.java"DD_SITE="ddog-gov.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" java "Example.java"DD_SITE="us2.ddog-gov.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" java "Example.java""""
Update custom allocation rule returns "OK" response
"""
from os import environ
from datadog_api_client import ApiClient, Configuration
from datadog_api_client.v2.api.cloud_cost_management_api import CloudCostManagementApi
from datadog_api_client.v2.model.arbitrary_cost_upsert_request import ArbitraryCostUpsertRequest
from datadog_api_client.v2.model.arbitrary_cost_upsert_request_data import ArbitraryCostUpsertRequestData
from datadog_api_client.v2.model.arbitrary_cost_upsert_request_data_attributes import (
ArbitraryCostUpsertRequestDataAttributes,
)
from datadog_api_client.v2.model.arbitrary_cost_upsert_request_data_attributes_costs_to_allocate_items import (
ArbitraryCostUpsertRequestDataAttributesCostsToAllocateItems,
)
from datadog_api_client.v2.model.arbitrary_cost_upsert_request_data_attributes_strategy import (
ArbitraryCostUpsertRequestDataAttributesStrategy,
)
from datadog_api_client.v2.model.arbitrary_cost_upsert_request_data_attributes_strategy_based_on_costs_items import (
ArbitraryCostUpsertRequestDataAttributesStrategyBasedOnCostsItems,
)
from datadog_api_client.v2.model.arbitrary_cost_upsert_request_data_type import ArbitraryCostUpsertRequestDataType
body = ArbitraryCostUpsertRequest(
data=ArbitraryCostUpsertRequestData(
attributes=ArbitraryCostUpsertRequestDataAttributes(
costs_to_allocate=[
ArbitraryCostUpsertRequestDataAttributesCostsToAllocateItems(
condition="is",
tag="account_id",
value="123456789",
values=[],
),
ArbitraryCostUpsertRequestDataAttributesCostsToAllocateItems(
condition="in",
tag="environment",
value="",
values=[
"production",
"staging",
],
),
],
enabled=True,
order_id=1,
provider=[
"aws",
"gcp",
],
rule_name="example-arbitrary-cost-rule",
strategy=ArbitraryCostUpsertRequestDataAttributesStrategy(
allocated_by_tag_keys=[
"team",
"environment",
],
based_on_costs=[
ArbitraryCostUpsertRequestDataAttributesStrategyBasedOnCostsItems(
condition="is",
tag="service",
value="web-api",
values=[],
),
ArbitraryCostUpsertRequestDataAttributesStrategyBasedOnCostsItems(
condition="not in",
tag="team",
value="",
values=[
"legacy",
"deprecated",
],
),
],
granularity="daily",
method="proportional",
),
type="shared",
),
type=ArbitraryCostUpsertRequestDataType.UPSERT_ARBITRARY_RULE,
),
)
configuration = Configuration()
configuration.access_token = environ["DD_BEARER_TOKEN"]
with ApiClient(configuration) as api_client:
api_instance = CloudCostManagementApi(api_client)
response = api_instance.update_custom_allocation_rule(rule_id=683, body=body)
print(response)
Instructions
First install the library and its dependencies and then save the example to example.py and run following commands:
DD_SITE="datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" python3 "example.py"DD_SITE="us3.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" python3 "example.py"DD_SITE="us5.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" python3 "example.py"DD_SITE="datadoghq.eu" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" python3 "example.py"DD_SITE="ap1.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" python3 "example.py"DD_SITE="ap2.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" python3 "example.py"DD_SITE="uk1.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" python3 "example.py"DD_SITE="ddog-gov.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" python3 "example.py"DD_SITE="us2.ddog-gov.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" python3 "example.py"# Update custom allocation rule returns "OK" response
require "datadog_api_client"
DatadogAPIClient.configure do |config|
config.access_token = ENV["DD_BEARER_TOKEN"]
end
api_instance = DatadogAPIClient::V2::CloudCostManagementAPI.new
body = DatadogAPIClient::V2::ArbitraryCostUpsertRequest.new({
data: DatadogAPIClient::V2::ArbitraryCostUpsertRequestData.new({
attributes: DatadogAPIClient::V2::ArbitraryCostUpsertRequestDataAttributes.new({
costs_to_allocate: [
DatadogAPIClient::V2::ArbitraryCostUpsertRequestDataAttributesCostsToAllocateItems.new({
condition: "is",
tag: "account_id",
value: "123456789",
values: [],
}),
DatadogAPIClient::V2::ArbitraryCostUpsertRequestDataAttributesCostsToAllocateItems.new({
condition: "in",
tag: "environment",
value: "",
values: [
"production",
"staging",
],
}),
],
enabled: true,
order_id: 1,
provider: [
"aws",
"gcp",
],
rule_name: "example-arbitrary-cost-rule",
strategy: DatadogAPIClient::V2::ArbitraryCostUpsertRequestDataAttributesStrategy.new({
allocated_by_tag_keys: [
"team",
"environment",
],
based_on_costs: [
DatadogAPIClient::V2::ArbitraryCostUpsertRequestDataAttributesStrategyBasedOnCostsItems.new({
condition: "is",
tag: "service",
value: "web-api",
values: [],
}),
DatadogAPIClient::V2::ArbitraryCostUpsertRequestDataAttributesStrategyBasedOnCostsItems.new({
condition: "not in",
tag: "team",
value: "",
values: [
"legacy",
"deprecated",
],
}),
],
granularity: "daily",
method: "proportional",
}),
type: "shared",
}),
type: DatadogAPIClient::V2::ArbitraryCostUpsertRequestDataType::UPSERT_ARBITRARY_RULE,
}),
})
p api_instance.update_custom_allocation_rule(683, body)
Instructions
First install the library and its dependencies and then save the example to example.rb and run following commands:
DD_SITE="datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" rb "example.rb"DD_SITE="us3.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" rb "example.rb"DD_SITE="us5.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" rb "example.rb"DD_SITE="datadoghq.eu" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" rb "example.rb"DD_SITE="ap1.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" rb "example.rb"DD_SITE="ap2.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" rb "example.rb"DD_SITE="uk1.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" rb "example.rb"DD_SITE="ddog-gov.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" rb "example.rb"DD_SITE="us2.ddog-gov.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" rb "example.rb"// Update custom allocation rule returns "OK" response
use datadog_api_client::datadog;
use datadog_api_client::datadogV2::api_cloud_cost_management::CloudCostManagementAPI;
use datadog_api_client::datadogV2::model::ArbitraryCostUpsertRequest;
use datadog_api_client::datadogV2::model::ArbitraryCostUpsertRequestData;
use datadog_api_client::datadogV2::model::ArbitraryCostUpsertRequestDataAttributes;
use datadog_api_client::datadogV2::model::ArbitraryCostUpsertRequestDataAttributesCostsToAllocateItems;
use datadog_api_client::datadogV2::model::ArbitraryCostUpsertRequestDataAttributesStrategy;
use datadog_api_client::datadogV2::model::ArbitraryCostUpsertRequestDataAttributesStrategyBasedOnCostsItems;
use datadog_api_client::datadogV2::model::ArbitraryCostUpsertRequestDataType;
#[tokio::main]
async fn main() {
let body = ArbitraryCostUpsertRequest::new().data(
ArbitraryCostUpsertRequestData::new(
ArbitraryCostUpsertRequestDataType::UPSERT_ARBITRARY_RULE,
)
.attributes(
ArbitraryCostUpsertRequestDataAttributes::new(
vec![
ArbitraryCostUpsertRequestDataAttributesCostsToAllocateItems::new(
"is".to_string(),
"account_id".to_string(),
)
.value("123456789".to_string())
.values(Some(vec![])),
ArbitraryCostUpsertRequestDataAttributesCostsToAllocateItems::new(
"in".to_string(),
"environment".to_string(),
)
.value("".to_string())
.values(Some(vec!["production".to_string(), "staging".to_string()])),
],
vec!["aws".to_string(), "gcp".to_string()],
"example-arbitrary-cost-rule".to_string(),
ArbitraryCostUpsertRequestDataAttributesStrategy::new("proportional".to_string())
.allocated_by_tag_keys(vec!["team".to_string(), "environment".to_string()])
.based_on_costs(vec![
ArbitraryCostUpsertRequestDataAttributesStrategyBasedOnCostsItems::new(
"is".to_string(),
"service".to_string(),
)
.value("web-api".to_string())
.values(Some(vec![])),
ArbitraryCostUpsertRequestDataAttributesStrategyBasedOnCostsItems::new(
"not in".to_string(),
"team".to_string(),
)
.value("".to_string())
.values(Some(vec!["legacy".to_string(), "deprecated".to_string()])),
])
.granularity("daily".to_string()),
"shared".to_string(),
)
.enabled(true)
.order_id(1),
),
);
let configuration = datadog::Configuration::new();
let api = CloudCostManagementAPI::with_config(configuration);
let resp = api.update_custom_allocation_rule(683, body).await;
if let Ok(value) = resp {
println!("{:#?}", value);
} else {
println!("{:#?}", resp.unwrap_err());
}
}
Instructions
First install the library and its dependencies and then save the example to src/main.rs and run following commands:
DD_SITE="datadoghq.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" cargo runDD_SITE="us3.datadoghq.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" cargo runDD_SITE="us5.datadoghq.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" cargo runDD_SITE="datadoghq.eu" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" cargo runDD_SITE="ap1.datadoghq.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" cargo runDD_SITE="ap2.datadoghq.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" cargo runDD_SITE="uk1.datadoghq.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" cargo runDD_SITE="ddog-gov.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" cargo runDD_SITE="us2.ddog-gov.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" cargo run/**
* Update custom allocation rule returns "OK" response
*/
import { client, v2 } from "@datadog/datadog-api-client";
const configuration = client.createConfiguration({
authMethods: {
AuthZ: {
accessToken: process.env.DD_BEARER_TOKEN as string,
},
},
});
const apiInstance = new v2.CloudCostManagementApi(configuration);
const params: v2.CloudCostManagementApiUpdateCustomAllocationRuleRequest = {
body: {
data: {
attributes: {
costsToAllocate: [
{
condition: "is",
tag: "account_id",
value: "123456789",
values: [],
},
{
condition: "in",
tag: "environment",
value: "",
values: ["production", "staging"],
},
],
enabled: true,
orderId: 1,
provider: ["aws", "gcp"],
ruleName: "example-arbitrary-cost-rule",
strategy: {
allocatedByTagKeys: ["team", "environment"],
basedOnCosts: [
{
condition: "is",
tag: "service",
value: "web-api",
values: [],
},
{
condition: "not in",
tag: "team",
value: "",
values: ["legacy", "deprecated"],
},
],
granularity: "daily",
method: "proportional",
},
type: "shared",
},
type: "upsert_arbitrary_rule",
},
},
ruleId: 683,
};
apiInstance
.updateCustomAllocationRule(params)
.then((data: v2.ArbitraryRuleResponse) => {
console.log(
"API called successfully. Returned data: " + JSON.stringify(data)
);
})
.catch((error: any) => console.error(error));
Instructions
First install the library and its dependencies and then save the example to example.ts and run following commands:
DD_SITE="datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" tsc "example.ts"DD_SITE="us3.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" tsc "example.ts"DD_SITE="us5.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" tsc "example.ts"DD_SITE="datadoghq.eu" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" tsc "example.ts"DD_SITE="ap1.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" tsc "example.ts"DD_SITE="ap2.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" tsc "example.ts"DD_SITE="uk1.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" tsc "example.ts"DD_SITE="ddog-gov.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" tsc "example.ts"DD_SITE="us2.ddog-gov.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" tsc "example.ts"