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 parameters to downtimes listing #1308

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-09-06 11:51:20.362624",
"spec_repo_commit": "c59cafad"
"regenerated": "2023-09-06 12:26:36.154836",
"spec_repo_commit": "07ee6775"
},
"v2": {
"apigentools_version": "1.6.5",
"regenerated": "2023-09-06 11:51:20.376672",
"spec_repo_commit": "c59cafad"
"regenerated": "2023-09-06 12:26:36.174283",
"spec_repo_commit": "07ee6775"
}
}
}
14 changes: 14 additions & 0 deletions .generator/schemas/v2/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18815,6 +18815,16 @@ paths:
schema:
example: created_by,monitor
type: string
- $ref: '#/components/parameters/PageOffset'
- description: Maximum number of downtimes in the response.
example: 100
in: query
name: page[limit]
required: false
schema:
default: 30
format: int64
type: integer
responses:
'200':
content:
Expand All @@ -18838,6 +18848,10 @@ paths:
summary: Get all downtimes
tags:
- Downtimes
x-pagination:
limitParam: page[limit]
pageOffsetParam: page[offset]
resultsPath: data
x-unstable: '**Note**: This endpoint is in private beta.

If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/).'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"2023-09-05T12:32:39.085Z"
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
{
"log": {
"_recordingName": "Downtimes/Get all downtimes returns \"OK\" response with pagination",
"creator": {
"comment": "persister:fs",
"name": "Polly.JS",
"version": "6.0.5"
},
"entries": [
{
"_id": "eab058833e2e3fd977fffe2fa5d6a767",
"_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": "page",
"value": {
"limit": "2"
}
}
],
"url": "https://api.datadoghq.com/api/v2/downtime?page%5Blimit%5D=2"
},
"response": {
"bodySize": 1126,
"content": {
"mimeType": "application/json",
"size": 1126,
"text": "{\"data\":[{\"type\":\"downtime\",\"attributes\":{\"mute_first_recovery_notification\":false,\"canceled\":null,\"monitor_identifier\":{\"monitor_tags\":[\"*\"]},\"schedule\":{\"start\":\"2023-05-22T03:06:54.072998+00:00\",\"end\":null},\"notify_end_types\":[\"expired\"],\"notify_end_states\":[\"no data\",\"warn\",\"alert\"],\"status\":\"active\",\"scope\":\"host:\\\"java-hostsMuteErrorsTest-local-1684724813\\\"\",\"created\":\"2023-05-22T03:06:54.079122+00:00\",\"display_timezone\":\"UTC\",\"message\":null,\"modified\":\"2023-05-22T03:06:54.079122+00:00\"},\"id\":\"b4613732-f84d-11ed-a766-da7ad0900002\"},{\"type\":\"downtime\",\"attributes\":{\"mute_first_recovery_notification\":false,\"canceled\":null,\"monitor_identifier\":{\"monitor_tags\":[\"*\"]},\"schedule\":{\"start\":\"2023-05-23T03:21:54.687109+00:00\",\"end\":null},\"notify_end_types\":[\"expired\"],\"notify_end_states\":[\"no data\",\"warn\",\"alert\"],\"status\":\"active\",\"scope\":\"host:\\\"java-hostsMuteErrorsTest-local-1684812114\\\"\",\"created\":\"2023-05-23T03:21:54.690618+00:00\",\"display_timezone\":\"UTC\",\"message\":null,\"modified\":\"2023-05-23T03:21:54.690618+00:00\"},\"id\":\"f799770a-f918-11ed-8b48-da7ad0900002\"}],\"meta\":{\"page\":{\"total_filtered_count\":3}}}\n"
},
"cookies": [],
"headers": [
{
"name": "content-type",
"value": "application/json"
}
],
"headersSize": 696,
"httpVersion": "HTTP/1.1",
"redirectURL": "",
"status": 200,
"statusText": "OK"
},
"startedDateTime": "2023-09-05T12:32:39.094Z",
"time": 491
},
{
"_id": "d373bb44355fb07f5a004f9395685267",
"_order": 0,
"cache": {},
"request": {
"bodySize": 0,
"cookies": [],
"headers": [
{
"_fromType": "array",
"name": "accept",
"value": "application/json"
}
],
"headersSize": 539,
"httpVersion": "HTTP/1.1",
"method": "GET",
"queryString": [
{
"name": "page",
"value": {
"limit": "2",
"offset": "2"
}
}
],
"url": "https://api.datadoghq.com/api/v2/downtime?page%5Blimit%5D=2&page%5Boffset%5D=2"
},
"response": {
"bodySize": 1126,
"content": {
"mimeType": "application/json",
"size": 1126,
"text": "{\"data\":[{\"type\":\"downtime\",\"attributes\":{\"modified\":\"2023-05-24T03:29:35.343207+00:00\",\"created\":\"2023-05-24T03:29:35.343207+00:00\",\"canceled\":null,\"status\":\"active\",\"scope\":\"host:\\\"java-hostsMuteErrorsTest-local-1684898975\\\"\",\"display_timezone\":\"UTC\",\"schedule\":{\"end\":null,\"start\":\"2023-05-24T03:29:35.340446+00:00\"},\"message\":null,\"mute_first_recovery_notification\":false,\"notify_end_types\":[\"expired\"],\"notify_end_states\":[\"warn\",\"no data\",\"alert\"],\"monitor_identifier\":{\"monitor_tags\":[\"*\"]}},\"id\":\"34953930-f9e3-11ed-85d4-da7ad0900002\"}],\"meta\":{\"page\":{\"total_filtered_count\":3}}}\n"
},
"cookies": [],
"headers": [
{
"name": "content-type",
"value": "application/json"
}
],
"headersSize": 696,
"httpVersion": "HTTP/1.1",
"redirectURL": "",
"status": 200,
"statusText": "OK"
},
"startedDateTime": "2023-09-05T12:32:39.593Z",
"time": 452
}
],
"pages": [],
"version": "1.2"
}
}
23 changes: 23 additions & 0 deletions examples/v2/downtimes/ListDowntimes_805770330.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* Get all downtimes returns "OK" response with pagination
*/

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

