Skip to content

Commit 57f83df

Browse files
api-clients-generation-pipeline[bot]ci.datadog-api-spec
andauthored
Add formula and function slo query to dash widgets (#1145)
Co-authored-by: ci.datadog-api-spec <[email protected]>
1 parent c82b157 commit 57f83df

File tree

14 files changed

+560
-4
lines changed

14 files changed

+560
-4
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.4",
7-
"regenerated": "2023-05-17 14:44:41.288610",
8-
"spec_repo_commit": "f8bfb8c1"
7+
"regenerated": "2023-05-17 20:58:15.183994",
8+
"spec_repo_commit": "d8186149"
99
},
1010
"v2": {
1111
"apigentools_version": "1.6.4",
12-
"regenerated": "2023-05-17 14:44:41.301361",
13-
"spec_repo_commit": "f8bfb8c1"
12+
"regenerated": "2023-05-17 20:58:15.204157",
13+
"spec_repo_commit": "d8186149"
1414
}
1515
}
1616
}

.generator/schemas/v1/openapi.yaml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2728,6 +2728,7 @@ components:
27282728
- $ref: '#/components/schemas/FormulaAndFunctionProcessQueryDefinition'
27292729
- $ref: '#/components/schemas/FormulaAndFunctionApmDependencyStatsQueryDefinition'
27302730
- $ref: '#/components/schemas/FormulaAndFunctionApmResourceStatsQueryDefinition'
2731+
- $ref: '#/components/schemas/FormulaAndFunctionSLOQueryDefinition'
27312732
type: object
27322733
FormulaAndFunctionResponseFormat:
27332734
description: Timeseries or Scalar response.
@@ -2739,6 +2740,81 @@ components:
27392740
x-enum-varnames:
27402741
- TIMESERIES
27412742
- SCALAR
2743+
FormulaAndFunctionSLODataSource:
2744+
description: Data source for SLO measures queries.
2745+
enum:
2746+
- slo
2747+
example: slo
2748+
type: string
2749+
x-enum-varnames:
2750+
- SLO
2751+
FormulaAndFunctionSLOGroupMode:
2752+
description: Group mode to query measures.
2753+
enum:
2754+
- overall
2755+
- components
2756+
example: overall
2757+
type: string
2758+
x-enum-varnames:
2759+
- OVERALL
2760+
- COMPONENTS
2761+
FormulaAndFunctionSLOMeasure:
2762+
description: SLO measures queries.
2763+
enum:
2764+
- good_events
2765+
- bad_events
2766+
- slo_status
2767+
- error_budget_remaining
2768+
- burn_rate
2769+
- error_budget_burndown
2770+
example: slo_status
2771+
type: string
2772+
x-enum-varnames:
2773+
- GOOD_EVENTS
2774+
- BAD_EVENTS
2775+
- SLO_STATUS
2776+
- ERROR_BUDGET_REMAINING
2777+
- BURN_RATE
2778+
- ERROR_BUDGET_BURNDOWN
2779+
FormulaAndFunctionSLOQueryDefinition:
2780+
description: A formula and functions metrics query.
2781+
example:
2782+
data_source: slo
2783+
group_mode: overall
2784+
measure: good_events
2785+
name: my_slo
2786+
slo_id: '12345678910'
2787+
slo_query_type: metric
2788+
properties:
2789+
data_source:
2790+
$ref: '#/components/schemas/FormulaAndFunctionSLODataSource'
2791+
group_mode:
2792+
$ref: '#/components/schemas/FormulaAndFunctionSLOGroupMode'
2793+
measure:
2794+
$ref: '#/components/schemas/FormulaAndFunctionSLOMeasure'
2795+
name:
2796+
description: Name of the query for use in formulas.
2797+
example: my_slo
2798+
type: string
2799+
slo_id:
2800+
description: ID of an SLO to query measures.
2801+
example: '12345678910'
2802+
type: string
2803+
slo_query_type:
2804+
$ref: '#/components/schemas/FormulaAndFunctionSLOQueryType'
2805+
required:
2806+
- data_source
2807+
- slo_id
2808+
- measure
2809+
type: object
2810+
FormulaAndFunctionSLOQueryType:
2811+
description: Name of the query for use in formulas.
2812+
enum:
2813+
- metric
2814+
example: metric
2815+
type: string
2816+
x-enum-varnames:
2817+
- METRIC
27422818
FreeTextWidgetDefinition:
27432819
description: Free text is a widget that allows you to add headings to your screenboard.
27442820
Commonly used to state the overall purpose of the dashboard. Only available
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"2023-05-16T22:06:53.853Z"
Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
{
2+
"log": {
3+
"_recordingName": "Dashboards/Create a new dashboard with a change widget using formulas and functions slo query",
4+
"creator": {
5+
"comment": "persister:fs",
6+
"name": "Polly.JS",
7+
"version": "6.0.5"
8+
},
9+
"entries": [
10+
{
11+
"_id": "561c5e1d53e3cde4dbbbed6e66af81d3",
12+
"_order": 0,
13+
"cache": {},
14+
"request": {
15+
"bodySize": 309,
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": 547,
30+
"httpVersion": "HTTP/1.1",
31+
"method": "POST",
32+
"postData": {
33+
"mimeType": "application/json",
34+
"params": [],
35+
"text": "{\"name\":\"Test-Create_a_new_dashboard_with_a_change_widget_using_formulas_and_functions_slo_query-1684274813\",\"query\":{\"denominator\":\"sum:httpservice.hits{!code:3xx}.as_count()\",\"numerator\":\"sum:httpservice.hits{code:2xx}.as_count()\"},\"thresholds\":[{\"target\":95,\"timeframe\":\"7d\",\"warning\":98}],\"type\":\"metric\"}"
36+
},
37+
"queryString": [],
38+
"url": "https://api.datadoghq.com/api/v1/slo"
39+
},
40+
"response": {
41+
"bodySize": 676,
42+
"content": {
43+
"mimeType": "application/json",
44+
"size": 676,
45+
"text": "{\"data\":[{\"id\":\"1c7cc520f98356d6b79adb1f8dbdef60\",\"name\":\"Test-Create_a_new_dashboard_with_a_change_widget_using_formulas_and_functions_slo_query-1684274813\",\"tags\":[],\"monitor_tags\":[],\"thresholds\":[{\"timeframe\":\"7d\",\"target\":95.0,\"target_display\":\"95.\",\"warning\":98.0,\"warning_display\":\"98.\"}],\"type\":\"metric\",\"type_id\":1,\"description\":\"\",\"timeframe\":\"7d\",\"warning_threshold\":98,\"target_threshold\":95,\"query\":{\"denominator\":\"sum:httpservice.hits{!code:3xx}.as_count()\",\"numerator\":\"sum:httpservice.hits{code:2xx}.as_count()\"},\"creator\":{\"name\":null,\"handle\":\"[email protected]\",\"email\":\"[email protected]\"},\"created_at\":1684274814,\"modified_at\":1684274814}],\"error\":null}\n"
46+
},
47+
"cookies": [],
48+
"headers": [
49+
{
50+
"name": "content-type",
51+
"value": "application/json"
52+
}
53+
],
54+
"headersSize": 645,
55+
"httpVersion": "HTTP/1.1",
56+
"redirectURL": "",
57+
"status": 200,
58+
"statusText": "OK"
59+
},
60+
"startedDateTime": "2023-05-16T22:06:53.868Z",
61+
"time": 283
62+
},
63+
{
64+
"_id": "ccbdcca4ee0e571d3ed520f17d875ff4",
65+
"_order": 0,
66+
"cache": {},
67+
"request": {
68+
"bodySize": 643,
69+
"cookies": [],
70+
"headers": [
71+
{
72+
"_fromType": "array",
73+
"name": "accept",
74+
"value": "application/json"
75+
},
76+
{
77+
"_fromType": "array",
78+
"name": "content-type",
79+
"value": "application/json"
80+
}
81+
],
82+
"headersSize": 558,
83+
"httpVersion": "HTTP/1.1",
84+
"method": "POST",
85+
"postData": {
86+
"mimeType": "application/json",
87+
"params": [],
88+
"text": "{\"layout_type\":\"ordered\",\"title\":\"Test-Create_a_new_dashboard_with_a_change_widget_using_formulas_and_functions_slo_query-1684274813\",\"widgets\":[{\"definition\":{\"requests\":[{\"change_type\":\"absolute\",\"formulas\":[{\"formula\":\"hour_before(query1)\"},{\"formula\":\"query1\"}],\"increase_good\":true,\"order_by\":\"change\",\"order_dir\":\"asc\",\"queries\":[{\"data_source\":\"slo\",\"group_mode\":\"overall\",\"measure\":\"slo_status\",\"name\":\"query1\",\"slo_id\":\"1c7cc520f98356d6b79adb1f8dbdef60\",\"slo_query_type\":\"metric\"}],\"response_format\":\"scalar\"}],\"time\":{},\"title\":\"\",\"title_align\":\"left\",\"title_size\":\"16\",\"type\":\"change\"},\"layout\":{\"height\":2,\"width\":4,\"x\":0,\"y\":0}}]}"
89+
},
90+
"queryString": [],
91+
"url": "https://api.datadoghq.com/api/v1/dashboard"
92+
},
93+
"response": {
94+
"bodySize": 1057,
95+
"content": {
96+
"mimeType": "application/json",
97+
"size": 1057,
98+
"text": "{\"id\":\"8kt-y74-2i3\",\"title\":\"Test-Create_a_new_dashboard_with_a_change_widget_using_formulas_and_functions_slo_query-1684274813\",\"description\":null,\"author_handle\":\"[email protected]\",\"author_name\":null,\"layout_type\":\"ordered\",\"url\":\"/dashboard/8kt-y74-2i3/test-createanewdashboardwithachangewidgetusingformulasandfunctionssloquery-16842\",\"is_read_only\":false,\"template_variables\":null,\"widgets\":[{\"definition\":{\"requests\":[{\"change_type\":\"absolute\",\"formulas\":[{\"formula\":\"hour_before(query1)\"},{\"formula\":\"query1\"}],\"increase_good\":true,\"order_by\":\"change\",\"order_dir\":\"asc\",\"queries\":[{\"data_source\":\"slo\",\"group_mode\":\"overall\",\"measure\":\"slo_status\",\"name\":\"query1\",\"slo_id\":\"1c7cc520f98356d6b79adb1f8dbdef60\",\"slo_query_type\":\"metric\"}],\"response_format\":\"scalar\"}],\"time\":{},\"title\":\"\",\"title_align\":\"left\",\"title_size\":\"16\",\"type\":\"change\"},\"layout\":{\"height\":2,\"width\":4,\"x\":0,\"y\":0},\"id\":8047848064178828}],\"notify_list\":null,\"created_at\":\"2023-05-16T22:06:54.344881+00:00\",\"modified_at\":\"2023-05-16T22:06:54.344881+00:00\",\"restricted_roles\":[]}\n"
99+
},
100+
"cookies": [],
101+
"headers": [
102+
{
103+
"name": "content-type",
104+
"value": "application/json"
105+
}
106+
],
107+
"headersSize": 518,
108+
"httpVersion": "HTTP/1.1",
109+
"redirectURL": "",
110+
"status": 200,
111+
"statusText": "OK"
112+
},
113+
"startedDateTime": "2023-05-16T22:06:54.162Z",
114+
"time": 232
115+
},
116+
{
117+
"_id": "5734ef8dc2b0db9c9381810e619f85cd",
118+
"_order": 0,
119+
"cache": {},
120+
"request": {
121+
"bodySize": 0,
122+
"cookies": [],
123+
"headers": [
124+
{
125+
"_fromType": "array",
126+
"name": "accept",
127+
"value": "application/json"
128+
}
129+
],
130+
"headersSize": 519,
131+
"httpVersion": "HTTP/1.1",
132+
"method": "DELETE",
133+
"queryString": [],
134+
"url": "https://api.datadoghq.com/api/v1/dashboard/8kt-y74-2i3"
135+
},
136+
"response": {
137+
"bodySize": 39,
138+
"content": {
139+
"mimeType": "application/json",
140+
"size": 39,
141+
"text": "{\"deleted_dashboard_id\":\"8kt-y74-2i3\"}\n"
142+
},
143+
"cookies": [],
144+
"headers": [
145+
{
146+
"name": "content-type",
147+
"value": "application/json"
148+
}
149+
],
150+
"headersSize": 516,
151+
"httpVersion": "HTTP/1.1",
152+
"redirectURL": "",
153+
"status": 200,
154+
"statusText": "OK"
155+
},
156+
"startedDateTime": "2023-05-16T22:06:54.406Z",
157+
"time": 234
158+
},
159+
{
160+
"_id": "9fef392995a3e9035947add8232beaaa",
161+
"_order": 0,
162+
"cache": {},
163+
"request": {
164+
"bodySize": 0,
165+
"cookies": [],
166+
"headers": [
167+
{
168+
"_fromType": "array",
169+
"name": "accept",
170+
"value": "application/json"
171+
}
172+
],
173+
"headersSize": 529,
174+
"httpVersion": "HTTP/1.1",
175+
"method": "DELETE",
176+
"queryString": [],
177+
"url": "https://api.datadoghq.com/api/v1/slo/1c7cc520f98356d6b79adb1f8dbdef60"
178+
},
179+
"response": {
180+
"bodySize": 59,
181+
"content": {
182+
"mimeType": "application/json",
183+
"size": 59,
184+
"text": "{\"data\":[\"1c7cc520f98356d6b79adb1f8dbdef60\"],\"error\":null}\n"
185+
},
186+
"cookies": [],
187+
"headers": [
188+
{
189+
"name": "content-type",
190+
"value": "application/json"
191+
}
192+
],
193+
"headersSize": 643,
194+
"httpVersion": "HTTP/1.1",
195+
"redirectURL": "",
196+
"status": 200,
197+
"statusText": "OK"
198+
},
199+
"startedDateTime": "2023-05-16T22:06:54.645Z",
200+
"time": 272
201+
}
202+
],
203+
"pages": [],
204+
"version": "1.2"
205+
}
206+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/**
2+
* Create a new dashboard with a change widget using formulas and functions slo query
3+
*/
4+
5+
import { client, v1 } from "@datadog/datadog-api-client";
6+
7+
const configuration = client.createConfiguration();
8+
const apiInstance = new v1.DashboardsApi(configuration);
9+
10+
// there is a valid "slo" in the system
11+
const SLO_DATA_0_ID = process.env.SLO_DATA_0_ID as string;
12+
13+
const params: v1.DashboardsApiCreateDashboardRequest = {
14+
body: {
15+
title: "Example-Dashboard",
16+
widgets: [
17+
{
18+
definition: {
19+
title: "",
20+
titleSize: "16",
21+
titleAlign: "left",
22+
time: {},
23+
type: "change",
24+
requests: [
25+
{
26+
formulas: [
27+
{
28+
formula: "hour_before(query1)",
29+
},
30+
{
31+
formula: "query1",
32+
},
33+
],
34+
queries: [
35+
{
36+
name: "query1",
37+
dataSource: "slo",
38+
sloId: SLO_DATA_0_ID,
39+
measure: "slo_status",
40+
groupMode: "overall",
41+
sloQueryType: "metric",
42+
},
43+
],
44+
responseFormat: "scalar",
45+
orderBy: "change",
46+
changeType: "absolute",
47+
increaseGood: true,
48+
orderDir: "asc",
49+
},
50+
],
51+
},
52+
layout: {
53+
x: 0,
54+
y: 0,
55+
width: 4,
56+
height: 2,
57+
},
58+
},
59+
],
60+
layoutType: "ordered",
61+
},
62+
};
63+
64+
apiInstance
65+
.createDashboard(params)
66+
.then((data: v1.Dashboard) => {
67+
console.log(
68+
"API called successfully. Returned data: " + JSON.stringify(data)
69+
);
70+
})
71+
.catch((error: any) => console.error(error));

0 commit comments

Comments
 (0)