Skip to content

Commit 6ed404c

Browse files
api-clients-generation-pipeline[bot]skarimoci.datadog-api-spec
authored
Add Synthetics endpoint to fetch uptimes in API spec (#272)
Co-authored-by: Sherzod Karimov <[email protected]> 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 <[email protected]>
1 parent 42841a8 commit 6ed404c

16 files changed

+917
-4
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.6",
7-
"regenerated": "2024-10-02 13:39:22.917984",
8-
"spec_repo_commit": "e02e4f4c"
7+
"regenerated": "2024-10-02 14:33:54.593908",
8+
"spec_repo_commit": "3b4747f4"
99
},
1010
"v2": {
1111
"apigentools_version": "1.6.6",
12-
"regenerated": "2024-10-02 13:39:22.933099",
13-
"spec_repo_commit": "e02e4f4c"
12+
"regenerated": "2024-10-02 14:33:54.609830",
13+
"spec_repo_commit": "3b4747f4"
1414
}
1515
}
1616
}

.generator/schemas/v1/openapi.yaml

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15194,6 +15194,32 @@ components:
1519415194
- EDGE_LAPTOP_LARGE
1519515195
- EDGE_TABLET
1519615196
- EDGE_MOBILE_SMALL
15197+
SyntheticsFetchUptimesPayload:
15198+
description: Object containing IDs of Synthetic tests and a timeframe.
15199+
properties:
15200+
from_ts:
15201+
description: Timestamp in seconds (Unix epoch) for the start of uptime.
15202+
example: 0
15203+
format: int64
15204+
type: integer
15205+
public_ids:
15206+
description: An array of Synthetic test IDs you want to delete.
15207+
example: []
15208+
items:
15209+
description: A Synthetic test ID.
15210+
example: abc-def-123
15211+
type: string
15212+
type: array
15213+
to_ts:
15214+
description: Timestamp in seconds (Unix epoch) for the end of uptime.
15215+
example: 0
15216+
format: int64
15217+
type: integer
15218+
required:
15219+
- from_ts
15220+
- to_ts
15221+
- public_ids
15222+
type: object
1519715223
SyntheticsGetAPITestLatestResultsResponse:
1519815224
description: Object with the latest Synthetic API test run.
1519915225
properties:
@@ -17283,6 +17309,24 @@ components:
1728317309
description: String Port number to use when performing the test. Supports templated
1728417310
variables.
1728517311
type: string
17312+
SyntheticsTestUptime:
17313+
description: Object containing the uptime for a Synthetic test ID.
17314+
properties:
17315+
from_ts:
17316+
description: Timestamp in seconds for the start of uptime.
17317+
format: int64
17318+
type: integer
17319+
overall:
17320+
$ref: '#/components/schemas/SyntheticsUptime'
17321+
public_id:
17322+
description: A Synthetic test ID.
17323+
example: abc-def-123
17324+
type: string
17325+
to_ts:
17326+
description: Timestamp in seconds for the end of uptime.
17327+
format: int64
17328+
type: integer
17329+
type: object
1728617330
SyntheticsTiming:
1728717331
description: 'Object containing all metrics and their values collected for a
1728817332
Synthetic API test.
@@ -17406,6 +17450,62 @@ components:
1740617450
new_status:
1740717451
$ref: '#/components/schemas/SyntheticsTestPauseStatus'
1740817452
type: object
17453+
SyntheticsUptime:
17454+
description: Object containing the uptime information.
17455+
properties:
17456+
errors:
17457+
description: An array of error objects returned while querying the history
17458+
data for the service level objective.
17459+
items:
17460+
$ref: '#/components/schemas/SLOHistoryResponseErrorWithType'
17461+
nullable: true
17462+
type: array
17463+
group:
17464+
description: The location name
17465+
example: name
17466+
type: string
17467+
history:
17468+
description: 'The state transition history for the monitor, represented
17469+
as an array of
17470+
17471+
pairs. Each pair is an array where the first element is the transition
17472+
timestamp
17473+
17474+
in Unix epoch format (integer) and the second element is the state (integer).
17475+
17476+
For the state, an integer value of `0` indicates uptime, `1` indicates
17477+
downtime,
17478+
17479+
and `2` indicates no data.'
17480+
example:
17481+
- - 1579212382
17482+
- 0
17483+
items:
17484+
description: An array of transitions
17485+
example:
17486+
- 1579212382
17487+
- 0
17488+
items:
17489+
description: A timeseries data point which is a tuple of (timestamp,
17490+
value).
17491+
format: double
17492+
type: number
17493+
maxItems: 2
17494+
minItems: 2
17495+
type: array
17496+
type: array
17497+
span_precision:
17498+
description: The number of decimal places to which the SLI value is accurate
17499+
for the given from-to timestamps.
17500+
example: 2.0
17501+
format: double
17502+
type: number
17503+
uptime:
17504+
description: The overall uptime.
17505+
example: 99.99
17506+
format: double
17507+
type: number
17508+
type: object
1740917509
SyntheticsVariableParser:
1741017510
description: Details of the parser to use for the global variable.
1741117511
example:
@@ -32934,6 +33034,49 @@ paths:
3293433034
operator: OR
3293533035
permissions:
3293633036
- synthetics_write
33037+
/api/v1/synthetics/tests/uptimes:
33038+
post:
33039+
description: Fetch uptime for multiple Synthetic tests by ID.
33040+
operationId: FetchUptimes
33041+
requestBody:
33042+
content:
33043+
application/json:
33044+
schema:
33045+
$ref: '#/components/schemas/SyntheticsFetchUptimesPayload'
33046+
description: Public ID list of the Synthetic tests and timeframe.
33047+
required: true
33048+
responses:
33049+
'200':
33050+
content:
33051+
application/json:
33052+
schema:
33053+
items:
33054+
$ref: '#/components/schemas/SyntheticsTestUptime'
33055+
type: array
33056+
description: OK.
33057+
'400':
33058+
content:
33059+
application/json:
33060+
schema:
33061+
$ref: '#/components/schemas/APIErrorResponse'
33062+
description: '- JSON format is wrong'
33063+
'403':
33064+
content:
33065+
application/json:
33066+
schema:
33067+
$ref: '#/components/schemas/APIErrorResponse'
33068+
description: Forbidden
33069+
'429':
33070+
$ref: '#/components/responses/TooManyRequestsResponse'
33071+
security:
33072+
- apiKeyAuth: []
33073+
appKeyAuth: []
33074+
- AuthZ:
33075+
- synthetics_read
33076+
summary: Fetch uptime for multiple tests
33077+
tags:
33078+
- Synthetics
33079+
x-codegen-request-body-name: body
3293733080
/api/v1/synthetics/tests/{public_id}:
3293833081
get:
3293933082
description: Get the detailed configuration associated with a Synthetic test.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Fetch uptime for multiple tests returns "OK." response
2+
use datadog_api_client::datadog;
3+
use datadog_api_client::datadogV1::api_synthetics::SyntheticsAPI;
4+
use datadog_api_client::datadogV1::model::SyntheticsFetchUptimesPayload;
5+
6+
#[tokio::main]
7+
async fn main() {
8+
let body =
9+
SyntheticsFetchUptimesPayload::new(1726041488, vec!["p8m-9gw-nte".to_string()], 1726055954);
10+
let configuration = datadog::Configuration::new();
11+
let api = SyntheticsAPI::with_config(configuration);
12+
let resp = api.fetch_uptimes(body).await;
13+
if let Ok(value) = resp {
14+
println!("{:#?}", value);
15+
} else {
16+
println!("{:#?}", resp.unwrap_err());
17+
}
18+
}

