Skip to content

Commit cf15a03

Browse files
api-clients-generation-pipeline[bot]ci.datadog-api-spec
and
ci.datadog-api-spec
authored
Add a cost monitor example (#2007)
Co-authored-by: ci.datadog-api-spec <packages@datadoghq.com>
1 parent 0179b15 commit cf15a03

File tree

12 files changed

+381
-4
lines changed

12 files changed

+381
-4
lines changed

.apigentools-info

+4-4
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:21.654943",
8-
"spec_repo_commit": "617655da"
7+
"regenerated": "2025-01-17 21:41:11.567854",
8+
"spec_repo_commit": "27e609f7"
99
},
1010
"v2": {
1111
"apigentools_version": "1.6.6",
12-
"regenerated": "2025-01-17 21:03:21.670788",
13-
"spec_repo_commit": "617655da"
12+
"regenerated": "2025-01-17 21:41:11.583353",
13+
"spec_repo_commit": "27e609f7"
1414
}
1515
}
1616
}

.generator/schemas/v1/openapi.yaml

+57
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:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"2025-01-17T11:21:26.452Z"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
{
2+
"log": {
3+
"_recordingName": "Monitors/Create a Cost Monitor returns \"OK\" response",
4+
"creator": {
5+
"comment": "persister:fs",
6+
"name": "Polly.JS",
7+
"version": "6.0.5"
8+
},
9+
"entries": [
10+
{
11+
"_id": "d16d3cd4da227a00e7aba69082fd390c",
12+
"_order": 0,
13+
"cache": {},
14+
"request": {
15+
"bodySize": 557,
16+
"cookies": [],
17+
"headers": [
18+
{
19+
"_fromType": "array",
20+
"name": "accept",
21+
"value": "application/json"
22+
},
23+
{
24+
"_fromType": "array",
25+
"name": "content-type",
26+
"value": "application/json"
27+
}
28+
],
29+
"headersSize": 553,
30+
"httpVersion": "HTTP/1.1",
31+
"method": "POST",
32+
"postData": {
33+
"mimeType": "application/json",
34+
"params": [],
35+
"text": "{\"message\":\"some message Notify: @hipchat-channel\",\"name\":\"Example Monitor\",\"options\":{\"include_tags\":true,\"thresholds\":{\"critical\":5,\"warning\":3},\"variables\":[{\"aggregator\":\"sum\",\"data_source\":\"cloud_cost\",\"name\":\"query1\",\"query\":\"sum:aws.cost.net.amortized.shared.resources.allocated{aws_product IN (amplify ,athena, backup, bedrock ) } by {aws_product}.rollup(sum, 86400)\"}]},\"priority\":3,\"query\":\"formula(\\\"exclude_null(query1)\\\").last(\\\"7d\\\").anomaly(direction=\\\"above\\\", threshold=10) >= 5\",\"tags\":[\"test:examplemonitor\",\"env:ci\"],\"type\":\"cost alert\"}"
36+
},
37+
"queryString": [],
38+
"url": "https://api.datadoghq.com/api/v1/monitor"
39+
},
40+
"response": {
41+
"bodySize": 1068,
42+
"content": {
43+
"mimeType": "application/json",
44+
"size": 1068,
45+
"text": "{\"id\":162921056,\"org_id\":321813,\"type\":\"cost alert\",\"name\":\"Example Monitor\",\"message\":\"some message Notify: @hipchat-channel\",\"tags\":[\"test:examplemonitor\",\"env:ci\"],\"query\":\"formula(\\\"exclude_null(query1)\\\").last(\\\"7d\\\").anomaly(direction=\\\"above\\\", threshold=10) >= 5\",\"options\":{\"include_tags\":true,\"thresholds\":{\"critical\":5.0,\"warning\":3.0},\"variables\":[{\"aggregator\":\"sum\",\"data_source\":\"cloud_cost\",\"name\":\"query1\",\"query\":\"sum:aws.cost.net.amortized.shared.resources.allocated{aws_product IN (amplify ,athena, backup, bedrock ) } by {aws_product}.rollup(sum, 86400)\"}],\"notify_no_data\":false,\"notify_audit\":false,\"new_host_delay\":300,\"silenced\":{}},\"multi\":false,\"created_at\":1737112886000,\"created\":\"2025-01-17T11:21:26.560275+00:00\",\"modified\":\"2025-01-17T11:21:26.560275+00:00\",\"deleted\":null,\"priority\":3,\"restricted_roles\":null,\"restriction_policy\":null,\"overall_state_modified\":null,\"overall_state\":\"No Data\",\"creator\":{\"name\":\"CI Account\",\"handle\":\"9919ec9b-ebc7-49ee-8dc8-03626e717cca\",\"email\":\"team-intg-tools-libs-spam@datadoghq.com\",\"id\":2320499}}\n"
46+
},
47+
"cookies": [],
48+
"headers": [
49+
{
50+
"name": "content-type",
51+
"value": "application/json"
52+
}
53+
],
54+
"headersSize": 649,
55+
"httpVersion": "HTTP/1.1",
56+
"redirectURL": "",
57+
"status": 200,
58+
"statusText": "OK"
59+
},
60+
"startedDateTime": "2025-01-17T11:21:26.460Z",
61+
"time": 154
62+
},
63+
{
64+
"_id": "ecb89ccc0ef8ed62f948ecbbf3ec4982",
65+
"_order": 0,
66+
"cache": {},
67+
"request": {
68+
"bodySize": 0,
69+
"cookies": [],
70+
"headers": [
71+
{
72+
"_fromType": "array",
73+
"name": "accept",
74+
"value": "application/json"
75+
}
76+
],
77+
"headersSize": 514,
78+
"httpVersion": "HTTP/1.1",
79+
"method": "DELETE",
80+
"queryString": [],
81+
"url": "https://api.datadoghq.com/api/v1/monitor/162921056"
82+
},
83+
"response": {
84+
"bodySize": 33,
85+
"content": {
86+
"mimeType": "application/json",
87+
"size": 33,
88+
"text": "{\"deleted_monitor_id\":162921056}\n"
89+
},
90+
"cookies": [],
91+
"headers": [
92+
{
93+
"name": "content-type",
94+
"value": "application/json"
95+
}
96+
],
97+
"headersSize": 516,
98+
"httpVersion": "HTTP/1.1",
99+
"redirectURL": "",
100+
"status": 200,
101+
"statusText": "OK"
102+
},
103+
"startedDateTime": "2025-01-17T11:21:26.621Z",
104+
"time": 211
105+
}
106+
],
107+
"pages": [],
108+
"version": "1.2"
109+
}
110+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* Create a Cost Monitor returns "OK" response
3+
*/
4+
5+
import { client, v1 } from "@datadog/datadog-api-client";
6+
7+
const configuration = client.createConfiguration();
8+
const apiInstance = new v1.MonitorsApi(configuration);
9+
10+
const params: v1.MonitorsApiCreateMonitorRequest = {
11+
body: {
12+
name: "Example Monitor",
13+
type: "cost alert",
14+
query: `formula("exclude_null(query1)").last("7d").anomaly(direction="above", threshold=10) >= 5`,
15+
message: "some message Notify: @hipchat-channel",
16+
tags: ["test:examplemonitor", "env:ci"],
17+
priority: 3,
18+
options: {
19+
thresholds: {
20+
critical: 5,
21+
warning: 3,
22+
},
23+
variables: [
24+
{
25+
dataSource: "cloud_cost",
26+
query:
27+
"sum:aws.cost.net.amortized.shared.resources.allocated{aws_product IN (amplify ,athena, backup, bedrock ) } by {aws_product}.rollup(sum, 86400)",
28+
name: "query1",
29+
aggregator: "sum",
30+
},
31+
],
32+
includeTags: true,
33+
},
34+
},
35+
};
36+
37+
apiInstance
38+
.createMonitor(params)
39+
.then((data: v1.Monitor) => {
40+
console.log(
41+
"API called successfully. Returned data: " + JSON.stringify(data)
42+
);
43+
})
44+
.catch((error: any) => console.error(error));

features/v1/monitors.feature

+7
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

packages/datadog-api-client-v1/index.ts

+3
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,9 @@ export { MetricsQueryResponse } from "./models/MetricsQueryResponse";
614614
export { MetricsQueryUnit } from "./models/MetricsQueryUnit";
615615
export { Monitor } from "./models/Monitor";
616616
export { MonitorDeviceID } from "./models/MonitorDeviceID";
617+
export { MonitorFormulaAndFunctionCostAggregator } from "./models/MonitorFormulaAndFunctionCostAggregator";
618+
export { MonitorFormulaAndFunctionCostDataSource } from "./models/MonitorFormulaAndFunctionCostDataSource";
619+
export { MonitorFormulaAndFunctionCostQueryDefinition } from "./models/MonitorFormulaAndFunctionCostQueryDefinition";
617620
export { MonitorFormulaAndFunctionEventAggregation } from "./models/MonitorFormulaAndFunctionEventAggregation";
618621
export { MonitorFormulaAndFunctionEventQueryDefinition } from "./models/MonitorFormulaAndFunctionEventQueryDefinition";
619622
export { MonitorFormulaAndFunctionEventQueryDefinitionCompute } from "./models/MonitorFormulaAndFunctionEventQueryDefinitionCompute";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
3+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
4+
* Copyright 2020-Present Datadog, Inc.
5+
*/
6+
7+
import { UnparsedObject } from "../../datadog-api-client-common/util";
8+
9+
/**
10+
* Aggregation methods for metric queries.
11+
*/
12+
13+
export type MonitorFormulaAndFunctionCostAggregator =
14+
| typeof AVG
15+
| typeof SUM
16+
| typeof MAX
17+
| typeof MIN
18+
| typeof LAST
19+
| typeof AREA
20+
| typeof L2NORM
21+
| typeof PERCENTILE
22+
| typeof STDDEV
23+
| UnparsedObject;
24+
export const AVG = "avg";
25+
export const SUM = "sum";
26+
export const MAX = "max";
27+
export const MIN = "min";
28+
export const LAST = "last";
29+
export const AREA = "area";
30+
export const L2NORM = "l2norm";
31+
export const PERCENTILE = "percentile";
32+
export const STDDEV = "stddev";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
3+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
4+
* Copyright 2020-Present Datadog, Inc.
5+
*/
6+
7+
import { UnparsedObject } from "../../datadog-api-client-common/util";
8+
9+
/**
10+
* Data source for cost queries.
11+
*/
12+
13+
export type MonitorFormulaAndFunctionCostDataSource =
14+
| typeof METRICS
15+
| typeof CLOUD_COST
16+
| typeof DATADOG_USAGE
17+
| UnparsedObject;
18+
export const METRICS = "metrics";
19+
export const CLOUD_COST = "cloud_cost";
20+
export const DATADOG_USAGE = "datadog_usage";

0 commit comments

Comments
 (0)