Skip to content

Commit 15a3969

Browse files
api-clients-generation-pipeline[bot]ci.datadog-api-spec
and
ci.datadog-api-spec
authored
Add pagination extension to notebook (#1302)
Co-authored-by: ci.datadog-api-spec <packages@datadoghq.com>
1 parent 2e426c9 commit 15a3969

File tree

7 files changed

+207
-4
lines changed

7 files changed

+207
-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.5",
7-
"regenerated": "2023-09-01 14:18:46.087912",
8-
"spec_repo_commit": "fd65b2e4"
7+
"regenerated": "2023-09-04 09:06:17.163397",
8+
"spec_repo_commit": "a5115137"
99
},
1010
"v2": {
1111
"apigentools_version": "1.6.5",
12-
"regenerated": "2023-09-01 14:18:46.108524",
13-
"spec_repo_commit": "fd65b2e4"
12+
"regenerated": "2023-09-04 09:06:17.176462",
13+
"spec_repo_commit": "a5115137"
1414
}
1515
}
1616
}

.generator/schemas/v1/openapi.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26095,6 +26095,7 @@ paths:
2609526095
name: count
2609626096
required: false
2609726097
schema:
26098+
default: 100
2609826099
example: 5
2609926100
format: int64
2610026101
type: integer
@@ -26179,6 +26180,10 @@ paths:
2617926180
summary: Get all notebooks
2618026181
tags:
2618126182
- Notebooks
26183+
x-pagination:
26184+
limitParam: count
26185+
pageOffsetParam: start
26186+
resultsPath: data
2618226187
post:
2618326188
description: Create a notebook using the specified options.
2618426189
operationId: CreateNotebook
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"2023-08-31T09:47:14.068Z"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
{
2+
"log": {
3+
"_recordingName": "Notebooks/Get all notebooks returns \"OK\" response with pagination",
4+
"creator": {
5+
"comment": "persister:fs",
6+
"name": "Polly.JS",
7+
"version": "6.0.5"
8+
},
9+
"entries": [
10+
{
11+
"_id": "8411da1c939233417092ea377d2379ef",
12+
"_order": 0,
13+
"cache": {},
14+
"request": {
15+
"bodySize": 0,
16+
"cookies": [],
17+
"headers": [
18+
{
19+
"_fromType": "array",
20+
"name": "accept",
21+
"value": "application/json"
22+
}
23+
],
24+
"headersSize": 511,
25+
"httpVersion": "HTTP/1.1",
26+
"method": "GET",
27+
"queryString": [
28+
{
29+
"name": "count",
30+
"value": "2"
31+
}
32+
],
33+
"url": "https://api.datadoghq.com/api/v1/notebooks?count=2"
34+
},
35+
"response": {
36+
"bodySize": 4626,
37+
"content": {
38+
"mimeType": "application/json",
39+
"size": 4626,
40+
"text": "{\"data\":[{\"type\":\"notebooks\",\"id\":4758632,\"attributes\":{\"name\":\"PCF Container Usage Attribution\",\"cells\":[{\"type\":\"notebook_cells\",\"id\":\"jod8dstf\",\"attributes\":{\"split_by\":{\"tags\":[],\"keys\":[]},\"definition\":{\"title\":\"Count of containers\",\"type\":\"query_table\",\"requests\":[{\"response_format\":\"scalar\",\"formulas\":[{\"alias\":\"containers\",\"formula\":\"query1\",\"limit\":{\"count\":10000,\"order\":\"desc\"}}],\"queries\":[{\"name\":\"query1\",\"data_source\":\"metrics\",\"query\":\"avg:cloudfoundry.nozzle.app.instances{$container_deployement_guid,$troux_uuid} by {app_name,bosh_id}\",\"aggregator\":\"avg\"}]}]},\"graph_size\":\"m\",\"time\":null}},{\"type\":\"notebook_cells\",\"id\":\"0t3xetbt\",\"attributes\":{\"definition\":{\"type\":\"markdown\",\"text\":\"This displays the count of containers per `troux_uuid` (`bosh_id`) and `container_deployment_guid` (`app_name`)\"}}},{\"type\":\"notebook_cells\",\"id\":\"7lxv9snf\",\"attributes\":{\"definition\":{\"title\":\"Percentage breakdown of containers on VMs\",\"requests\":[{\"response_format\":\"scalar\",\"formulas\":[{\"formula\":\"query1\",\"limit\":{\"order\":\"desc\"}}],\"queries\":[{\"query\":\"avg:cloudfoundry.nozzle.app.instances{$troux_uuid,$container_deployement_guid} by {app_name,bosh_id}.rollup(avg, 3600)\",\"data_source\":\"metrics\",\"name\":\"query1\",\"aggregator\":\"sum\"}],\"style\":{\"palette\":\"datadog16\"}}],\"type\":\"sunburst\",\"legend\":{\"type\":\"automatic\"}},\"time\":null}},{\"type\":\"notebook_cells\",\"id\":\"uhwq9m18\",\"attributes\":{\"definition\":{\"type\":\"markdown\",\"text\":\"This displays the count of containers per\\u00a0`troux_uuid` (`bosh_id`)\\u00a0and\\u00a0`container_deployment_guid` (`app_name`) as percentages of total containers\\n\"}}},{\"type\":\"notebook_cells\",\"id\":\"fcid5x88\",\"attributes\":{\"split_by\":{\"tags\":[],\"keys\":[]},\"definition\":{\"title\":\"Number of VMs per container_deployment_guid\",\"type\":\"query_value\",\"requests\":[{\"response_format\":\"scalar\",\"queries\":[{\"name\":\"query1\",\"data_source\":\"metrics\",\"query\":\"avg:cloudfoundry.nozzle.app.instances{$troux_uuid,$container_deployement_guid}\",\"aggregator\":\"avg\"}],\"formulas\":[{\"formula\":\"count_nonzero(query1)\",\"alias\":\"VMs\"}]}],\"autoscale\":true,\"precision\":2},\"graph_size\":\"xs\",\"time\":null}},{\"type\":\"notebook_cells\",\"id\":\"7qmg68gc\",\"attributes\":{\"definition\":{\"type\":\"markdown\",\"text\":\"When filtering by the template variable `container_deployment_guid`, this value represents the number of VMs (or `troux_uuid`s) that `container_deployment_guid` runs on \"}}},{\"type\":\"notebook_cells\",\"id\":\"h75xo4j5\",\"attributes\":{\"split_by\":{\"tags\":[],\"keys\":[]},\"definition\":{\"type\":\"query_table\",\"requests\":[{\"queries\":[{\"data_source\":\"metrics\",\"name\":\"query1\",\"query\":\"avg:system.cpu.user{$troux_uuid,$container_deployement_guid} by {bosh_id,application_name}.rollup(avg, 3600)\",\"aggregator\":\"avg\"}],\"formulas\":[{\"conditional_formats\":[],\"cell_display_mode\":\"bar\",\"formula\":\"query1\",\"limit\":{\"count\":500,\"order\":\"desc\"}}],\"response_format\":\"scalar\"}],\"has_search_bar\":\"auto\"},\"time\":null}}],\"time\":{\"live_span\":\"2d\"},\"metadata\":{\"take_snapshots\":false,\"is_template\":false,\"is_favorite\":false,\"type\":null},\"template_variables\":[{\"name\":\"container_deployement_guid\",\"prefix\":\"app_name\",\"available_values\":[],\"default\":\"*\"},{\"name\":\"troux_uuid\",\"prefix\":\"bosh_id\",\"available_values\":[],\"default\":\"*\"}],\"status\":\"published\",\"modified\":\"2023-02-27T17:53:59.623647+00:00\",\"created\":\"2023-02-15T18:12:35.189588+00:00\",\"author\":{\"name\":\"Sarah Witt\",\"handle\":\"sarah.witt@datadoghq.com\",\"email\":\"sarah.witt@datadoghq.com\",\"icon\":\"https://secure.gravatar.com/avatar/7f710a0bcefa8df8d47bfcba79f69a40?s=48&d=retro\",\"title\":null,\"verified\":true,\"disabled\":false,\"status\":\"Active\"}}},{\"type\":\"notebooks\",\"id\":4823614,\"attributes\":{\"name\":\"Sarah Feb 22 2023 11:04\",\"cells\":[{\"type\":\"notebook_cells\",\"id\":\"dnulkt1p\",\"attributes\":{\"split_by\":{\"tags\":[],\"keys\":[]},\"definition\":{\"show_legend\":true,\"type\":\"timeseries\",\"requests\":[{\"response_format\":\"timeseries\",\"queries\":[{\"name\":\"query1\",\"data_source\":\"metrics\",\"query\":\"avg:system.cpu.user{*}\"}],\"style\":{\"palette\":\"dog_classic\",\"line_type\":\"solid\",\"line_width\":\"normal\"},\"display_type\":\"line\"}]},\"time\":null}}],\"time\":{\"live_span\":\"1h\"},\"metadata\":{\"take_snapshots\":false,\"is_template\":false,\"is_favorite\":false,\"type\":null},\"template_variables\":[],\"status\":\"published\",\"modified\":\"2023-02-22T16:04:51.449049+00:00\",\"created\":\"2023-02-22T16:04:51.449049+00:00\",\"author\":{\"name\":\"Sarah Witt\",\"handle\":\"sarah.witt@datadoghq.com\",\"email\":\"sarah.witt@datadoghq.com\",\"icon\":\"https://secure.gravatar.com/avatar/7f710a0bcefa8df8d47bfcba79f69a40?s=48&d=retro\",\"title\":null,\"verified\":true,\"disabled\":false,\"status\":\"Active\"}}}],\"meta\":{\"page\":{\"total_count\":158,\"total_filtered_count\":2}}}\n"
41+
},
42+
"cookies": [],
43+
"headers": [
44+
{
45+
"name": "content-type",
46+
"value": "application/json"
47+
}
48+
],
49+
"headersSize": 662,
50+
"httpVersion": "HTTP/1.1",
51+
"redirectURL": "",
52+
"status": 200,
53+
"statusText": "OK"
54+
},
55+
"startedDateTime": "2023-08-31T09:47:14.078Z",
56+
"time": 456
57+
},
58+
{
59+
"_id": "457a2edf5653169d4f94900f94004dfb",
60+
"_order": 0,
61+
"cache": {},
62+
"request": {
63+
"bodySize": 0,
64+
"cookies": [],
65+
"headers": [
66+
{
67+
"_fromType": "array",
68+
"name": "accept",
69+
"value": "application/json"
70+
}
71+
],
72+
"headersSize": 519,
73+
"httpVersion": "HTTP/1.1",
74+
"method": "GET",
75+
"queryString": [
76+
{
77+
"name": "count",
78+
"value": "2"
79+
},
80+
{
81+
"name": "start",
82+
"value": "2"
83+
}
84+
],
85+
"url": "https://api.datadoghq.com/api/v1/notebooks?count=2&start=2"
86+
},
87+
"response": {
88+
"bodySize": 4831,
89+
"content": {
90+
"mimeType": "application/json",
91+
"size": 4831,
92+
"text": "{\"data\":[{\"type\":\"notebooks\",\"id\":4745953,\"attributes\":{\"name\":\"PCF Container Usage Attribution\",\"cells\":[{\"type\":\"notebook_cells\",\"id\":\"bqyp7v5p\",\"attributes\":{\"definition\":{\"title\":\"Count of containers\",\"type\":\"query_table\",\"requests\":[{\"response_format\":\"scalar\",\"formulas\":[{\"alias\":\"containers\",\"formula\":\"query1\",\"limit\":{\"count\":500,\"order\":\"desc\"}}],\"queries\":[{\"name\":\"query1\",\"data_source\":\"metrics\",\"query\":\"avg:cloudfoundry.nozzle.app.instances{$troux_uuid,$container_deployment_guid} by {app_name,bosh_id}.rollup(avg, 3600)\",\"aggregator\":\"sum\"}]}]},\"time\":null,\"split_by\":{\"keys\":[],\"tags\":[]},\"graph_size\":\"m\"}},{\"type\":\"notebook_cells\",\"id\":\"svgafvhk\",\"attributes\":{\"definition\":{\"type\":\"markdown\",\"text\":\"This displays the count of containers per `troux_uuid` (`bosh_id`) and `container_deployment_guid` (`app_name`)\"}}},{\"type\":\"notebook_cells\",\"id\":\"vq0zsiia\",\"attributes\":{\"definition\":{\"title\":\"Percentage breakdown of containers on VMs\",\"requests\":[{\"response_format\":\"scalar\",\"formulas\":[{\"formula\":\"query1\",\"limit\":{\"order\":\"desc\"}}],\"queries\":[{\"query\":\"avg:cloudfoundry.nozzle.app.instances{$troux_uuid,$container_deployment_guid} by {app_name,bosh_id}.rollup(avg, 3600)\",\"data_source\":\"metrics\",\"name\":\"query1\",\"aggregator\":\"sum\"}],\"style\":{\"palette\":\"datadog16\"}}],\"type\":\"sunburst\",\"legend\":{\"type\":\"automatic\"}},\"time\":null}},{\"type\":\"notebook_cells\",\"id\":\"oldqd75v\",\"attributes\":{\"definition\":{\"type\":\"markdown\",\"text\":\"This displays the count of containers per\\u00a0`troux_uuid` (`bosh_id`)\\u00a0and\\u00a0`container_deployment_guid` (`app_name`) as percentages of total containers\\n\"}}},{\"type\":\"notebook_cells\",\"id\":\"m2dcz3jo\",\"attributes\":{\"definition\":{\"title\":\"Number of VMs per container_deployment_guid\",\"type\":\"query_value\",\"requests\":[{\"response_format\":\"scalar\",\"queries\":[{\"name\":\"query1\",\"data_source\":\"metrics\",\"query\":\"avg:cloudfoundry.nozzle.app.instances{$troux_uuid,$container_deployment_guid}\",\"aggregator\":\"avg\"}],\"formulas\":[{\"formula\":\"count_nonzero(query1)\",\"alias\":\"VMs\"}]}],\"autoscale\":true,\"precision\":2},\"time\":null,\"split_by\":{\"keys\":[],\"tags\":[]},\"graph_size\":\"xs\"}},{\"type\":\"notebook_cells\",\"id\":\"39crgjxd\",\"attributes\":{\"definition\":{\"type\":\"markdown\",\"text\":\"When filtering by the template variable `container_deployment_guid`, this value represents the number of VMs (or `troux_uuid`s) that `container_deployment_guid` runs on \"}}}],\"time\":{\"live_span\":\"2d\"},\"metadata\":{\"take_snapshots\":false,\"is_template\":false,\"is_favorite\":false,\"type\":null},\"template_variables\":[{\"name\":\"container_deployment_guid\",\"prefix\":\"app_name\",\"available_values\":[],\"default\":\"*\"},{\"name\":\"troux_uuid\",\"prefix\":\"bosh_id\",\"available_values\":[],\"default\":\"*\"}],\"status\":\"published\",\"modified\":\"2023-02-16T17:32:46.774359+00:00\",\"created\":\"2023-02-14T20:04:16.789408+00:00\",\"author\":{\"name\":\"Sarah Witt\",\"handle\":\"sarah.witt@datadoghq.com\",\"email\":\"sarah.witt@datadoghq.com\",\"icon\":\"https://secure.gravatar.com/avatar/7f710a0bcefa8df8d47bfcba79f69a40?s=48&d=retro\",\"title\":null,\"verified\":true,\"disabled\":false,\"status\":\"Active\"}}}],\"meta\":{\"page\":{\"total_count\":158,\"total_filtered_count\":2}}}\n"
93+
},
94+
"cookies": [],
95+
"headers": [
96+
{
97+
"name": "content-type",
98+
"value": "application/json"
99+
}
100+
],
101+
"headersSize": 662,
102+
"httpVersion": "HTTP/1.1",
103+
"redirectURL": "",
104+
"status": 200,
105+
"statusText": "OK"
106+
},
107+
"startedDateTime": "2023-08-31T09:47:14.542Z",
108+
"time": 441
109+
}
110+
],
111+
"pages": [],
112+
"version": "1.2"
113+
}
114+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Get all notebooks returns "OK" response with pagination
3+
*/
4+
5+
import { client, v1 } from "@datadog/datadog-api-client";
6+
7+
const configuration = client.createConfiguration();
8+
const apiInstance = new v1.NotebooksApi(configuration);
9+
10+
const params: v1.NotebooksApiListNotebooksRequest = {
11+
count: 2,
12+
};
13+
14+
(async () => {
15+
try {
16+
for await (const item of apiInstance.listNotebooksWithPagination(params)) {
17+
console.log(item);
18+
}
19+
} catch (error) {
20+
console.error(error);
21+
}
22+
})();

features/v1/notebooks.feature

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ Feature: Notebooks
8686
Then the response status is 200 OK
8787
And the response "data" has item with field "attributes.status" with value "published"
8888

89+
@replay-only @skip-validation @team:DataDog/notebooks @with-pagination
90+
Scenario: Get all notebooks returns "OK" response with pagination
91+
Given new "ListNotebooks" request
92+
And request contains "count" parameter with value 2
93+
When the request with pagination is sent
94+
Then the response status is 200 OK
95+
And the response has 3 items
96+
8997
@generated @skip @team:DataDog/notebooks
9098
Scenario: Update a notebook returns "Bad Request" response
9199
Given new "UpdateNotebook" request

packages/datadog-api-client-v1/apis/NotebooksApi.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { APIErrorResponse } from "../models/APIErrorResponse";
2020
import { NotebookCreateRequest } from "../models/NotebookCreateRequest";
2121
import { NotebookResponse } from "../models/NotebookResponse";
2222
import { NotebooksResponse } from "../models/NotebooksResponse";
23+
import { NotebooksResponseData } from "../models/NotebooksResponseData";
2324
import { NotebookUpdateRequest } from "../models/NotebookUpdateRequest";
2425

2526
export class NotebooksApiRequestFactory extends BaseAPIRequestFactory {
@@ -788,6 +789,58 @@ export class NotebooksApi {
788789
});
789790
}
790791

