Skip to content

Add pagination extension to SLOs #1295

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .apigentools-info
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"spec_versions": {
"v1": {
"apigentools_version": "1.6.5",
"regenerated": "2023-08-28 20:29:20.861535",
"spec_repo_commit": "0fac706f"
"regenerated": "2023-08-30 07:29:16.616488",
"spec_repo_commit": "febdee32"
},
"v2": {
"apigentools_version": "1.6.5",
"regenerated": "2023-08-28 20:29:20.877322",
"spec_repo_commit": "0fac706f"
"regenerated": "2023-08-30 07:29:16.629575",
"spec_repo_commit": "febdee32"
}
}
}
5 changes: 5 additions & 0 deletions .generator/schemas/v1/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27004,6 +27004,7 @@ paths:
name: limit
required: false
schema:
default: 1000
format: int64
type: integer
- description: The specific offset to use as the beginning of the returned response.
Expand Down Expand Up @@ -27048,6 +27049,10 @@ paths:
summary: Get all SLOs
tags:
- Service Level Objectives
x-pagination:
limitParam: limit
pageOffsetParam: offset
resultsPath: data
post:
description: Create a service level objective object.
operationId: CreateSLO
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"2023-08-25T12:33:42.432Z"
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
{
"log": {
"_recordingName": "Service Level Objectives/Get all SLOs returns \"OK\" response with pagination",
"creator": {
"comment": "persister:fs",
"name": "Polly.JS",
"version": "6.0.5"
},
"entries": [
{
"_id": "a179f385561658282db79e086f7baadf",
"_order": 0,
"cache": {},
"request": {
"bodySize": 0,
"cookies": [],
"headers": [
{
"_fromType": "array",
"name": "accept",
"value": "application/json"
}
],
"headersSize": 500,
"httpVersion": "HTTP/1.1",
"method": "GET",
"queryString": [
{
"name": "limit",
"value": "2"
}
],
"url": "https://api.datadoghq.com/api/v1/slo?limit=2"
},
"response": {
"bodySize": 1491,
"content": {
"mimeType": "application/json",
"size": 1491,
"text": "{\"data\":[{\"id\":\"70e82706f4ae56ff8bdd7f02e767f97c\",\"name\":\"test SLO 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\":\"frog@datadoghq.com\",\"email\":\"frog@datadoghq.com\"},\"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 updated description about foo SLO\",\"timeframe\":\"7d\",\"warning_threshold\":99.8,\"target_threshold\":99.5,\"query\":{\"denominator\":\"sum:my.metric{type:good}.as_count() + sum:my.metric{type:bad}.as_count()\",\"numerator\":\"sum:my.metric{type:good}.as_count()\"},\"creator\":{\"name\":null,\"handle\":\"frog@datadoghq.com\",\"email\":\"frog@datadoghq.com\"},\"created_at\":1673543944,\"modified_at\":1673543945}],\"error\":null,\"metadata\":{\"page\":{\"total_count\":3,\"total_filtered_count\":2}}}\n"
},
"cookies": [],
"headers": [
{
"name": "content-type",
"value": "application/json"
}
],
"headersSize": 648,
"httpVersion": "HTTP/1.1",
"redirectURL": "",
"status": 200,
"statusText": "OK"
},
"startedDateTime": "2023-08-25T12:33:42.442Z",
"time": 478
},
{
"_id": "20536200546072f9877a58046da401ba",
"_order": 0,
"cache": {},
"request": {
"bodySize": 0,
"cookies": [],
"headers": [
{
"_fromType": "array",
"name": "accept",
"value": "application/json"
}
],
"headersSize": 509,
"httpVersion": "HTTP/1.1",
"method": "GET",
"queryString": [
{
"name": "limit",
"value": "2"
},
{
"name": "offset",
"value": "2"
}
],
"url": "https://api.datadoghq.com/api/v1/slo?limit=2&offset=2"
},
"response": {
"bodySize": 1130,
"content": {
"mimeType": "application/json",
"size": 1130,
"text": "{\"data\":[{\"id\":\"a17acfd48b7c55d19192e3a697cc1d01\",\"name\":\"test SLO 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 Account\",\"handle\":\"9919ec9b-ebc7-49ee-8dc8-03626e717cca\",\"email\":\"team-intg-tools-libs-spam@datadoghq.com\"},\"created_at\":1677686871,\"modified_at\":1677686871}],\"error\":null,\"metadata\":{\"page\":{\"total_count\":3,\"total_filtered_count\":2}}}\n"
},
"cookies": [],
"headers": [
{
"name": "content-type",
"value": "application/json"
}
],
"headersSize": 648,
"httpVersion": "HTTP/1.1",
"redirectURL": "",
"status": 200,
"statusText": "OK"
},
"startedDateTime": "2023-08-25T12:33:42.924Z",
"time": 454
}
],
"pages": [],
"version": "1.2"
}
}
22 changes: 22 additions & 0 deletions examples/v1/service-level-objectives/ListSLOs_3036942817.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Get all SLOs returns "OK" response with pagination
*/

import { client, v1 } from "@datadog/datadog-api-client";

const configuration = client.createConfiguration();
const apiInstance = new v1.ServiceLevelObjectivesApi(configuration);

const params: v1.ServiceLevelObjectivesApiListSLOsRequest = {
limit: 2,
};

(async () => {
try {
for await (const item of apiInstance.listSLOsWithPagination(params)) {
console.log(item);
}
} catch (error) {
console.error(error);
}
})();
8 changes: 8 additions & 0 deletions features/v1/service_level_objectives.feature
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@ Feature: Service Level Objectives
And the response "data" has length 1
And the response "data[0].id" has the same value as "slo.data[0].id"

@replay-only @skip-validation @team:DataDog/slo-app @with-pagination
Scenario: Get all SLOs returns "OK" response with pagination
Given new "ListSLOs" request
And request contains "limit" parameter with value 2
When the request with pagination is sent
Then the response status is 200 OK
And the response has 3 items

@generated @skip @team:DataDog/slo-app
Scenario: Get an SLO's details returns "Not found" response
Given new "GetSLO" request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1517,6 +1517,52 @@ export class ServiceLevelObjectivesApi {
});
}

/**
* Provide a paginated version of listSLOs returning a generator with all the items.
*/
public async *listSLOsWithPagination(
param: ServiceLevelObjectivesApiListSLOsRequest = {},
options?: Configuration
): AsyncGenerator<ServiceLevelObjective> {
let pageSize = 1000;
if (param.limit !== undefined) {
pageSize = param.limit;
}
param.limit = pageSize;
while (true) {
const requestContext = await this.requestFactory.listSLOs(
param.ids,
param.query,
param.tagsQuery,
param.metricsQuery,
param.limit,
param.offset,
options
);
const responseContext = await this.configuration.httpApi.send(
requestContext
);

const response = await this.responseProcessor.listSLOs(responseContext);
const responseData = response.data;
if (responseData === undefined) {
break;
}
const results = responseData;
for (const item of results) {
yield item;
}
if (results.length < pageSize) {
break;
}
if (param.offset === undefined) {
param.offset = pageSize;
} else {
param.offset = param.offset + pageSize;
}
}
}

/**
* Get a list of service level objective objects for your organization.
* @param param The request object
Expand Down