Skip to content

Commit 2945616

Browse files
api-clients-generation-pipeline[bot]ci.datadog-api-spec
andauthored
Add a cost monitor example (#2198)
Co-authored-by: ci.datadog-api-spec <[email protected]>
1 parent c914b88 commit 2945616

11 files changed

+396
-5
lines changed

.apigentools-info

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
"spec_versions": {
55
"v1": {
66
"apigentools_version": "1.6.6",
7-
"regenerated": "2025-01-17 21:03:20.906234",
8-
"spec_repo_commit": "617655da"
7+
"regenerated": "2025-01-17 21:41:16.067400",
8+
"spec_repo_commit": "27e609f7"
99
},
1010
"v2": {
1111
"apigentools_version": "1.6.6",
12-
"regenerated": "2025-01-17 21:03:20.920935",
13-
"spec_repo_commit": "617655da"
12+
"regenerated": "2025-01-17 21:41:16.082979",
13+
"spec_repo_commit": "27e609f7"
1414
}
1515
}
1616
}

.generator/schemas/v1/openapi.yaml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6784,6 +6784,62 @@ components:
67846784
- FIREFOX_LAPTOP_LARGE
67856785
- FIREFOX_TABLET
67866786
- FIREFOX_MOBILE_SMALL
6787+
MonitorFormulaAndFunctionCostAggregator:
6788+
description: Aggregation methods for metric queries.
6789+
enum:
6790+
- avg
6791+
- sum
6792+
- max
6793+
- min
6794+
- last
6795+
- area
6796+
- l2norm
6797+
- percentile
6798+
- stddev
6799+
example: avg
6800+
type: string
6801+
x-enum-varnames:
6802+
- AVG
6803+
- SUM
6804+
- MAX
6805+
- MIN
6806+
- LAST
6807+
- AREA
6808+
- L2NORM
6809+
- PERCENTILE
6810+
- STDDEV
6811+
MonitorFormulaAndFunctionCostDataSource:
6812+
description: Data source for cost queries.
6813+
enum:
6814+
- metrics
6815+
- cloud_cost
6816+
- datadog_usage
6817+
example: cloud_cost
6818+
type: string
6819+
x-enum-varnames:
6820+
- METRICS
6821+
- CLOUD_COST
6822+
- DATADOG_USAGE
6823+
MonitorFormulaAndFunctionCostQueryDefinition:
6824+
description: A formula and functions cost query.
6825+
properties:
6826+
aggregator:
6827+
$ref: '#/components/schemas/MonitorFormulaAndFunctionCostAggregator'
6828+
data_source:
6829+
$ref: '#/components/schemas/MonitorFormulaAndFunctionCostDataSource'
6830+
name:
6831+
description: Name of the query for use in formulas.
6832+
example: query1
6833+
type: string
6834+
query:
6835+
description: The monitor query.
6836+
example: sum:all.cost{*}.rollup(sum, 86400)
6837+
type: string
6838+
required:
6839+
- name
6840+
- data_source
6841+
- query
6842+
type: object
67876843
MonitorFormulaAndFunctionEventAggregation:
67886844
description: Aggregation methods for event platform queries.
67896845
enum:
@@ -6934,6 +6990,7 @@ components:
69346990
description: A formula and function query.
69356991
oneOf:
69366992
- $ref: '#/components/schemas/MonitorFormulaAndFunctionEventQueryDefinition'
6993+
- $ref: '#/components/schemas/MonitorFormulaAndFunctionCostQueryDefinition'
69376994
MonitorGroupSearchResponse:
69386995
description: The response of a monitor group search.
69396996
example:
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2025-01-17T11:21:26.452Z

cassettes/features/v1/monitors/Create-a-Cost-Monitor-returns-OK-response.yml

Lines changed: 53 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Create a Cost Monitor returns "OK" response
2+
3+
require "datadog_api_client"
4+
api_instance = DatadogAPIClient::V1::MonitorsAPI.new
5+
6+
body = DatadogAPIClient::V1::Monitor.new({
7+
name: "Example Monitor",
8+
type: DatadogAPIClient::V1::MonitorType::COST_ALERT,
9+
query: 'formula("exclude_null(query1)").last("7d").anomaly(direction="above", threshold=10) >= 5',
10+
message: "some message Notify: @hipchat-channel",
11+
tags: [
12+
"test:examplemonitor",
13+
"env:ci",
14+
],
15+
priority: 3,
16+
options: DatadogAPIClient::V1::MonitorOptions.new({
17+
thresholds: DatadogAPIClient::V1::MonitorThresholds.new({
18+
critical: 5,
19+
warning: 3,
20+
}),
21+
variables: [
22+
DatadogAPIClient::V1::MonitorFormulaAndFunctionCostQueryDefinition.new({
23+
data_source: DatadogAPIClient::V1::MonitorFormulaAndFunctionCostDataSource::CLOUD_COST,
24+
query: "sum:aws.cost.net.amortized.shared.resources.allocated{aws_product IN (amplify ,athena, backup, bedrock ) } by {aws_product}.rollup(sum, 86400)",
25+
name: "query1",
26+
aggregator: DatadogAPIClient::V1::MonitorFormulaAndFunctionCostAggregator::SUM,
27+
}),
28+
],
29+
include_tags: true,
30+
}),
31+
})
32+
p api_instance.create_monitor(body)

