Skip to content

Commit 44f2dca

Browse files
api-clients-generation-pipeline[bot]ci.datadog-api-spec
andauthored
Add pagination extension to notebook (#1642)
Co-authored-by: ci.datadog-api-spec <[email protected]>
1 parent 392de36 commit 44f2dca

File tree

7 files changed

+191
-4
lines changed

7 files changed

+191
-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:43.853436",
8-
"spec_repo_commit": "fd65b2e4"
7+
"regenerated": "2023-09-04 09:06:11.821242",
8+
"spec_repo_commit": "a5115137"
99
},
1010
"v2": {
1111
"apigentools_version": "1.6.5",
12-
"regenerated": "2023-09-01 14:18:43.873695",
13-
"spec_repo_commit": "fd65b2e4"
12+
"regenerated": "2023-09-04 09:06:11.834122",
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
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""
2+
Get all notebooks returns "OK" response with pagination
3+
"""
4+
5+
from datadog_api_client import ApiClient, Configuration
6+
from datadog_api_client.v1.api.notebooks_api import NotebooksApi
7+
8+
configuration = Configuration()
9+
with ApiClient(configuration) as api_client:
10+
api_instance = NotebooksApi(api_client)
11+
items = api_instance.list_notebooks_with_pagination(
12+
count=2,
13+
)
14+
for item in items:
15+
print(item)

src/datadog_api_client/v1/api/notebooks_api.py

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,19 @@
33
# Copyright 2019-Present Datadog, Inc.
44
from __future__ import annotations
55

6+
import collections
67
from typing import Any, Dict, Union
78

89
from datadog_api_client.api_client import ApiClient, Endpoint as _Endpoint
910
from datadog_api_client.configuration import Configuration
1011
from datadog_api_client.model_utils import (
12+
set_attribute_from_path,
13+
get_attribute_from_path,
1114
UnsetType,
1215
unset,
1316
)
1417
from datadog_api_client.v1.model.notebooks_response import NotebooksResponse
18+
from datadog_api_client.v1.model.notebooks_response_data import NotebooksResponseData
1519
from datadog_api_client.v1.model.notebook_response import NotebookResponse
1620
from datadog_api_client.v1.model.notebook_create_request import NotebookCreateRequest
1721
from datadog_api_client.v1.model.notebook_update_request import NotebookUpdateRequest
@@ -313,6 +317,91 @@ def list_notebooks(
313317

314318
return self._list_notebooks_endpoint.call_with_http_info(**kwargs)
315319

320+
def list_notebooks_with_pagination(
321+
self,
322+
*,
323+
author_handle: Union[str, UnsetType] = unset,
324+
exclude_author_handle: Union[str, UnsetType] = unset,
325+
start: Union[int, UnsetType] = unset,
326+
count: Union[int, UnsetType] = unset,
327+
sort_field: Union[str, UnsetType] = unset,
328+
sort_dir: Union[str, UnsetType] = unset,
329+
query: Union[str, UnsetType] = unset,
330+
include_cells: Union[bool, UnsetType] = unset,
331+
is_template: Union[bool, UnsetType] = unset,
332+
type: Union[str, UnsetType] = unset,
333+
) -> collections.abc.Iterable[NotebooksResponseData]:
334+
"""Get all notebooks.
335+
336+
Provide a paginated version of :meth:`list_notebooks`, returning all items.
337+
338+
:param author_handle: Return notebooks created by the given ``author_handle``.
339+
:type author_handle: str, optional
340+
:param exclude_author_handle: Return notebooks not created by the given ``author_handle``.
341+
:type exclude_author_handle: str, optional
342+
:param start: The index of the first notebook you want returned.
343+
:type start: int, optional
344+
:param count: The number of notebooks to be returned.
345+
:type count: int, optional
346+
:param sort_field: Sort by field ``modified`` , ``name`` , or ``created``.
347+
:type sort_field: str, optional
348+
:param sort_dir: Sort by direction ``asc`` or ``desc``.
349+
:type sort_dir: str, optional
350+
:param query: Return only notebooks with ``query`` string in notebook name or author handle.
351+
:type query: str, optional
352+
:param include_cells: Value of ``false`` excludes the ``cells`` and global ``time`` for each notebook.
353+
:type include_cells: bool, optional
354+
:param is_template: True value returns only template notebooks. Default is false (returns only non-template notebooks).
355+
:type is_template: bool, optional
356+
:param type: If type is provided, returns only notebooks with that metadata type. Default does not have type filtering.
357+
:type type: str, optional
358+
359+
:return: A generator of paginated results.
360+
:rtype: collections.abc.Iterable[NotebooksResponseData]
361+
"""
362+
kwargs: Dict[str, Any] = {}
363+
if author_handle is not unset:
364+
kwargs["author_handle"] = author_handle
365+
366+
if exclude_author_handle is not unset:
367+
kwargs["exclude_author_handle"] = exclude_author_handle
368+
369+
if start is not unset:
370+
kwargs["start"] = start
371+
372+
if count is not unset:
373+
kwargs["count"] = count
374+
375+
if sort_field is not unset:
376+
kwargs["sort_field"] = sort_field
377+
378+
if sort_dir is not unset:
379+
kwargs["sort_dir"] = sort_dir
380+
381+
if query is not unset:
382+
kwargs["query"] = query
383+
384+
if include_cells is not unset:
385+
kwargs["include_cells"] = include_cells
386+
387+
if is_template is not unset:
388+
kwargs["is_template"] = is_template
389+
390+
if type is not unset:
391+
kwargs["type"] = type
392+
393+
local_page_size = get_attribute_from_path(kwargs, "count", 100)
394+
endpoint = self._list_notebooks_endpoint
395+
set_attribute_from_path(kwargs, "count", local_page_size, endpoint.params_map)
396+
pagination = {
397+
"limit_value": local_page_size,
398+
"results_path": "data",
399+
"page_offset_param": "start",
400+
"endpoint": endpoint,
401+
"kwargs": kwargs,
402+
}
403+
return endpoint.call_with_http_info_paginated(pagination)
404+
316405
def update_notebook(
317406
self,
318407
notebook_id: int,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2023-08-31T09:47:14.068Z
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
interactions:
2+
- request:
3+
body: null
4+
headers:
5+
accept:
6+
- application/json
7+
method: GET
8+
uri: https://api.datadoghq.com/api/v1/notebooks?count=2
9+
response:
10+
body:
11+
string: '{"data":[{"type":"notebooks","id":4758632,"attributes":{"name":"PCF
12+
Container Usage Attribution","cells":[{"type":"notebook_cells","id":"jod8dstf","attributes":{"split_by":{"tags":[],"keys":[]},"definition":{"title":"Count
13+
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}
14+
by {app_name,bosh_id}","aggregator":"avg"}]}]},"graph_size":"m","time":null}},{"type":"notebook_cells","id":"0t3xetbt","attributes":{"definition":{"type":"markdown","text":"This
15+
displays the count of containers per `troux_uuid` (`bosh_id`) and `container_deployment_guid`
16+
(`app_name`)"}}},{"type":"notebook_cells","id":"7lxv9snf","attributes":{"definition":{"title":"Percentage
17+
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}
18+
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
19+
displays the count of containers per\u00a0`troux_uuid` (`bosh_id`)\u00a0and\u00a0`container_deployment_guid`
20+
(`app_name`) as percentages of total containers\n"}}},{"type":"notebook_cells","id":"fcid5x88","attributes":{"split_by":{"tags":[],"keys":[]},"definition":{"title":"Number
21+
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
22+
filtering by the template variable `container_deployment_guid`, this value
23+
represents the number of VMs (or `troux_uuid`s) that `container_deployment_guid`
24+
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}
25+
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
26+
Witt","handle":"[email protected]","email":"[email protected]","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
27+
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
28+
Witt","handle":"[email protected]","email":"[email protected]","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}}}
29+
30+
'
31+
headers:
32+
content-type:
33+
- application/json
34+
status:
35+
code: 200
36+
message: OK
37+
- request:
38+
body: null
39+
headers:
40+
accept:
41+
- application/json
42+
method: GET
43+
uri: https://api.datadoghq.com/api/v1/notebooks?count=2&start=2
44+
response:
45+
body:
46+
string: '{"data":[{"type":"notebooks","id":4745953,"attributes":{"name":"PCF
47+
Container Usage Attribution","cells":[{"type":"notebook_cells","id":"bqyp7v5p","attributes":{"definition":{"title":"Count
48+
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}
49+
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
50+
displays the count of containers per `troux_uuid` (`bosh_id`) and `container_deployment_guid`
51+
(`app_name`)"}}},{"type":"notebook_cells","id":"vq0zsiia","attributes":{"definition":{"title":"Percentage
52+
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}
53+
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
54+
displays the count of containers per\u00a0`troux_uuid` (`bosh_id`)\u00a0and\u00a0`container_deployment_guid`
55+
(`app_name`) as percentages of total containers\n"}}},{"type":"notebook_cells","id":"m2dcz3jo","attributes":{"definition":{"title":"Number
56+
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
57+
filtering by the template variable `container_deployment_guid`, this value
58+
represents the number of VMs (or `troux_uuid`s) that `container_deployment_guid`
59+
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
60+
Witt","handle":"[email protected]","email":"[email protected]","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}}}
61+
62+
'
63+
headers:
64+
content-type:
65+
- application/json
66+
status:
67+
code: 200
68+
message: OK
69+
version: 1

tests/v1/features/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

0 commit comments

Comments
 (0)