Skip to content

Commit f9bda90

Browse files
api-clients-generation-pipeline[bot]ci.datadog-api-spec
andauthored
Add pagination extension to SLOs (#1632)
Co-authored-by: ci.datadog-api-spec <[email protected]>
1 parent 5190bed commit f9bda90

File tree

7 files changed

+141
-5
lines changed

7 files changed

+141
-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.5",
7-
"regenerated": "2023-08-28 20:29:20.630970",
8-
"spec_repo_commit": "0fac706f"
7+
"regenerated": "2023-08-30 07:29:22.537461",
8+
"spec_repo_commit": "febdee32"
99
},
1010
"v2": {
1111
"apigentools_version": "1.6.5",
12-
"regenerated": "2023-08-28 20:29:20.644178",
13-
"spec_repo_commit": "0fac706f"
12+
"regenerated": "2023-08-30 07:29:22.557428",
13+
"spec_repo_commit": "febdee32"
1414
}
1515
}
1616
}

.generator/schemas/v1/openapi.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27004,6 +27004,7 @@ paths:
2700427004
name: limit
2700527005
required: false
2700627006
schema:
27007+
default: 1000
2700727008
format: int64
2700827009
type: integer
2700927010
- description: The specific offset to use as the beginning of the returned response.
@@ -27048,6 +27049,10 @@ paths:
2704827049
summary: Get all SLOs
2704927050
tags:
2705027051
- Service Level Objectives
27052+
x-pagination:
27053+
limitParam: limit
27054+
pageOffsetParam: offset
27055+
resultsPath: data
2705127056
post:
2705227057
description: Create a service level objective object.
2705327058
operationId: CreateSLO
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""
2+
Get all SLOs returns "OK" response with pagination
3+
"""
4+
5+
from datadog_api_client import ApiClient, Configuration
6+
from datadog_api_client.v1.api.service_level_objectives_api import ServiceLevelObjectivesApi
7+
8+
configuration = Configuration()
9+
with ApiClient(configuration) as api_client:
10+
api_instance = ServiceLevelObjectivesApi(api_client)
11+
items = api_instance.list_slos_with_pagination(
12+
limit=2,
13+
)
14+
for item in items:
15+
print(item)

src/datadog_api_client/v1/api/service_level_objectives_api.py

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,26 @@
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.slo_list_response import SLOListResponse
18+
from datadog_api_client.v1.model.service_level_objective import ServiceLevelObjective
1519
from datadog_api_client.v1.model.service_level_objective_request import ServiceLevelObjectiveRequest
1620
from datadog_api_client.v1.model.slo_bulk_delete_response import SLOBulkDeleteResponse
1721
from datadog_api_client.v1.model.slo_bulk_delete import SLOBulkDelete
1822
from datadog_api_client.v1.model.check_can_delete_slo_response import CheckCanDeleteSLOResponse
1923
from datadog_api_client.v1.model.search_slo_response import SearchSLOResponse
2024
from datadog_api_client.v1.model.slo_delete_response import SLODeleteResponse
2125
from datadog_api_client.v1.model.slo_response import SLOResponse
22-
from datadog_api_client.v1.model.service_level_objective import ServiceLevelObjective
2326
from datadog_api_client.v1.model.slo_correction_list_response import SLOCorrectionListResponse
2427
from datadog_api_client.v1.model.slo_history_response import SLOHistoryResponse
2528

@@ -561,6 +564,67 @@ def list_slos(
561564

562565
return self._list_slos_endpoint.call_with_http_info(**kwargs)
563566

567+
def list_slos_with_pagination(
568+
self,
569+
*,
570+
ids: Union[str, UnsetType] = unset,
571+
query: Union[str, UnsetType] = unset,
572+
tags_query: Union[str, UnsetType] = unset,
573+
metrics_query: Union[str, UnsetType] = unset,
574+
limit: Union[int, UnsetType] = unset,
575+
offset: Union[int, UnsetType] = unset,
576+
) -> collections.abc.Iterable[ServiceLevelObjective]:
577+
"""Get all SLOs.
578+
579+
Provide a paginated version of :meth:`list_slos`, returning all items.
580+
581+
:param ids: A comma separated list of the IDs of the service level objectives objects.
582+
:type ids: str, optional
583+
:param query: The query string to filter results based on SLO names.
584+
:type query: str, optional
585+
:param tags_query: The query string to filter results based on a single SLO tag.
586+
:type tags_query: str, optional
587+
:param metrics_query: The query string to filter results based on SLO numerator and denominator.
588+
:type metrics_query: str, optional
589+
:param limit: The number of SLOs to return in the response.
590+
:type limit: int, optional
591+
:param offset: The specific offset to use as the beginning of the returned response.
592+
:type offset: int, optional
593+
594+
:return: A generator of paginated results.
595+
:rtype: collections.abc.Iterable[ServiceLevelObjective]
596+
"""
597+
kwargs: Dict[str, Any] = {}
598+
if ids is not unset:
599+
kwargs["ids"] = ids
600+
601+
if query is not unset:
602+
kwargs["query"] = query
603+
604+
if tags_query is not unset:
605+
kwargs["tags_query"] = tags_query
606+
607+
if metrics_query is not unset:
608+
kwargs["metrics_query"] = metrics_query
609+
610+
if limit is not unset:
611+
kwargs["limit"] = limit
612+
613+
if offset is not unset:
614+
kwargs["offset"] = offset
615+
616+
local_page_size = get_attribute_from_path(kwargs, "limit", 1000)
617+
endpoint = self._list_slos_endpoint
618+
set_attribute_from_path(kwargs, "limit", local_page_size, endpoint.params_map)
619+
pagination = {
620+
"limit_value": local_page_size,
621+
"results_path": "data",
622+
"page_offset_param": "offset",
623+
"endpoint": endpoint,
624+
"kwargs": kwargs,
625+
}
626+
return endpoint.call_with_http_info_paginated(pagination)
627+
564628
def search_slo(
565629
self,
566630
*,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2023-08-25T12:33:42.432Z
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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/slo?limit=2
9+
response:
10+
body:
11+
string: '{"data":[{"id":"70e82706f4ae56ff8bdd7f02e767f97c","name":"test SLO
12+
1668426861","tags":["type:test"],"monitor_tags":[],"thresholds":[{"timeframe":"7d","target":90.0,"target_display":"90."}],"type":"metric","type_id":1,"description":"","timeframe":"7d","target_threshold":90.0,"query":{"denominator":"sum:my.custom.metric{!type:ignored}.as_count()","numerator":"sum:my.custom.metric{type:good,!type:ignored}.as_count()"},"creator":{"name":null,"handle":"[email protected]","email":"[email protected]"},"created_at":1668426862,"modified_at":1668426862},{"id":"955ab6301fa656e7b061de4a05ad4774","name":"tf-TestAccDatadogServiceLevelObjective_Basic-local-1673543942-updated","tags":["foo:bar","baz"],"monitor_tags":[],"thresholds":[{"timeframe":"7d","target":99.5,"target_display":"99.5","warning":99.8,"warning_display":"99.8"},{"timeframe":"30d","target":98.0,"target_display":"98.","warning":99.0,"warning_display":"99."},{"timeframe":"90d","target":99.9,"target_display":"99.9"}],"type":"metric","type_id":1,"description":"some
13+
updated description about foo SLO","timeframe":"7d","warning_threshold":99.8,"target_threshold":99.5,"query":{"denominator":"sum:my.metric{type:good}.as_count()
14+
+ sum:my.metric{type:bad}.as_count()","numerator":"sum:my.metric{type:good}.as_count()"},"creator":{"name":null,"handle":"[email protected]","email":"[email protected]"},"created_at":1673543944,"modified_at":1673543945}],"error":null,"metadata":{"page":{"total_count":3,"total_filtered_count":2}}}
15+
16+
'
17+
headers:
18+
content-type:
19+
- application/json
20+
status:
21+
code: 200
22+
message: OK
23+
- request:
24+
body: null
25+
headers:
26+
accept:
27+
- application/json
28+
method: GET
29+
uri: https://api.datadoghq.com/api/v1/slo?limit=2&offset=2
30+
response:
31+
body:
32+
string: '{"data":[{"id":"a17acfd48b7c55d19192e3a697cc1d01","name":"test SLO
33+
1677686870","tags":[],"monitor_tags":[],"thresholds":[{"timeframe":"7d","target":90.0,"target_display":"90."}],"type":"monitor","type_id":0,"description":"","timeframe":"7d","target_threshold":90.0,"monitor_ids":[112445445],"creator":{"name":"CI
34+
Account","handle":"9919ec9b-ebc7-49ee-8dc8-03626e717cca","email":"[email protected]"},"created_at":1677686871,"modified_at":1677686871}],"error":null,"metadata":{"page":{"total_count":3,"total_filtered_count":2}}}
35+
36+
'
37+
headers:
38+
content-type:
39+
- application/json
40+
status:
41+
code: 200
42+
message: OK
43+
version: 1

tests/v1/features/service_level_objectives.feature

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,14 @@ Feature: Service Level Objectives
134134
And the response "data" has length 1
135135
And the response "data[0].id" has the same value as "slo.data[0].id"
136136

137+
@replay-only @skip-validation @team:DataDog/slo-app @with-pagination
138+
Scenario: Get all SLOs returns "OK" response with pagination
139+
Given new "ListSLOs" request
140+
And request contains "limit" parameter with value 2
141+
When the request with pagination is sent
142+
Then the response status is 200 OK
143+
And the response has 3 items
144+
137145
@generated @skip @team:DataDog/slo-app
138146
Scenario: Get an SLO's details returns "Not found" response
139147
Given new "GetSLO" request

0 commit comments

Comments
 (0)