Skip to content

Commit

Permalink
Add Synthetics endpoint to fetch uptimes in API spec (#1792)
Browse files Browse the repository at this point in the history
* add support for top level indexing

* Regenerate client from commit 3b4747f4 of spec repo

---------

Co-authored-by: Sherzod Karimov <sherzod.karimov@datadoghq.com>
Co-authored-by: api-clients-generation-pipeline[bot] <54105614+api-clients-generation-pipeline[bot]@users.noreply.github.com>
Co-authored-by: ci.datadog-api-spec <packages@datadoghq.com>
  • Loading branch information
3 people authored Oct 2, 2024
1 parent 82e2cbc commit 77a185d
Show file tree
Hide file tree
Showing 17 changed files with 730 additions and 4 deletions.
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.6",
"regenerated": "2024-10-02 13:39:26.970748",
"spec_repo_commit": "e02e4f4c"
"regenerated": "2024-10-02 14:33:57.486086",
"spec_repo_commit": "3b4747f4"
},
"v2": {
"apigentools_version": "1.6.6",
"regenerated": "2024-10-02 13:39:26.985809",
"spec_repo_commit": "e02e4f4c"
"regenerated": "2024-10-02 14:33:57.582216",
"spec_repo_commit": "3b4747f4"
}
}
}
143 changes: 143 additions & 0 deletions .generator/schemas/v1/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15194,6 +15194,32 @@ components:
- EDGE_LAPTOP_LARGE
- EDGE_TABLET
- EDGE_MOBILE_SMALL
SyntheticsFetchUptimesPayload:
description: Object containing IDs of Synthetic tests and a timeframe.
properties:
from_ts:
description: Timestamp in seconds (Unix epoch) for the start of uptime.
example: 0
format: int64
type: integer
public_ids:
description: An array of Synthetic test IDs you want to delete.
example: []
items:
description: A Synthetic test ID.
example: abc-def-123
type: string
type: array
to_ts:
description: Timestamp in seconds (Unix epoch) for the end of uptime.
example: 0
format: int64
type: integer
required:
- from_ts
- to_ts
- public_ids
type: object
SyntheticsGetAPITestLatestResultsResponse:
description: Object with the latest Synthetic API test run.
properties:
Expand Down Expand Up @@ -17283,6 +17309,24 @@ components:
description: String Port number to use when performing the test. Supports templated
variables.
type: string
SyntheticsTestUptime:
description: Object containing the uptime for a Synthetic test ID.
properties:
from_ts:
description: Timestamp in seconds for the start of uptime.
format: int64
type: integer
overall:
$ref: '#/components/schemas/SyntheticsUptime'
public_id:
description: A Synthetic test ID.
example: abc-def-123
type: string
to_ts:
description: Timestamp in seconds for the end of uptime.
format: int64
type: integer
type: object
SyntheticsTiming:
description: 'Object containing all metrics and their values collected for a
Synthetic API test.
Expand Down Expand Up @@ -17406,6 +17450,62 @@ components:
new_status:
$ref: '#/components/schemas/SyntheticsTestPauseStatus'
type: object
SyntheticsUptime:
description: Object containing the uptime information.
properties:
errors:
description: An array of error objects returned while querying the history
data for the service level objective.
items:
$ref: '#/components/schemas/SLOHistoryResponseErrorWithType'
nullable: true
type: array
group:
description: The location name
example: name
type: string
history:
description: 'The state transition history for the monitor, represented
as an array of

pairs. Each pair is an array where the first element is the transition
timestamp

in Unix epoch format (integer) and the second element is the state (integer).

For the state, an integer value of `0` indicates uptime, `1` indicates
downtime,