features/v1/monitors.feature

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ Feature: Monitors
3333
Then the response status is 200 OK
3434
And the response "data.ok[0]" has the same value as "monitor.id"
3535

36+
@team:DataDog/monitor-app
37+
Scenario: Create a Cost Monitor returns "OK" response
38+
Given new "CreateMonitor" request
39+
And body with value {"name": "Example Monitor", "type": "cost alert", "query": "formula(\"exclude_null(query1)\").last(\"7d\").anomaly(direction=\"above\", threshold=10) >= 5", "message": "some message Notify: @hipchat-channel", "tags": ["test:examplemonitor", "env:ci"], "priority": 3, "options": {"thresholds": {"critical": 5, "warning": 3}, "variables": [{"data_source": "cloud_cost", "query": "sum:aws.cost.net.amortized.shared.resources.allocated{aws_product IN (amplify ,athena, backup, bedrock ) } by {aws_product}.rollup(sum, 86400)", "name": "query1", "aggregator": "sum"}], "include_tags": true}}
40+
When the request is sent
41+
Then the response status is 200 OK
42+
3643
@team:DataDog/monitor-app
3744
Scenario: Create a RUM formula and functions monitor returns "OK" response
3845
Given new "CreateMonitor" request

lib/datadog_api_client/inflector.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,9 @@ def overrides
293293
"v1.metrics_query_unit" => "MetricsQueryUnit",
294294
"v1.monitor" => "Monitor",
295295
"v1.monitor_device_id" => "MonitorDeviceID",
296+
"v1.monitor_formula_and_function_cost_aggregator" => "MonitorFormulaAndFunctionCostAggregator",
297+
"v1.monitor_formula_and_function_cost_data_source" => "MonitorFormulaAndFunctionCostDataSource",
298+
"v1.monitor_formula_and_function_cost_query_definition" => "MonitorFormulaAndFunctionCostQueryDefinition",
296299
"v1.monitor_formula_and_function_event_aggregation" => "MonitorFormulaAndFunctionEventAggregation",
297300
"v1.monitor_formula_and_function_event_query_definition" => "MonitorFormulaAndFunctionEventQueryDefinition",
298301
"v1.monitor_formula_and_function_event_query_definition_compute" => "MonitorFormulaAndFunctionEventQueryDefinitionCompute",
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
=begin
2+
#Datadog API V1 Collection
3+
4+
#Collection of all Datadog Public endpoints.
5+
6+
The version of the OpenAPI document: 1.0
7+
8+
Generated by: https://github.com/DataDog/datadog-api-client-ruby/tree/master/.generator
9+
10+
Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
11+
This product includes software developed at Datadog (https://www.datadoghq.com/).
12+
Copyright 2020-Present Datadog, Inc.
13+
14+
=end
15+
16+
require 'date'
17+
require 'time'
18+
19+
module DatadogAPIClient::V1
20+
# Aggregation methods for metric queries.
21+
class MonitorFormulaAndFunctionCostAggregator
22+
include BaseEnumModel
23+
24+
AVG = "avg".freeze
25+
SUM = "sum".freeze
26+
MAX = "max".freeze
27+
MIN = "min".freeze
28+
LAST = "last".freeze
29+
AREA = "area".freeze
30+
L2NORM = "l2norm".freeze
31+
PERCENTILE = "percentile".freeze
32+
STDDEV = "stddev".freeze
33+
end
34+
end
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
=begin
2+
#Datadog API V1 Collection
3+
4+
#Collection of all Datadog Public endpoints.
5+
6+
The version of the OpenAPI document: 1.0
7+
8+
Generated by: https://github.com/DataDog/datadog-api-client-ruby/tree/master/.generator
9+
10+
Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
11+
This product includes software developed at Datadog (https://www.datadoghq.com/).
12+
Copyright 2020-Present Datadog, Inc.
13+
14+
=end
15+
16+
require 'date'
17+
require 'time'
18+
19+
module DatadogAPIClient::V1
20+
# Data source for cost queries.
21+
class MonitorFormulaAndFunctionCostDataSource
22+
include BaseEnumModel
23+
24+
METRICS = "metrics".freeze
25+
CLOUD_COST = "cloud_cost".freeze
26+
DATADOG_USAGE = "datadog_usage".freeze
27+
end
28+
end

0 commit comments

Comments
 (0)