Skip to content

Add Synthetics endpoint to fetch uptimes in API spec #272

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

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.6",
"regenerated": "2024-10-02 13:39:22.917984",
"spec_repo_commit": "e02e4f4c"
"regenerated": "2024-10-02 14:33:54.593908",
"spec_repo_commit": "3b4747f4"
},
"v2": {
"apigentools_version": "1.6.6",
"regenerated": "2024-10-02 13:39:22.933099",
"spec_repo_commit": "e02e4f4c"
"regenerated": "2024-10-02 14:33:54.609830",
"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
18 changes: 18 additions & 0 deletions examples/v1_synthetics_FetchUptimes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Fetch uptime for multiple tests returns "OK." response
use datadog_api_client::datadog;
use datadog_api_client::datadogV1::api_synthetics::SyntheticsAPI;
use datadog_api_client::datadogV1::model::SyntheticsFetchUptimesPayload;

#[tokio::main]
async fn main() {
let body =
SyntheticsFetchUptimesPayload::new(1726041488, vec!["p8m-9gw-nte".to_string()], 1726055954);
let configuration = datadog::Configuration::new();
let api = SyntheticsAPI::with_config(configuration);
let resp = api.fetch_uptimes(body).await;
if let Ok(value) = resp {
println!("{:#?}", value);
} else {
println!("{:#?}", resp.unwrap_err());
}
}
159 changes: 159 additions & 0 deletions src/datadogV1/api/api_synthetics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,14 @@ pub enum EditGlobalVariableError {
UnknownValue(serde_json::Value),
}

/// FetchUptimesError is a struct for typed errors of method [`SyntheticsAPI::fetch_uptimes`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum FetchUptimesError {
APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}

/// GetAPITestError is a struct for typed errors of method [`SyntheticsAPI::get_api_test`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
Expand Down Expand Up @@ -1695,6 +1703,157 @@ impl SyntheticsAPI {
}
}

/// Fetch uptime for multiple Synthetic tests by ID.
pub async fn fetch_uptimes(
&self,
body: crate::datadogV1::model::SyntheticsFetchUptimesPayload,
) -> Result<Vec<crate::datadogV1::model::SyntheticsTestUptime>, datadog::Error<FetchUptimesError>>
{
match self.fetch_uptimes_with_http_info(body).await {
Ok(response_content) => {
if let Some(e) = response_content.entity {
Ok(e)
} else {
Err(datadog::Error::Serde(serde::de::Error::custom(
"response content was None",
)))
}
}
Err(err) => Err(err),
}
}

/// Fetch uptime for multiple Synthetic tests by ID.
pub async fn fetch_uptimes_with_http_info(
&self,
body: crate::datadogV1::model::SyntheticsFetchUptimesPayload,
) -> Result<
datadog::ResponseContent<Vec<crate::datadogV1::model::SyntheticsTestUptime>>,
datadog::Error<FetchUptimesError>,
> {
let local_configuration = &self.config;
let operation_id = "v1.fetch_uptimes";

let local_client = &self.client;

let local_uri_str = format!(
"{}/api/v1/synthetics/tests/uptimes",
local_configuration.get_operation_host(operation_id)
);
let mut local_req_builder =
local_client.request(reqwest::Method::POST, local_uri_str.as_str());

// build headers
let mut headers = HeaderMap::new();
headers.insert("Content-Type", HeaderValue::from_static("application/json"));
headers.insert("Accept", HeaderValue::from_static("application/json"));

// build user agent
match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
Err(e) => {
log::warn!("Failed to parse user agent header: {e}, falling back to default");
headers.insert(
reqwest::header::USER_AGENT,
HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
)
}
};

// build auth
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
headers.insert(
"DD-API-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-API-KEY header"),
);
};
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
headers.insert(
"DD-APPLICATION-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-APPLICATION-KEY header"),
);
};

// build body parameters
let output = Vec::new();
let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
if body.serialize(&mut ser).is_ok() {
if let Some(content_encoding) = headers.get("Content-Encoding") {
match content_encoding.to_str().unwrap_or_default() {
"gzip" => {
let mut enc = GzEncoder::new(Vec::new(), Compression::default());
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
"deflate" => {
let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
"zstd1" => {
let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
_ => {
local_req_builder = local_req_builder.body(ser.into_inner());
}
}
} else {
local_req_builder = local_req_builder.body(ser.into_inner());
}
}

local_req_builder = local_req_builder.headers(headers);
let local_req = local_req_builder.build()?;
log::debug!("request content: {:?}", local_req.body());
let local_resp = local_client.execute(local_req).await?;

let local_status = local_resp.status();
let local_content = local_resp.text().await?;
log::debug!("response content: {}", local_content);

if !local_status.is_client_error() && !local_status.is_server_error() {
match serde_json::from_str::<Vec<crate::datadogV1::model::SyntheticsTestUptime>>(
&local_content,
) {
Ok(e) => {
return Ok(datadog::ResponseContent {
status: local_status,
content: local_content,
entity: Some(e),
})
}
Err(e) => return Err(datadog::Error::Serde(e)),
};
} else {
let local_entity: Option<FetchUptimesError> = serde_json::from_str(&local_content).ok();
let local_error = datadog::ResponseContent {
status: local_status,
content: local_content,
entity: local_entity,
};
Err(datadog::Error::ResponseError(local_error))
}
}

/// Get the detailed configuration associated with
/// a Synthetic API test.
pub async fn get_api_test(
Expand Down
6 changes: 6 additions & 0 deletions src/datadogV1/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1538,6 +1538,12 @@ pub mod model_synthetics_ci_test_body;
pub use self::model_synthetics_ci_test_body::SyntheticsCITestBody;
pub mod model_synthetics_ci_test;
pub use self::model_synthetics_ci_test::SyntheticsCITest;
pub mod model_synthetics_fetch_uptimes_payload;
pub use self::model_synthetics_fetch_uptimes_payload::SyntheticsFetchUptimesPayload;
pub mod model_synthetics_test_uptime;
pub use self::model_synthetics_test_uptime::SyntheticsTestUptime;
pub mod model_synthetics_uptime;
pub use self::model_synthetics_uptime::SyntheticsUptime;
pub mod model_synthetics_patch_test_body;
pub use self::model_synthetics_patch_test_body::SyntheticsPatchTestBody;
pub mod model_synthetics_patch_test_operation;
Expand Down
Loading
Loading