Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
162 changes: 138 additions & 24 deletions .generator/schemas/v2/openapi.yaml

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions examples/v2/usage-metering/CreateQuotas.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@
DatadogAPIClient::V2::UsageQuotaCreateData.new({
attributes: DatadogAPIClient::V2::UsageQuotaCreateAttributes.new({
enforced: true,
scope: {
user_handle: "jane@example.com",
},
usage_limit: 100000,
pending_usage_limit: 100000,
usage_limit: 600000,
}),
type: DatadogAPIClient::V2::UsageQuotaType::QUOTAS,
}),
Expand Down
9 changes: 9 additions & 0 deletions examples/v2/usage-metering/DeletePendingQuota.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Cancel a scheduled usage quota limit returns "No Content" response

require "datadog_api_client"
DatadogAPIClient.configure do |config|
config.access_token = ENV["DD_BEARER_TOKEN"]
config.unstable_operations["v2.delete_pending_quota".to_sym] = true
end
api_instance = DatadogAPIClient::V2::UsageMeteringAPI.new
api_instance.delete_pending_quota("ai_credits", "MTIzNB9haV9jcmVkaXRzH3VzZXJfaGFuZGxlOl9fQUxMX18")
2 changes: 1 addition & 1 deletion examples/v2/usage-metering/DeleteQuota.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
config.unstable_operations["v2.delete_quota".to_sym] = true
end
api_instance = DatadogAPIClient::V2::UsageMeteringAPI.new
api_instance.delete_quota("ai_credits", "MjAfYWlfY3JlZGl0c1911c2VyX2hhbmRsZTpfX0FMTF9f")
api_instance.delete_quota("ai_credits", "MTIzNB9haV9jcmVkaXRzH3VzZXJfaGFuZGxlOl9fQUxMX18")
5 changes: 3 additions & 2 deletions examples/v2/usage-metering/UpdateQuota.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
data: DatadogAPIClient::V2::UsageQuotaUpdateData.new({
attributes: DatadogAPIClient::V2::UsageQuotaUpdateAttributes.new({
enforced: false,
pending_usage_limit: 50000,
usage_limit: 120000,
}),
id: "MjAfYWlfY3JlZGl0c1911c2VyX2hhbmRsZTpfX0FMTF9f",
id: "MTIzNB9haV9jcmVkaXRzH3VzZXJfaGFuZGxlOl9fQUxMX18",
type: DatadogAPIClient::V2::UsageQuotaType::QUOTAS,
}),
})
p api_instance.update_quota("ai_credits", "MjAfYWlfY3JlZGl0c1911c2VyX2hhbmRsZTpfX0FMTF9f", body)
p api_instance.update_quota("ai_credits", "MTIzNB9haV9jcmVkaXRzH3VzZXJfaGFuZGxlOl9fQUxMX18", body)
4 changes: 4 additions & 0 deletions features/scenarios_model_mapping.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3220,6 +3220,10 @@
"id" => "String",
"body" => "UsageQuotaUpdateRequest",
},
"v2.DeletePendingQuota" => {
"quota_namespace" => "String",
"id" => "String",
},
"v2.ListAllCSMAgents" => {
"page" => "Integer",
"size" => "Integer",
Expand Down
6 changes: 6 additions & 0 deletions features/v2/undo.json
Original file line number Diff line number Diff line change
Expand Up @@ -11046,6 +11046,12 @@
"type": "idempotent"
}
},
"DeletePendingQuota": {
"tag": "Usage Metering",
"undo": {
"type": "idempotent"
}
},
"GetUsageSummaryAvailableFields": {
"tag": "Usage Metering",
"undo": {
Expand Down
45 changes: 36 additions & 9 deletions features/v2/usage_metering.feature
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,47 @@ Feature: Usage Metering
And an instance of "UsageMetering" API

@generated @skip @team:ddoghq/billing-hub
Scenario: Create or update usage quotas returns "Bad Request" response
Scenario: Cancel a scheduled usage quota limit returns "Bad Request. Returned if the `id` is malformed or does not belong to the requested quota namespace." response
Given operation "DeletePendingQuota" enabled
And new "DeletePendingQuota" request
And request contains "quota_namespace" parameter from "REPLACE.ME"
And request contains "id" parameter from "REPLACE.ME"
When the request is sent
Then the response status is 400 Bad Request. Returned if the `id` is malformed or does not belong to the requested quota namespace.

@generated @skip @team:ddoghq/billing-hub
Scenario: Cancel a scheduled usage quota limit returns "No Content" response
Given operation "DeletePendingQuota" enabled
And new "DeletePendingQuota" request
And request contains "quota_namespace" parameter from "REPLACE.ME"
And request contains "id" parameter from "REPLACE.ME"
When the request is sent
Then the response status is 204 No Content

@generated @skip @team:ddoghq/billing-hub
Scenario: Cancel a scheduled usage quota limit returns "Not Found" response
Given operation "DeletePendingQuota" enabled
And new "DeletePendingQuota" request
And request contains "quota_namespace" parameter from "REPLACE.ME"
And request contains "id" parameter from "REPLACE.ME"
When the request is sent
Then the response status is 404 Not Found

@generated @skip @team:ddoghq/billing-hub
Scenario: Create or update usage quotas returns "Bad Request. Returned if the request is malformed, including when an item sets `pending_usage_limit` on a scoped quota, provides `enforced` without `usage_limit`, or provides neither limit. A pending-only item for a quota that does not exist is reported in that item's `error`; when only the caller's organization is targeted, this failure returns `400`." response
Given operation "CreateQuotas" enabled
And new "CreateQuotas" request
And request contains "quota_namespace" parameter from "REPLACE.ME"
And body with value {"data": [{"attributes": {"enforced": true, "scope": {"user_handle": "jane@example.com"}, "usage_limit": 100000}, "type": "quotas"}]}
And body with value {"data": [{"attributes": {"enforced": true, "pending_usage_limit": 100000, "usage_limit": 600000}, "type": "quotas"}]}
When the request is sent
Then the response status is 400 Bad Request
Then the response status is 400 Bad Request. Returned if the request is malformed, including when an item sets `pending_usage_limit` on a scoped quota, provides `enforced` without `usage_limit`, or provides neither limit. A pending-only item for a quota that does not exist is reported in that item's `error`; when only the caller's organization is targeted, this failure returns `400`.

@generated @skip @team:ddoghq/billing-hub
Scenario: Create or update usage quotas returns "OK. The response includes each item's result; see each item's `error` attribute for any that failed to write." response
Given operation "CreateQuotas" enabled
And new "CreateQuotas" request
And request contains "quota_namespace" parameter from "REPLACE.ME"
And body with value {"data": [{"attributes": {"enforced": true, "scope": {"user_handle": "jane@example.com"}, "usage_limit": 100000}, "type": "quotas"}]}
And body with value {"data": [{"attributes": {"enforced": true, "pending_usage_limit": 100000, "usage_limit": 600000}, "type": "quotas"}]}
When the request is sent
Then the response status is 200 OK. The response includes each item's result; see each item's `error` attribute for any that failed to write.

Expand Down Expand Up @@ -304,22 +331,22 @@ Feature: Usage Metering
Then the response status is 200 OK

@generated @skip @team:ddoghq/billing-hub
Scenario: Update a usage quota returns "Bad Request. Returned if the request is malformed, or if the `id` in the request body does not match the `id` in the request path." response
Scenario: Update a usage quota returns "Bad Request. Returned if the request is malformed, if the `id` in the request body does not match the `id` in the request path, if none of `usage_limit`, `enforced`, or `pending_usage_limit` is provided, or if `pending_usage_limit` is set on a scoped quota." response
Given operation "UpdateQuota" enabled
And new "UpdateQuota" request
And request contains "quota_namespace" parameter from "REPLACE.ME"
And request contains "id" parameter from "REPLACE.ME"
And body with value {"data": {"attributes": {"enforced": false, "usage_limit": 120000}, "id": "MjAfYWlfY3JlZGl0c1911c2VyX2hhbmRsZTpfX0FMTF9f", "type": "quotas"}}
And body with value {"data": {"attributes": {"enforced": false, "pending_usage_limit": 50000, "usage_limit": 120000}, "id": "MTIzNB9haV9jcmVkaXRzH3VzZXJfaGFuZGxlOl9fQUxMX18", "type": "quotas"}}
When the request is sent
Then the response status is 400 Bad Request. Returned if the request is malformed, or if the `id` in the request body does not match the `id` in the request path.
Then the response status is 400 Bad Request. Returned if the request is malformed, if the `id` in the request body does not match the `id` in the request path, if none of `usage_limit`, `enforced`, or `pending_usage_limit` is provided, or if `pending_usage_limit` is set on a scoped quota.

@generated @skip @team:ddoghq/billing-hub
Scenario: Update a usage quota returns "Not Found" response
Given operation "UpdateQuota" enabled
And new "UpdateQuota" request
And request contains "quota_namespace" parameter from "REPLACE.ME"
And request contains "id" parameter from "REPLACE.ME"
And body with value {"data": {"attributes": {"enforced": false, "usage_limit": 120000}, "id": "MjAfYWlfY3JlZGl0c1911c2VyX2hhbmRsZTpfX0FMTF9f", "type": "quotas"}}
And body with value {"data": {"attributes": {"enforced": false, "pending_usage_limit": 50000, "usage_limit": 120000}, "id": "MTIzNB9haV9jcmVkaXRzH3VzZXJfaGFuZGxlOl9fQUxMX18", "type": "quotas"}}
When the request is sent
Then the response status is 404 Not Found

Expand All @@ -329,6 +356,6 @@ Feature: Usage Metering
And new "UpdateQuota" request
And request contains "quota_namespace" parameter from "REPLACE.ME"
And request contains "id" parameter from "REPLACE.ME"
And body with value {"data": {"attributes": {"enforced": false, "usage_limit": 120000}, "id": "MjAfYWlfY3JlZGl0c1911c2VyX2hhbmRsZTpfX0FMTF9f", "type": "quotas"}}
And body with value {"data": {"attributes": {"enforced": false, "pending_usage_limit": 50000, "usage_limit": 120000}, "id": "MTIzNB9haV9jcmVkaXRzH3VzZXJfaGFuZGxlOl9fQUxMX18", "type": "quotas"}}
When the request is sent
Then the response status is 200 OK
1 change: 1 addition & 0 deletions lib/datadog_api_client/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ def initialize
"v2.search_cost_recommendations": false,
"v2.update_unit_cost": false,
"v2.create_quotas": false,
"v2.delete_pending_quota": false,
"v2.delete_quota": false,
"v2.list_quotas": false,
"v2.update_quota": false,
Expand Down
84 changes: 82 additions & 2 deletions lib/datadog_api_client/v2/api/usage_metering_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ def create_quotas(quota_namespace, body, opts = {})

# Create or update usage quotas.
#
# Creates or updates one or more usage quotas by scope. If a quota already exists for a supplied scope, it is updated; otherwise, a new quota is created. Requires the `billing_edit` permission.
# Creates or updates one or more usage quotas by scope. If a quota already exists for a supplied scope, it is updated.
# Otherwise, a quota is created only when `usage_limit` and `enforced` are provided.
# For the organization-wide quota, `pending_usage_limit` schedules a limit for the next usage period and can
# accompany an immediate limit or update an existing quota by itself.
# Scheduled changes follow `include_descendants` like the other fields. Requires the `billing_edit` permission.
#
# @param quota_namespace [String] The product-specific namespace whose usage quotas are being managed.
# @param body [UsageQuotasCreateRequest] The usage quotas to create or update.
Expand Down Expand Up @@ -103,6 +107,82 @@ def create_quotas_with_http_info(quota_namespace, body, opts = {})
return data, status_code, headers
end

# Cancel a scheduled usage quota limit.
#
# @see #delete_pending_quota_with_http_info
def delete_pending_quota(quota_namespace, id, opts = {})
delete_pending_quota_with_http_info(quota_namespace, id, opts)
nil
end

# Cancel a scheduled usage quota limit.
#
# Cancels the limit change scheduled to take effect at the start of the next usage period, leaving the usage quota and its current limit unchanged. Returns `404` when the quota does not exist, has no scheduled change, or its scheduled change has already taken effect; in every case the quota is left unchanged. The quota must belong to the caller's organization or one of its descendants, and its opaque identifier must belong to the requested quota namespace. Requires the `billing_edit` permission.
#
# @param quota_namespace [String] The product-specific namespace whose usage quotas are being managed.
# @param id [String] The opaque quota identifier returned by a previous list or create request. Clients must pass this value verbatim.
# @param opts [Hash] the optional parameters
# @return [Array<(nil, Integer, Hash)>] nil, response status code and response headers
def delete_pending_quota_with_http_info(quota_namespace, id, opts = {})
unstable_enabled = @api_client.config.unstable_operations["v2.delete_pending_quota".to_sym]
if unstable_enabled
@api_client.config.logger.warn format("Using unstable operation '%s'", "v2.delete_pending_quota")
else
raise DatadogAPIClient::APIError.new(message: format("Unstable operation '%s' is disabled", "v2.delete_pending_quota"))
end

if @api_client.config.debugging
@api_client.config.logger.debug 'Calling API: UsageMeteringAPI.delete_pending_quota ...'
end
# verify the required parameter 'quota_namespace' is set
if @api_client.config.client_side_validation && quota_namespace.nil?
fail ArgumentError, "Missing the required parameter 'quota_namespace' when calling UsageMeteringAPI.delete_pending_quota"
end
# verify the required parameter 'id' is set
if @api_client.config.client_side_validation && id.nil?
fail ArgumentError, "Missing the required parameter 'id' when calling UsageMeteringAPI.delete_pending_quota"
end
# resource path
local_var_path = '/api/v2/usage/quotas/{quota_namespace}/{id}/pending'.sub('{quota_namespace}', CGI.escape(quota_namespace.to_s).gsub('%2F', '/')).sub('{id}', CGI.escape(id.to_s).gsub('%2F', '/'))

# query parameters
query_params = opts[:query_params] || {}

# header parameters
header_params = opts[:header_params] || {}
# HTTP header 'Accept' (if needed)
header_params['Accept'] = @api_client.select_header_accept(['*/*'])

# form parameters
form_params = opts[:form_params] || {}

# http body (model)
post_body = opts[:debug_body]

# return_type
return_type = opts[:debug_return_type]

# auth_names
auth_names = opts[:debug_auth_names] || [:apiKeyAuth, :appKeyAuth, :AuthZ]

new_options = opts.merge(
:operation => :delete_pending_quota,
:header_params => header_params,
:query_params => query_params,
:form_params => form_params,
:body => post_body,
:auth_names => auth_names,
:return_type => return_type,
:api_version => "V2"
)

data, status_code, headers = @api_client.call_api(Net::HTTP::Delete, local_var_path, new_options)
if @api_client.config.debugging
@api_client.config.logger.debug "API called: UsageMeteringAPI#delete_pending_quota\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
end
return data, status_code, headers
end

# Delete a usage quota.
#
# @see #delete_quota_with_http_info
Expand Down Expand Up @@ -1292,7 +1372,7 @@ def update_quota(quota_namespace, id, body, opts = {})

# Update a usage quota.
#
# Updates the supplied fields on a usage quota and leaves omitted fields unchanged. The quota must belong to the caller's organization or one of its descendants, and its opaque identifier must belong to the requested quota namespace. Requires the `billing_edit` permission.
# Updates the supplied fields on a usage quota and leaves omitted fields unchanged. For an organization-wide quota, `pending_usage_limit` schedules a limit for the next usage period. The quota must belong to the caller's organization or one of its descendants, and its opaque identifier must belong to the requested quota namespace. Requires the `billing_edit` permission.
#
# @param quota_namespace [String] The product-specific namespace whose usage quotas are being managed.
# @param id [String] The opaque quota identifier returned by a previous list or create request. Clients must pass this value verbatim.
Expand Down
Loading
Loading