Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add pagination extension to SLO corrections #1294

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-23 20:02:10.805710",
"spec_repo_commit": "7e4a4121"
"regenerated": "2023-08-25 12:25:26.250184",
"spec_repo_commit": "1a77c0b6"
},
"v2": {
"apigentools_version": "1.6.5",
"regenerated": "2023-08-23 20:02:10.823663",
"spec_repo_commit": "7e4a4121"
"regenerated": "2023-08-25 12:25:26.263034",
"spec_repo_commit": "1a77c0b6"
}
}
}
5 changes: 5 additions & 0 deletions .generator/schemas/v1/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27185,6 +27185,7 @@ paths:
name: limit
required: false
schema:
default: 25
format: int64
type: integer
responses:
Expand All @@ -27210,6 +27211,10 @@ paths:
summary: Get all SLO corrections
tags:
- Service Level Objective Corrections
x-pagination:
limitParam: limit
pageOffsetParam: offset
resultsPath: data
post:
description: Create an SLO Correction.
operationId: CreateSLOCorrection
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"2023-08-25T11:50:34.970Z"
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
{
"log": {
"_recordingName": "Service Level Objective Corrections/Get all SLO corrections returns \"OK\" response with pagination",
"creator": {
"comment": "persister:fs",
"name": "Polly.JS",
"version": "6.0.5"
},
"entries": [
{
"_id": "a47256681b359bab367712eda16a1905",
"_order": 0,
"cache": {},
"request": {
"bodySize": 0,
"cookies": [],
"headers": [
{
"_fromType": "array",
"name": "accept",
"value": "application/json"
}
],
"headersSize": 520,
"httpVersion": "HTTP/1.1",
"method": "GET",
"queryString": [
{
"name": "limit",
"value": "2"
}
],
"url": "https://api.datadoghq.com/api/v1/slo/correction?limit=2"
},
"response": {
"bodySize": 1358,
"content": {
"mimeType": "application/json",
"size": 1358,
"text": "{\"data\":[{\"type\":\"correction\",\"id\":\"fb76e0fa-bf7b-11ed-ba7e-da7ad0902002\",\"attributes\":{\"slo_id\":\"a17acfd48b7c55d19192e3a697cc1d01\",\"start\":1678255200,\"end\":1678355280,\"description\":\"\",\"category\":\"Other\",\"timezone\":\"UTC\",\"created_at\":1678477473,\"modified_at\":1678477473,\"rrule\":null,\"duration\":null,\"creator\":{\"data\":{\"type\":\"users\",\"id\":\"35c75d43-eba0-11e9-a77a-2b3585ff5dfb\",\"attributes\":{\"uuid\":\"35c75d43-eba0-11e9-a77a-2b3585ff5dfb\",\"handle\":\"support-nickautotestingorg\",\"email\":\"[email protected]\",\"name\":\"Datadog Support\",\"icon\":\"https://secure.gravatar.com/avatar/e6952b5f29fe2d996cf4e63f40db9e71?s=48&d=retro\"}}},\"modifier\":null}},{\"type\":\"correction\",\"id\":\"2d16c2ee-bf70-11ed-895f-da7ad0902002\",\"attributes\":{\"slo_id\":\"70e82706f4ae56ff8bdd7f02e767f97c\",\"start\":1678255200,\"end\":1678339140,\"description\":\"\",\"category\":\"Other\",\"timezone\":\"UTC\",\"created_at\":1678472403,\"modified_at\":1678472403,\"rrule\":null,\"duration\":null,\"creator\":{\"data\":{\"type\":\"users\",\"id\":\"35c75d43-eba0-11e9-a77a-2b3585ff5dfb\",\"attributes\":{\"uuid\":\"35c75d43-eba0-11e9-a77a-2b3585ff5dfb\",\"handle\":\"support-nickautotestingorg\",\"email\":\"[email protected]\",\"name\":\"Datadog Support\",\"icon\":\"https://secure.gravatar.com/avatar/e6952b5f29fe2d996cf4e63f40db9e71?s=48&d=retro\"}}},\"modifier\":null}}],\"meta\":{\"page\":{\"total_count\":3,\"total_filtered_count\":2}}}\n"
},
"cookies": [],
"headers": [
{
"name": "content-type",
"value": "application/json"
}
],
"headersSize": 663,
"httpVersion": "HTTP/1.1",
"redirectURL": "",
"status": 200,
"statusText": "OK"
},
"startedDateTime": "2023-08-25T11:50:34.979Z",
"time": 551
},
{
"_id": "95d50d9a0ada960f9b57178aacd8f885",
"_order": 0,
"cache": {},
"request": {
"bodySize": 0,
"cookies": [],
"headers": [
{
"_fromType": "array",
"name": "accept",
"value": "application/json"
}
],
"headersSize": 529,
"httpVersion": "HTTP/1.1",
"method": "GET",
"queryString": [
{
"name": "limit",
"value": "2"
},
{
"name": "offset",
"value": "2"
}
],
"url": "https://api.datadoghq.com/api/v1/slo/correction?limit=2&offset=2"
},
"response": {
"bodySize": 714,
"content": {
"mimeType": "application/json",
"size": 714,
"text": "{\"data\":[{\"type\":\"correction\",\"id\":\"cc2316d2-bf6e-11ed-82f2-da7ad0902002\",\"attributes\":{\"slo_id\":\"955ab6301fa656e7b061de4a05ad4774\",\"start\":1678255200,\"end\":1678339140,\"description\":\"\",\"category\":\"Other\",\"timezone\":\"UTC\",\"created_at\":1678471811,\"modified_at\":1678471811,\"rrule\":null,\"duration\":null,\"creator\":{\"data\":{\"type\":\"users\",\"id\":\"35c75d43-eba0-11e9-a77a-2b3585ff5dfb\",\"attributes\":{\"uuid\":\"35c75d43-eba0-11e9-a77a-2b3585ff5dfb\",\"handle\":\"support-nickautotestingorg\",\"email\":\"[email protected]\",\"name\":\"Datadog Support\",\"icon\":\"https://secure.gravatar.com/avatar/e6952b5f29fe2d996cf4e63f40db9e71?s=48&d=retro\"}}},\"modifier\":null}}],\"meta\":{\"page\":{\"total_count\":3,\"total_filtered_count\":1}}}\n"
},
"cookies": [],
"headers": [
{
"name": "content-type",
"value": "application/json"
}
],
"headersSize": 662,
"httpVersion": "HTTP/1.1",
"redirectURL": "",
"status": 200,
"statusText": "OK"
},
"startedDateTime": "2023-08-25T11:50:35.538Z",
"time": 500
}
],
"pages": [],
"version": "1.2"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Get all SLO corrections returns "OK" response with pagination
*/

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

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

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

(async () => {
try {
for await (const item of apiInstance.listSLOCorrectionWithPagination(
params
)) {
console.log(item);
}
} catch (error) {
console.error(error);
}
})();
8 changes: 8 additions & 0 deletions features/v1/service_level_objective_corrections.feature
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ Feature: Service Level Objective Corrections
Then the response status is 200 OK
And the response "data" has length 1

@replay-only @skip-validation @team:DataDog/slo-app @with-pagination
Scenario: Get all SLO corrections returns "OK" response with pagination
Given new "ListSLOCorrection" 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 correction for an SLO returns "Bad Request" response
Given new "GetSLOCorrection" request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { ObjectSerializer } from "../models/ObjectSerializer";
import { ApiException } from "../../datadog-api-client-common/exception";

import { APIErrorResponse } from "../models/APIErrorResponse";
import { SLOCorrection } from "../models/SLOCorrection";
import { SLOCorrectionCreateRequest } from "../models/SLOCorrectionCreateRequest";
import { SLOCorrectionListResponse } from "../models/SLOCorrectionListResponse";
import { SLOCorrectionResponse } from "../models/SLOCorrectionResponse";
Expand Down Expand Up @@ -681,6 +682,50 @@ export class ServiceLevelObjectiveCorrectionsApi {
});
}

/**
* Provide a paginated version of listSLOCorrection returning a generator with all the items.
*/
public async *listSLOCorrectionWithPagination(
param: ServiceLevelObjectiveCorrectionsApiListSLOCorrectionRequest = {},
options?: Configuration
): AsyncGenerator<SLOCorrection> {
let pageSize = 25;
if (param.limit !== undefined) {
pageSize = param.limit;
}
param.limit = pageSize;
while (true) {
const requestContext = await this.requestFactory.listSLOCorrection(
param.offset,
param.limit,
options
);
const responseContext = await this.configuration.httpApi.send(
requestContext
);

const response = await this.responseProcessor.listSLOCorrection(
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;
}
}
}

/**
* Update the specified SLO correction object.
* @param param The request object
Expand Down
Loading