const configuration = client.createConfiguration();
configuration.unstableOperations["v2.listDowntimes"] = true;
const apiInstance = new v2.DowntimesApi(configuration);

const params: v2.DowntimesApiListDowntimesRequest = {
pageLimit: 2,
};

(async () => {
try {
for await (const item of apiInstance.listDowntimesWithPagination(params)) {
console.log(item);
}
} catch (error) {
console.error(error);
}
})();
8 changes: 8 additions & 0 deletions features/support/scenarios_model_mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2721,6 +2721,14 @@ export const ScenariosModelMappings: {[key: string]: {[key: string]: any}} = {
"type": "string",
"format": "",
},
"pageOffset": {
"type": "number",
"format": "int64",
},
"pageLimit": {
"type": "number",
"format": "int64",
},
"operationResponseType": "ListDowntimesResponse",
},
"v2.CreateDowntime": {
Expand Down
9 changes: 9 additions & 0 deletions features/v2/downtimes.feature
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,15 @@ Feature: Downtimes
Then the response status is 200 OK
And the response "data" has item with field "id" with value "1dcb33f8-b23a-11ed-ae77-da7ad0900002"

@replay-only @skip-validation @team:DataDog/monitor-app @with-pagination
Scenario: Get all downtimes returns "OK" response with pagination
Given operation "ListDowntimes" enabled
And new "ListDowntimes" request
And request contains "page[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

@skip-validation @team:DataDog/monitor-app
Scenario: Schedule a downtime returns "Bad Request" response
Given new "CreateDowntime" request
Expand Down
73 changes: 73 additions & 0 deletions packages/datadog-api-client-v2/apis/DowntimesApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { ApiException } from "../../datadog-api-client-common/exception";
import { APIErrorResponse } from "../models/APIErrorResponse";
import { DowntimeCreateRequest } from "../models/DowntimeCreateRequest";
import { DowntimeResponse } from "../models/DowntimeResponse";
import { DowntimeResponseData } from "../models/DowntimeResponseData";
import { DowntimeUpdateRequest } from "../models/DowntimeUpdateRequest";
import { ListDowntimesResponse } from "../models/ListDowntimesResponse";
import { MonitorDowntimeMatchResponse } from "../models/MonitorDowntimeMatchResponse";
Expand Down Expand Up @@ -161,6 +162,8 @@ export class DowntimesApiRequestFactory extends BaseAPIRequestFactory {
public async listDowntimes(
currentOnly?: boolean,
include?: string,
pageOffset?: number,
pageLimit?: number,
_options?: Configuration
): Promise<RequestContext> {
const _config = _options || this.configuration;
Expand Down Expand Up @@ -193,6 +196,18 @@ export class DowntimesApiRequestFactory extends BaseAPIRequestFactory {
ObjectSerializer.serialize(include, "string", "")
);
}
if (pageOffset !== undefined) {
requestContext.setQueryParam(
"page[offset]",
ObjectSerializer.serialize(pageOffset, "number", "int64")
);
}
if (pageLimit !== undefined) {
requestContext.setQueryParam(
"page[limit]",
ObjectSerializer.serialize(pageLimit, "number", "int64")
);
}

// Apply auth methods
applySecurityAuthentication(_config, requestContext, [
Expand Down Expand Up @@ -705,6 +720,16 @@ export interface DowntimesApiListDowntimesRequest {
* @type string
*/
include?: string;
/**
* Specific offset to use as the beginning of the returned page.
* @type number
*/
pageOffset?: number;
/**
* Maximum number of downtimes in the response.
* @type number
*/
pageLimit?: number;
}

export interface DowntimesApiListMonitorDowntimesRequest {
Expand Down Expand Up @@ -820,6 +845,8 @@ export class DowntimesApi {
const requestContextPromise = this.requestFactory.listDowntimes(
param.currentOnly,
param.include,
param.pageOffset,
param.pageLimit,
options
);
return requestContextPromise.then((requestContext) => {
Expand All @@ -831,6 +858,52 @@ export class DowntimesApi {
});
}

/**
* Provide a paginated version of listDowntimes returning a generator with all the items.
*/
public async *listDowntimesWithPagination(
param: DowntimesApiListDowntimesRequest = {},
options?: Configuration
): AsyncGenerator<DowntimeResponseData> {
let pageSize = 30;
if (param.pageLimit !== undefined) {
pageSize = param.pageLimit;
}
param.pageLimit = pageSize;
while (true) {
const requestContext = await this.requestFactory.listDowntimes(
param.currentOnly,
param.include,
param.pageOffset,
param.pageLimit,
options
);
const responseContext = await this.configuration.httpApi.send(
requestContext
);

const response = await this.responseProcessor.listDowntimes(
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.pageOffset === undefined) {
param.pageOffset = pageSize;
} else {
param.pageOffset = param.pageOffset + pageSize;
}
}
}

/**
* Get all active downtimes for the specified monitor.
* @param param The request object
Expand Down
Loading