and `2` indicates no data.'
example:
- - 1579212382
- 0
items:
description: An array of transitions
example:
- 1579212382
- 0
items:
description: A timeseries data point which is a tuple of (timestamp,
value).
format: double
type: number
maxItems: 2
minItems: 2
type: array
type: array
span_precision:
description: The number of decimal places to which the SLI value is accurate
for the given from-to timestamps.
example: 2.0
format: double
type: number
uptime:
description: The overall uptime.
example: 99.99
format: double
type: number
type: object
SyntheticsVariableParser:
description: Details of the parser to use for the global variable.
example:
Expand Down Expand Up @@ -32934,6 +33034,49 @@ paths:
operator: OR
permissions:
- synthetics_write
/api/v1/synthetics/tests/uptimes:
post:
description: Fetch uptime for multiple Synthetic tests by ID.
operationId: FetchUptimes
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/SyntheticsFetchUptimesPayload'
description: Public ID list of the Synthetic tests and timeframe.
required: true
responses:
'200':
content:
application/json:
schema:
items:
$ref: '#/components/schemas/SyntheticsTestUptime'
type: array
description: OK.
'400':
content:
application/json:
schema:
$ref: '#/components/schemas/APIErrorResponse'
description: '- JSON format is wrong'
'403':
content:
application/json:
schema:
$ref: '#/components/schemas/APIErrorResponse'
description: Forbidden
'429':
$ref: '#/components/responses/TooManyRequestsResponse'
security:
- apiKeyAuth: []
appKeyAuth: []
- AuthZ:
- synthetics_read
summary: Fetch uptime for multiple tests
tags:
- Synthetics
x-codegen-request-body-name: body
/api/v1/synthetics/tests/{public_id}:
get:
description: Get the detailed configuration associated with a Synthetic test.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"2024-10-02T14:22:00.562Z"
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"log": {
"_recordingName": "Synthetics/Fetch uptime for multiple tests returns \"- JSON format is wrong\" response",
"creator": {
"comment": "persister:fs",
"name": "Polly.JS",
"version": "6.0.5"
},
"entries": [
{
"_id": "23da9bb74dd412c237ee8406f9945944",
"_order": 0,
"cache": {},
"request": {
"bodySize": 39,
"cookies": [],
"headers": [
{
"_fromType": "array",
"name": "accept",
"value": "application/json"
},
{
"_fromType": "array",
"name": "content-type",
"value": "application/json"
}
],
"headersSize": 570,
"httpVersion": "HTTP/1.1",
"method": "POST",
"postData": {
"mimeType": "application/json",
"params": [],
"text": "{\"from_ts\":0,\"public_ids\":[],\"to_ts\":0}"
},
"queryString": [],
"url": "https://api.datadoghq.com/api/v1/synthetics/tests/uptimes"
},
"response": {
"bodySize": 79,
"content": {
"mimeType": "application/json",
"size": 79,
"text": "{\"errors\":[\"Minimum number of elements in parameter 'public_ids' should be 1\"]}"
},
"cookies": [],
"headers": [
{
"name": "content-type",
"value": "application/json"
}
],
"headersSize": 664,
"httpVersion": "HTTP/1.1",
"redirectURL": "",
"status": 400,
"statusText": "Bad Request"
},
"startedDateTime": "2024-10-02T14:22:00.573Z",
"time": 81
}
],
"pages": [],
"version": "1.2"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"2024-09-11T13:09:28.349Z"
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"log": {
"_recordingName": "Synthetics/Fetch uptime for multiple tests returns \"OK.\" response",
"creator": {
"comment": "persister:fs",
"name": "Polly.JS",
"version": "6.0.5"
},
"entries": [
{
"_id": "5bb349ef4e2317c9387395651078521d",
"_order": 0,
"cache": {},
"request": {
"bodySize": 70,
"cookies": [],
"headers": [
{
"_fromType": "array",
"name": "accept",
"value": "application/json"
},
{
"_fromType": "array",
"name": "content-type",
"value": "application/json"
}
],
"headersSize": 570,
"httpVersion": "HTTP/1.1",
"method": "POST",
"postData": {
"mimeType": "application/json",
"params": [],
"text": "{\"from_ts\":1726041488,\"public_ids\":[\"p8m-9gw-nte\"],\"to_ts\":1726055954}"
},
"queryString": [],
"url": "https://api.datadoghq.com/api/v1/synthetics/tests/uptimes"
},
"response": {
"bodySize": 314,
"content": {
"mimeType": "application/json",
"size": 314,
"text": "[{\"from_ts\":1726041488,\"to_ts\":1726055954,\"overall\":{\"name\":\"[Synthetics] Synthetics test\",\"preview\":false,\"monitor_type\":\"synthetics alert\",\"monitor_modified\":1726060063,\"errors\":null,\"span_precision\":0,\"history\":[[1726004543,0],[1726053503,1]],\"uptime\":83.05682373046875},\"public_id\":\"p8m-9gw-nte\",\"groups\":[]}]\n"
},
"cookies": [],
"headers": [
{
"name": "content-type",
"value": "application/json"
}
],
"headersSize": 665,
"httpVersion": "HTTP/1.1",
"redirectURL": "",
"status": 200,
"statusText": "OK"
},
"startedDateTime": "2024-09-11T13:09:28.358Z",
"time": 508
}
],
"pages": [],
"version": "1.2"
}
}
25 changes: 25 additions & 0 deletions examples/v1/synthetics/FetchUptimes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Fetch uptime for multiple tests returns "OK." response
*/

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

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

const params: v1.SyntheticsApiFetchUptimesRequest = {
body: {
fromTs: 1726041488,
publicIds: ["p8m-9gw-nte"],
toTs: 1726055954,
},
};

apiInstance
.fetchUptimes(params)
.then((data: v1.SyntheticsTestUptime[]) => {
console.log(
"API called successfully. Returned data: " + JSON.stringify(data)
);
})
.catch((error: any) => console.error(error));
7 changes: 7 additions & 0 deletions features/support/scenarios_model_mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2108,6 +2108,13 @@ export const ScenariosModelMappings: {[key: string]: {[key: string]: any}} = {
},
"operationResponseType": "SyntheticsTriggerCITestsResponse",
},
"v1.FetchUptimes": {
"body": {
"type": "SyntheticsFetchUptimesPayload",
"format": "",
},
"operationResponseType": "Array<SyntheticsTestUptime>",
},
"v1.GetTest": {
"publicId": {
"type": "string",
Expand Down
3 changes: 3 additions & 0 deletions features/support/templating.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ function pathLookup(data: any, dottedPath: string): any {
continue;
}
for (const part of dotPath.split("[")) {
if (part === "") {
continue;
}
if (part.includes("]")) {
const results = result as any[];
result = results[parseInt(part)];
Expand Down
Loading

0 comments on commit 77a185d

Please sign in to comment.