src/datadogV1/api/api_synthetics.rs

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,14 @@ pub enum EditGlobalVariableError {
167167
UnknownValue(serde_json::Value),
168168
}
169169

170+
/// FetchUptimesError is a struct for typed errors of method [`SyntheticsAPI::fetch_uptimes`]
171+
#[derive(Debug, Clone, Serialize, Deserialize)]
172+
#[serde(untagged)]
173+
pub enum FetchUptimesError {
174+
APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
175+
UnknownValue(serde_json::Value),
176+
}
177+
170178
/// GetAPITestError is a struct for typed errors of method [`SyntheticsAPI::get_api_test`]
171179
#[derive(Debug, Clone, Serialize, Deserialize)]
172180
#[serde(untagged)]
@@ -1695,6 +1703,157 @@ impl SyntheticsAPI {
16951703
}
16961704
}
16971705

1706+
/// Fetch uptime for multiple Synthetic tests by ID.
1707+
pub async fn fetch_uptimes(
1708+
&self,
1709+
body: crate::datadogV1::model::SyntheticsFetchUptimesPayload,
1710+
) -> Result<Vec<crate::datadogV1::model::SyntheticsTestUptime>, datadog::Error<FetchUptimesError>>
1711+
{
1712+
match self.fetch_uptimes_with_http_info(body).await {
1713+
Ok(response_content) => {
1714+
if let Some(e) = response_content.entity {
1715+
Ok(e)
1716+
} else {
1717+
Err(datadog::Error::Serde(serde::de::Error::custom(
1718+
"response content was None",
1719+
)))
1720+
}
1721+
}
1722+
Err(err) => Err(err),
1723+
}
1724+
}
1725+
1726+
/// Fetch uptime for multiple Synthetic tests by ID.
1727+
pub async fn fetch_uptimes_with_http_info(
1728+
&self,
1729+
body: crate::datadogV1::model::SyntheticsFetchUptimesPayload,
1730+
) -> Result<
1731+
datadog::ResponseContent<Vec<crate::datadogV1::model::SyntheticsTestUptime>>,
1732+
datadog::Error<FetchUptimesError>,
1733+
> {
1734+
let local_configuration = &self.config;
1735+
let operation_id = "v1.fetch_uptimes";
1736+
1737+
let local_client = &self.client;
1738+
1739+
let local_uri_str = format!(
1740+
"{}/api/v1/synthetics/tests/uptimes",
1741+
local_configuration.get_operation_host(operation_id)
1742+
);
1743+
let mut local_req_builder =
1744+
local_client.request(reqwest::Method::POST, local_uri_str.as_str());
1745+
1746+
// build headers
1747+
let mut headers = HeaderMap::new();
1748+
headers.insert("Content-Type", HeaderValue::from_static("application/json"));
1749+
headers.insert("Accept", HeaderValue::from_static("application/json"));
1750+
1751+
// build user agent
1752+
match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1753+
Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1754+
Err(e) => {
1755+
log::warn!("Failed to parse user agent header: {e}, falling back to default");
1756+
headers.insert(
1757+
reqwest::header::USER_AGENT,
1758+
HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1759+
)
1760+
}
1761+
};
1762+
1763+
// build auth
1764+
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1765+
headers.insert(
1766+
"DD-API-KEY",
1767+
HeaderValue::from_str(local_key.key.as_str())
1768+
.expect("failed to parse DD-API-KEY header"),
1769+
);
1770+
};
1771+
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1772+
headers.insert(
1773+
"DD-APPLICATION-KEY",
1774+
HeaderValue::from_str(local_key.key.as_str())
1775+
.expect("failed to parse DD-APPLICATION-KEY header"),
1776+
);
1777+
};
1778+
1779+
// build body parameters
1780+
let output = Vec::new();
1781+
let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
1782+
if body.serialize(&mut ser).is_ok() {
1783+
if let Some(content_encoding) = headers.get("Content-Encoding") {
1784+
match content_encoding.to_str().unwrap_or_default() {
1785+
"gzip" => {
1786+
let mut enc = GzEncoder::new(Vec::new(), Compression::default());
1787+
let _ = enc.write_all(ser.into_inner().as_slice());
1788+
match enc.finish() {
1789+
Ok(buf) => {
1790+
local_req_builder = local_req_builder.body(buf);
1791+
}
1792+
Err(e) => return Err(datadog::Error::Io(e)),
1793+
}
1794+
}
1795+
"deflate" => {
1796+
let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
1797+
let _ = enc.write_all(ser.into_inner().as_slice());
1798+
match enc.finish() {
1799+
Ok(buf) => {
1800+
local_req_builder = local_req_builder.body(buf);
1801+
}
1802+
Err(e) => return Err(datadog::Error::Io(e)),
1803+
}
1804+
}
1805+
"zstd1" => {
1806+
let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
1807+
let _ = enc.write_all(ser.into_inner().as_slice());
1808+
match enc.finish() {
1809+
Ok(buf) => {
1810+
local_req_builder = local_req_builder.body(buf);
1811+
}
1812+
Err(e) => return Err(datadog::Error::Io(e)),
1813+
}
1814+
}
1815+
_ => {
1816+
local_req_builder = local_req_builder.body(ser.into_inner());
1817+
}
1818+
}
1819+
} else {
1820+
local_req_builder = local_req_builder.body(ser.into_inner());
1821+
}
1822+
}
1823+
1824+
local_req_builder = local_req_builder.headers(headers);
1825+
let local_req = local_req_builder.build()?;
1826+
log::debug!("request content: {:?}", local_req.body());
1827+
let local_resp = local_client.execute(local_req).await?;
1828+
1829+
let local_status = local_resp.status();
1830+
let local_content = local_resp.text().await?;
1831+
log::debug!("response content: {}", local_content);
1832+
1833+
if !local_status.is_client_error() && !local_status.is_server_error() {
1834+
match serde_json::from_str::<Vec<crate::datadogV1::model::SyntheticsTestUptime>>(
1835+
&local_content,
1836+
) {
1837+
Ok(e) => {
1838+
return Ok(datadog::ResponseContent {
1839+
status: local_status,
1840+
content: local_content,
1841+
entity: Some(e),
1842+
})
1843+
}
1844+
Err(e) => return Err(datadog::Error::Serde(e)),
1845+
};
1846+
} else {
1847+
let local_entity: Option<FetchUptimesError> = serde_json::from_str(&local_content).ok();
1848+
let local_error = datadog::ResponseContent {
1849+
status: local_status,
1850+
content: local_content,
1851+
entity: local_entity,
1852+
};
1853+
Err(datadog::Error::ResponseError(local_error))
1854+
}
1855+
}
1856+
16981857
/// Get the detailed configuration associated with
16991858
/// a Synthetic API test.
17001859
pub async fn get_api_test(

src/datadogV1/model/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1538,6 +1538,12 @@ pub mod model_synthetics_ci_test_body;
15381538
pub use self::model_synthetics_ci_test_body::SyntheticsCITestBody;
15391539
pub mod model_synthetics_ci_test;
15401540
pub use self::model_synthetics_ci_test::SyntheticsCITest;
1541+
pub mod model_synthetics_fetch_uptimes_payload;
1542+
pub use self::model_synthetics_fetch_uptimes_payload::SyntheticsFetchUptimesPayload;
1543+
pub mod model_synthetics_test_uptime;
1544+
pub use self::model_synthetics_test_uptime::SyntheticsTestUptime;
1545+
pub mod model_synthetics_uptime;
1546+
pub use self::model_synthetics_uptime::SyntheticsUptime;
15411547
pub mod model_synthetics_patch_test_body;
15421548
pub use self::model_synthetics_patch_test_body::SyntheticsPatchTestBody;
15431549
pub mod model_synthetics_patch_test_operation;

0 commit comments

Comments
 (0)