792+
/**
793+
* Provide a paginated version of listNotebooks returning a generator with all the items.
794+
*/
795+
public async *listNotebooksWithPagination(
796+
param: NotebooksApiListNotebooksRequest = {},
797+
options?: Configuration
798+
): AsyncGenerator<NotebooksResponseData> {
799+
let pageSize = 100;
800+
if (param.count !== undefined) {
801+
pageSize = param.count;
802+
}
803+
param.count = pageSize;
804+
while (true) {
805+
const requestContext = await this.requestFactory.listNotebooks(
806+
param.authorHandle,
807+
param.excludeAuthorHandle,
808+
param.start,
809+
param.count,
810+
param.sortField,
811+
param.sortDir,
812+
param.query,
813+
param.includeCells,
814+
param.isTemplate,
815+
param.type,
816+
options
817+
);
818+
const responseContext = await this.configuration.httpApi.send(
819+
requestContext
820+
);
821+
822+
const response = await this.responseProcessor.listNotebooks(
823+
responseContext
824+
);
825+
const responseData = response.data;
826+
if (responseData === undefined) {
827+
break;
828+
}
829+
const results = responseData;
830+
for (const item of results) {
831+
yield item;
832+
}
833+
if (results.length < pageSize) {
834+
break;
835+
}
836+
if (param.start === undefined) {
837+
param.start = pageSize;
838+
} else {
839+
param.start = param.start + pageSize;
840+
}
841+
}
842+
}
843+
791844
/**
792845
* Update a notebook using the specified ID.
793846
* @param param The request object

0 commit comments

Comments
 (0)