From 755ea2289c9ba99fbb697aed656f37d3cfd5a5b8 Mon Sep 17 00:00:00 2001 From: Sherzod Karimov Date: Thu, 12 Sep 2024 10:29:58 -0400 Subject: [PATCH 1/4] add support for top level indexing --- src/test/java/com/datadog/api/World.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/test/java/com/datadog/api/World.java b/src/test/java/com/datadog/api/World.java index 95dd0ede6d3..db18fa35f69 100644 --- a/src/test/java/com/datadog/api/World.java +++ b/src/test/java/com/datadog/api/World.java @@ -653,6 +653,9 @@ public static Object lookup(Object data, String path) Object result = data; for (String dotPart : path.split("\\.")) { for (String part : dotPart.split("\\[")) { + if (part == "") { + continue; + } if (part.contains("]")) { int index = Integer.parseInt(part.replaceAll("]", "")); result = List.class.cast(result).get(index); From 22d4e357b1a3e508ea79f856d32f0c43febff627 Mon Sep 17 00:00:00 2001 From: Kevin Zou Date: Thu, 12 Sep 2024 17:09:51 -0400 Subject: [PATCH 2/4] empty strings aren't equal --- src/test/java/com/datadog/api/World.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/datadog/api/World.java b/src/test/java/com/datadog/api/World.java index db18fa35f69..555b9dabe81 100644 --- a/src/test/java/com/datadog/api/World.java +++ b/src/test/java/com/datadog/api/World.java @@ -653,7 +653,7 @@ public static Object lookup(Object data, String path) Object result = data; for (String dotPart : path.split("\\.")) { for (String part : dotPart.split("\\[")) { - if (part == "") { + if (part.length() > 0) { continue; } if (part.contains("]")) { From 64628614a8f367f4715c943c3627cf4c8060bd8f Mon Sep 17 00:00:00 2001 From: Kevin Zou Date: Thu, 12 Sep 2024 17:14:20 -0400 Subject: [PATCH 3/4] oops we should be skipping when the length is zero --- src/test/java/com/datadog/api/World.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/datadog/api/World.java b/src/test/java/com/datadog/api/World.java index 555b9dabe81..d00db19210a 100644 --- a/src/test/java/com/datadog/api/World.java +++ b/src/test/java/com/datadog/api/World.java @@ -653,7 +653,7 @@ public static Object lookup(Object data, String path) Object result = data; for (String dotPart : path.split("\\.")) { for (String part : dotPart.split("\\[")) { - if (part.length() > 0) { + if (part.length() == 0) { continue; } if (part.contains("]")) { From 5ece78da72667e28321a837e03a713c0573567fc Mon Sep 17 00:00:00 2001 From: "ci.datadog-api-spec" Date: Wed, 2 Oct 2024 14:35:17 +0000 Subject: [PATCH 4/4] Regenerate client from commit 3b4747f4 of spec repo --- .apigentools-info | 8 +- .generator/schemas/v1/openapi.yaml | 143 +++++++++ examples/v1/synthetics/FetchUptimes.java | 33 ++ .../api/client/v1/api/SyntheticsApi.java | 134 +++++++++ .../model/SyntheticsFetchUptimesPayload.java | 209 +++++++++++++ .../client/v1/model/SyntheticsTestUptime.java | 219 ++++++++++++++ .../api/client/v1/model/SyntheticsUptime.java | 284 ++++++++++++++++++ ...turns_JSON_format_is_wrong_response.freeze | 1 + ...returns_JSON_format_is_wrong_response.json | 32 ++ ..._multiple_tests_returns_OK_response.freeze | 1 + ...or_multiple_tests_returns_OK_response.json | 32 ++ .../api/client/v1/api/synthetics.feature | 17 ++ .../com/datadog/api/client/v1/api/undo.json | 6 + 13 files changed, 1115 insertions(+), 4 deletions(-) create mode 100644 examples/v1/synthetics/FetchUptimes.java create mode 100644 src/main/java/com/datadog/api/client/v1/model/SyntheticsFetchUptimesPayload.java create mode 100644 src/main/java/com/datadog/api/client/v1/model/SyntheticsTestUptime.java create mode 100644 src/main/java/com/datadog/api/client/v1/model/SyntheticsUptime.java create mode 100644 src/test/resources/cassettes/features/v1/Fetch_uptime_for_multiple_tests_returns_JSON_format_is_wrong_response.freeze create mode 100644 src/test/resources/cassettes/features/v1/Fetch_uptime_for_multiple_tests_returns_JSON_format_is_wrong_response.json create mode 100644 src/test/resources/cassettes/features/v1/Fetch_uptime_for_multiple_tests_returns_OK_response.freeze create mode 100644 src/test/resources/cassettes/features/v1/Fetch_uptime_for_multiple_tests_returns_OK_response.json diff --git a/.apigentools-info b/.apigentools-info index da726c63917..0f379e97734 100644 --- a/.apigentools-info +++ b/.apigentools-info @@ -4,13 +4,13 @@ "spec_versions": { "v1": { "apigentools_version": "1.6.6", - "regenerated": "2024-10-02 13:39:23.929055", - "spec_repo_commit": "e02e4f4c" + "regenerated": "2024-10-02 14:33:44.583261", + "spec_repo_commit": "3b4747f4" }, "v2": { "apigentools_version": "1.6.6", - "regenerated": "2024-10-02 13:39:23.943702", - "spec_repo_commit": "e02e4f4c" + "regenerated": "2024-10-02 14:33:44.597775", + "spec_repo_commit": "3b4747f4" } } } \ No newline at end of file diff --git a/.generator/schemas/v1/openapi.yaml b/.generator/schemas/v1/openapi.yaml index fa65f3a5d10..28ad73f8c53 100644 --- a/.generator/schemas/v1/openapi.yaml +++ b/.generator/schemas/v1/openapi.yaml @@ -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: @@ -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. @@ -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: @@ -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. diff --git a/examples/v1/synthetics/FetchUptimes.java b/examples/v1/synthetics/FetchUptimes.java new file mode 100644 index 00000000000..408b60fdd94 --- /dev/null +++ b/examples/v1/synthetics/FetchUptimes.java @@ -0,0 +1,33 @@ +// Fetch uptime for multiple tests returns "OK." response + +import com.datadog.api.client.ApiClient; +import com.datadog.api.client.ApiException; +import com.datadog.api.client.v1.api.SyntheticsApi; +import com.datadog.api.client.v1.model.SyntheticsFetchUptimesPayload; +import com.datadog.api.client.v1.model.SyntheticsTestUptime; +import java.util.Collections; +import java.util.List; + +public class Example { + public static void main(String[] args) { + ApiClient defaultClient = ApiClient.getDefaultApiClient(); + SyntheticsApi apiInstance = new SyntheticsApi(defaultClient); + + SyntheticsFetchUptimesPayload body = + new SyntheticsFetchUptimesPayload() + .fromTs(1726041488L) + .publicIds(Collections.singletonList("p8m-9gw-nte")) + .toTs(1726055954L); + + try { + List result = apiInstance.fetchUptimes(body); + System.out.println(result); + } catch (ApiException e) { + System.err.println("Exception when calling SyntheticsApi#fetchUptimes"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + } + } +} diff --git a/src/main/java/com/datadog/api/client/v1/api/SyntheticsApi.java b/src/main/java/com/datadog/api/client/v1/api/SyntheticsApi.java index 7ac7671fe73..93c9848e2a6 100644 --- a/src/main/java/com/datadog/api/client/v1/api/SyntheticsApi.java +++ b/src/main/java/com/datadog/api/client/v1/api/SyntheticsApi.java @@ -13,6 +13,7 @@ import com.datadog.api.client.v1.model.SyntheticsCITestBody; import com.datadog.api.client.v1.model.SyntheticsDeleteTestsPayload; import com.datadog.api.client.v1.model.SyntheticsDeleteTestsResponse; +import com.datadog.api.client.v1.model.SyntheticsFetchUptimesPayload; import com.datadog.api.client.v1.model.SyntheticsGetAPITestLatestResultsResponse; import com.datadog.api.client.v1.model.SyntheticsGetBrowserTestLatestResultsResponse; import com.datadog.api.client.v1.model.SyntheticsGlobalVariable; @@ -25,6 +26,7 @@ import com.datadog.api.client.v1.model.SyntheticsPrivateLocation; import com.datadog.api.client.v1.model.SyntheticsPrivateLocationCreationResponse; import com.datadog.api.client.v1.model.SyntheticsTestDetails; +import com.datadog.api.client.v1.model.SyntheticsTestUptime; import com.datadog.api.client.v1.model.SyntheticsTriggerBody; import com.datadog.api.client.v1.model.SyntheticsTriggerCITestsResponse; import com.datadog.api.client.v1.model.SyntheticsUpdateTestPauseStatusPayload; @@ -1304,6 +1306,138 @@ public ApiResponse editGlobalVariableWithHttpInfo( new GenericType() {}); } + /** + * Fetch uptime for multiple tests. + * + *

See {@link #fetchUptimesWithHttpInfo}. + * + * @param body Public ID list of the Synthetic tests and timeframe. (required) + * @return List<SyntheticsTestUptime> + * @throws ApiException if fails to make API call + */ + public List fetchUptimes(SyntheticsFetchUptimesPayload body) + throws ApiException { + return fetchUptimesWithHttpInfo(body).getData(); + } + + /** + * Fetch uptime for multiple tests. + * + *

See {@link #fetchUptimesWithHttpInfoAsync}. + * + * @param body Public ID list of the Synthetic tests and timeframe. (required) + * @return CompletableFuture<List<SyntheticsTestUptime>> + */ + public CompletableFuture> fetchUptimesAsync( + SyntheticsFetchUptimesPayload body) { + return fetchUptimesWithHttpInfoAsync(body) + .thenApply( + response -> { + return response.getData(); + }); + } + + /** + * Fetch uptime for multiple Synthetic tests by ID. + * + * @param body Public ID list of the Synthetic tests and timeframe. (required) + * @return ApiResponse<List<SyntheticsTestUptime>> + * @throws ApiException if fails to make API call + * @http.response.details + * + * + * + * + * + * + * + *
Response details
Status Code Description Response Headers
200 OK. -
400 - JSON format is wrong -
403 Forbidden -
429 Too many requests -
+ */ + public ApiResponse> fetchUptimesWithHttpInfo( + SyntheticsFetchUptimesPayload body) throws ApiException { + Object localVarPostBody = body; + + // verify the required parameter 'body' is set + if (body == null) { + throw new ApiException( + 400, "Missing the required parameter 'body' when calling fetchUptimes"); + } + // create path and map variables + String localVarPath = "/api/v1/synthetics/tests/uptimes"; + + Map localVarHeaderParams = new HashMap(); + + Invocation.Builder builder = + apiClient.createBuilder( + "v1.SyntheticsApi.fetchUptimes", + localVarPath, + new ArrayList(), + localVarHeaderParams, + new HashMap(), + new String[] {"application/json"}, + new String[] {"AuthZ", "apiKeyAuth", "appKeyAuth"}); + return apiClient.invokeAPI( + "POST", + builder, + localVarHeaderParams, + new String[] {"application/json"}, + localVarPostBody, + new HashMap(), + false, + new GenericType>() {}); + } + + /** + * Fetch uptime for multiple tests. + * + *

See {@link #fetchUptimesWithHttpInfo}. + * + * @param body Public ID list of the Synthetic tests and timeframe. (required) + * @return CompletableFuture<ApiResponse<List<SyntheticsTestUptime>>> + */ + public CompletableFuture>> fetchUptimesWithHttpInfoAsync( + SyntheticsFetchUptimesPayload body) { + Object localVarPostBody = body; + + // verify the required parameter 'body' is set + if (body == null) { + CompletableFuture>> result = new CompletableFuture<>(); + result.completeExceptionally( + new ApiException(400, "Missing the required parameter 'body' when calling fetchUptimes")); + return result; + } + // create path and map variables + String localVarPath = "/api/v1/synthetics/tests/uptimes"; + + Map localVarHeaderParams = new HashMap(); + + Invocation.Builder builder; + try { + builder = + apiClient.createBuilder( + "v1.SyntheticsApi.fetchUptimes", + localVarPath, + new ArrayList(), + localVarHeaderParams, + new HashMap(), + new String[] {"application/json"}, + new String[] {"AuthZ", "apiKeyAuth", "appKeyAuth"}); + } catch (ApiException ex) { + CompletableFuture>> result = new CompletableFuture<>(); + result.completeExceptionally(ex); + return result; + } + return apiClient.invokeAPIAsync( + "POST", + builder, + localVarHeaderParams, + new String[] {"application/json"}, + localVarPostBody, + new HashMap(), + false, + new GenericType>() {}); + } + /** * Get an API test. * diff --git a/src/main/java/com/datadog/api/client/v1/model/SyntheticsFetchUptimesPayload.java b/src/main/java/com/datadog/api/client/v1/model/SyntheticsFetchUptimesPayload.java new file mode 100644 index 00000000000..24dec0efa14 --- /dev/null +++ b/src/main/java/com/datadog/api/client/v1/model/SyntheticsFetchUptimesPayload.java @@ -0,0 +1,209 @@ +/* + * Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. + * This product includes software developed at Datadog (https://www.datadoghq.com/). + * Copyright 2019-Present Datadog, Inc. + */ + +package com.datadog.api.client.v1.model; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +/** Object containing IDs of Synthetic tests and a timeframe. */ +@JsonPropertyOrder({ + SyntheticsFetchUptimesPayload.JSON_PROPERTY_FROM_TS, + SyntheticsFetchUptimesPayload.JSON_PROPERTY_PUBLIC_IDS, + SyntheticsFetchUptimesPayload.JSON_PROPERTY_TO_TS +}) +@jakarta.annotation.Generated( + value = "https://github.com/DataDog/datadog-api-client-java/blob/master/.generator") +public class SyntheticsFetchUptimesPayload { + @JsonIgnore public boolean unparsed = false; + public static final String JSON_PROPERTY_FROM_TS = "from_ts"; + private Long fromTs; + + public static final String JSON_PROPERTY_PUBLIC_IDS = "public_ids"; + private List publicIds = new ArrayList<>(); + + public static final String JSON_PROPERTY_TO_TS = "to_ts"; + private Long toTs; + + public SyntheticsFetchUptimesPayload() {} + + @JsonCreator + public SyntheticsFetchUptimesPayload( + @JsonProperty(required = true, value = JSON_PROPERTY_FROM_TS) Long fromTs, + @JsonProperty(required = true, value = JSON_PROPERTY_PUBLIC_IDS) List publicIds, + @JsonProperty(required = true, value = JSON_PROPERTY_TO_TS) Long toTs) { + this.fromTs = fromTs; + this.publicIds = publicIds; + this.toTs = toTs; + } + + public SyntheticsFetchUptimesPayload fromTs(Long fromTs) { + this.fromTs = fromTs; + return this; + } + + /** + * Timestamp in seconds (Unix epoch) for the start of uptime. + * + * @return fromTs + */ + @JsonProperty(JSON_PROPERTY_FROM_TS) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public Long getFromTs() { + return fromTs; + } + + public void setFromTs(Long fromTs) { + this.fromTs = fromTs; + } + + public SyntheticsFetchUptimesPayload publicIds(List publicIds) { + this.publicIds = publicIds; + return this; + } + + public SyntheticsFetchUptimesPayload addPublicIdsItem(String publicIdsItem) { + this.publicIds.add(publicIdsItem); + return this; + } + + /** + * An array of Synthetic test IDs you want to delete. + * + * @return publicIds + */ + @JsonProperty(JSON_PROPERTY_PUBLIC_IDS) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public List getPublicIds() { + return publicIds; + } + + public void setPublicIds(List publicIds) { + this.publicIds = publicIds; + } + + public SyntheticsFetchUptimesPayload toTs(Long toTs) { + this.toTs = toTs; + return this; + } + + /** + * Timestamp in seconds (Unix epoch) for the end of uptime. + * + * @return toTs + */ + @JsonProperty(JSON_PROPERTY_TO_TS) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public Long getToTs() { + return toTs; + } + + public void setToTs(Long toTs) { + this.toTs = toTs; + } + + /** + * A container for additional, undeclared properties. This is a holder for any undeclared + * properties as specified with the 'additionalProperties' keyword in the OAS document. + */ + private Map additionalProperties; + + /** + * Set the additional (undeclared) property with the specified name and value. If the property + * does not already exist, create it otherwise replace it. + * + * @param key The arbitrary key to set + * @param value The associated value + * @return SyntheticsFetchUptimesPayload + */ + @JsonAnySetter + public SyntheticsFetchUptimesPayload putAdditionalProperty(String key, Object value) { + if (this.additionalProperties == null) { + this.additionalProperties = new HashMap(); + } + this.additionalProperties.put(key, value); + return this; + } + + /** + * Return the additional (undeclared) property. + * + * @return The additional properties + */ + @JsonAnyGetter + public Map getAdditionalProperties() { + return additionalProperties; + } + + /** + * Return the additional (undeclared) property with the specified name. + * + * @param key The arbitrary key to get + * @return The specific additional property for the given key + */ + public Object getAdditionalProperty(String key) { + if (this.additionalProperties == null) { + return null; + } + return this.additionalProperties.get(key); + } + + /** Return true if this SyntheticsFetchUptimesPayload object is equal to o. */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + SyntheticsFetchUptimesPayload syntheticsFetchUptimesPayload = (SyntheticsFetchUptimesPayload) o; + return Objects.equals(this.fromTs, syntheticsFetchUptimesPayload.fromTs) + && Objects.equals(this.publicIds, syntheticsFetchUptimesPayload.publicIds) + && Objects.equals(this.toTs, syntheticsFetchUptimesPayload.toTs) + && Objects.equals( + this.additionalProperties, syntheticsFetchUptimesPayload.additionalProperties); + } + + @Override + public int hashCode() { + return Objects.hash(fromTs, publicIds, toTs, additionalProperties); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class SyntheticsFetchUptimesPayload {\n"); + sb.append(" fromTs: ").append(toIndentedString(fromTs)).append("\n"); + sb.append(" publicIds: ").append(toIndentedString(publicIds)).append("\n"); + sb.append(" toTs: ").append(toIndentedString(toTs)).append("\n"); + sb.append(" additionalProperties: ") + .append(toIndentedString(additionalProperties)) + .append("\n"); + sb.append('}'); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/src/main/java/com/datadog/api/client/v1/model/SyntheticsTestUptime.java b/src/main/java/com/datadog/api/client/v1/model/SyntheticsTestUptime.java new file mode 100644 index 00000000000..0fa7a8ad9e2 --- /dev/null +++ b/src/main/java/com/datadog/api/client/v1/model/SyntheticsTestUptime.java @@ -0,0 +1,219 @@ +/* + * Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. + * This product includes software developed at Datadog (https://www.datadoghq.com/). + * Copyright 2019-Present Datadog, Inc. + */ + +package com.datadog.api.client.v1.model; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +/** Object containing the uptime for a Synthetic test ID. */ +@JsonPropertyOrder({ + SyntheticsTestUptime.JSON_PROPERTY_FROM_TS, + SyntheticsTestUptime.JSON_PROPERTY_OVERALL, + SyntheticsTestUptime.JSON_PROPERTY_PUBLIC_ID, + SyntheticsTestUptime.JSON_PROPERTY_TO_TS +}) +@jakarta.annotation.Generated( + value = "https://github.com/DataDog/datadog-api-client-java/blob/master/.generator") +public class SyntheticsTestUptime { + @JsonIgnore public boolean unparsed = false; + public static final String JSON_PROPERTY_FROM_TS = "from_ts"; + private Long fromTs; + + public static final String JSON_PROPERTY_OVERALL = "overall"; + private SyntheticsUptime overall; + + public static final String JSON_PROPERTY_PUBLIC_ID = "public_id"; + private String publicId; + + public static final String JSON_PROPERTY_TO_TS = "to_ts"; + private Long toTs; + + public SyntheticsTestUptime fromTs(Long fromTs) { + this.fromTs = fromTs; + return this; + } + + /** + * Timestamp in seconds for the start of uptime. + * + * @return fromTs + */ + @jakarta.annotation.Nullable + @JsonProperty(JSON_PROPERTY_FROM_TS) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public Long getFromTs() { + return fromTs; + } + + public void setFromTs(Long fromTs) { + this.fromTs = fromTs; + } + + public SyntheticsTestUptime overall(SyntheticsUptime overall) { + this.overall = overall; + this.unparsed |= overall.unparsed; + return this; + } + + /** + * Object containing the uptime information. + * + * @return overall + */ + @jakarta.annotation.Nullable + @JsonProperty(JSON_PROPERTY_OVERALL) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public SyntheticsUptime getOverall() { + return overall; + } + + public void setOverall(SyntheticsUptime overall) { + this.overall = overall; + } + + public SyntheticsTestUptime publicId(String publicId) { + this.publicId = publicId; + return this; + } + + /** + * A Synthetic test ID. + * + * @return publicId + */ + @jakarta.annotation.Nullable + @JsonProperty(JSON_PROPERTY_PUBLIC_ID) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public String getPublicId() { + return publicId; + } + + public void setPublicId(String publicId) { + this.publicId = publicId; + } + + public SyntheticsTestUptime toTs(Long toTs) { + this.toTs = toTs; + return this; + } + + /** + * Timestamp in seconds for the end of uptime. + * + * @return toTs + */ + @jakarta.annotation.Nullable + @JsonProperty(JSON_PROPERTY_TO_TS) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public Long getToTs() { + return toTs; + } + + public void setToTs(Long toTs) { + this.toTs = toTs; + } + + /** + * A container for additional, undeclared properties. This is a holder for any undeclared + * properties as specified with the 'additionalProperties' keyword in the OAS document. + */ + private Map additionalProperties; + + /** + * Set the additional (undeclared) property with the specified name and value. If the property + * does not already exist, create it otherwise replace it. + * + * @param key The arbitrary key to set + * @param value The associated value + * @return SyntheticsTestUptime + */ + @JsonAnySetter + public SyntheticsTestUptime putAdditionalProperty(String key, Object value) { + if (this.additionalProperties == null) { + this.additionalProperties = new HashMap(); + } + this.additionalProperties.put(key, value); + return this; + } + + /** + * Return the additional (undeclared) property. + * + * @return The additional properties + */ + @JsonAnyGetter + public Map getAdditionalProperties() { + return additionalProperties; + } + + /** + * Return the additional (undeclared) property with the specified name. + * + * @param key The arbitrary key to get + * @return The specific additional property for the given key + */ + public Object getAdditionalProperty(String key) { + if (this.additionalProperties == null) { + return null; + } + return this.additionalProperties.get(key); + } + + /** Return true if this SyntheticsTestUptime object is equal to o. */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + SyntheticsTestUptime syntheticsTestUptime = (SyntheticsTestUptime) o; + return Objects.equals(this.fromTs, syntheticsTestUptime.fromTs) + && Objects.equals(this.overall, syntheticsTestUptime.overall) + && Objects.equals(this.publicId, syntheticsTestUptime.publicId) + && Objects.equals(this.toTs, syntheticsTestUptime.toTs) + && Objects.equals(this.additionalProperties, syntheticsTestUptime.additionalProperties); + } + + @Override + public int hashCode() { + return Objects.hash(fromTs, overall, publicId, toTs, additionalProperties); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class SyntheticsTestUptime {\n"); + sb.append(" fromTs: ").append(toIndentedString(fromTs)).append("\n"); + sb.append(" overall: ").append(toIndentedString(overall)).append("\n"); + sb.append(" publicId: ").append(toIndentedString(publicId)).append("\n"); + sb.append(" toTs: ").append(toIndentedString(toTs)).append("\n"); + sb.append(" additionalProperties: ") + .append(toIndentedString(additionalProperties)) + .append("\n"); + sb.append('}'); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/src/main/java/com/datadog/api/client/v1/model/SyntheticsUptime.java b/src/main/java/com/datadog/api/client/v1/model/SyntheticsUptime.java new file mode 100644 index 00000000000..aa8e2a79b61 --- /dev/null +++ b/src/main/java/com/datadog/api/client/v1/model/SyntheticsUptime.java @@ -0,0 +1,284 @@ +/* + * Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. + * This product includes software developed at Datadog (https://www.datadoghq.com/). + * Copyright 2019-Present Datadog, Inc. + */ + +package com.datadog.api.client.v1.model; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import org.openapitools.jackson.nullable.JsonNullable; + +/** Object containing the uptime information. */ +@JsonPropertyOrder({ + SyntheticsUptime.JSON_PROPERTY_ERRORS, + SyntheticsUptime.JSON_PROPERTY_GROUP, + SyntheticsUptime.JSON_PROPERTY_HISTORY, + SyntheticsUptime.JSON_PROPERTY_SPAN_PRECISION, + SyntheticsUptime.JSON_PROPERTY_UPTIME +}) +@jakarta.annotation.Generated( + value = "https://github.com/DataDog/datadog-api-client-java/blob/master/.generator") +public class SyntheticsUptime { + @JsonIgnore public boolean unparsed = false; + public static final String JSON_PROPERTY_ERRORS = "errors"; + private JsonNullable> errors = + JsonNullable.>undefined(); + + public static final String JSON_PROPERTY_GROUP = "group"; + private String group; + + public static final String JSON_PROPERTY_HISTORY = "history"; + private List> history = null; + + public static final String JSON_PROPERTY_SPAN_PRECISION = "span_precision"; + private Double spanPrecision; + + public static final String JSON_PROPERTY_UPTIME = "uptime"; + private Double uptime; + + public SyntheticsUptime errors(List errors) { + this.errors = JsonNullable.>of(errors); + return this; + } + + public SyntheticsUptime addErrorsItem(SLOHistoryResponseErrorWithType errorsItem) { + if (this.errors == null || !this.errors.isPresent()) { + this.errors = JsonNullable.>of(new ArrayList<>()); + } + try { + this.errors.get().add(errorsItem); + } catch (java.util.NoSuchElementException e) { + // this can never happen, as we make sure above that the value is present + } + return this; + } + + /** + * An array of error objects returned while querying the history data for the service level + * objective. + * + * @return errors + */ + @jakarta.annotation.Nullable + @JsonIgnore + public List getErrors() { + return errors.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_ERRORS) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public JsonNullable> getErrors_JsonNullable() { + return errors; + } + + @JsonProperty(JSON_PROPERTY_ERRORS) + public void setErrors_JsonNullable(JsonNullable> errors) { + this.errors = errors; + } + + public void setErrors(List errors) { + this.errors = JsonNullable.>of(errors); + } + + public SyntheticsUptime group(String group) { + this.group = group; + return this; + } + + /** + * The location name + * + * @return group + */ + @jakarta.annotation.Nullable + @JsonProperty(JSON_PROPERTY_GROUP) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public String getGroup() { + return group; + } + + public void setGroup(String group) { + this.group = group; + } + + public SyntheticsUptime history(List> history) { + this.history = history; + return this; + } + + public SyntheticsUptime addHistoryItem(List historyItem) { + if (this.history == null) { + this.history = new ArrayList<>(); + } + this.history.add(historyItem); + return this; + } + + /** + * 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. + * + * @return history + */ + @jakarta.annotation.Nullable + @JsonProperty(JSON_PROPERTY_HISTORY) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public List> getHistory() { + return history; + } + + public void setHistory(List> history) { + this.history = history; + } + + public SyntheticsUptime spanPrecision(Double spanPrecision) { + this.spanPrecision = spanPrecision; + return this; + } + + /** + * The number of decimal places to which the SLI value is accurate for the given from-to + * timestamps. + * + * @return spanPrecision + */ + @jakarta.annotation.Nullable + @JsonProperty(JSON_PROPERTY_SPAN_PRECISION) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public Double getSpanPrecision() { + return spanPrecision; + } + + public void setSpanPrecision(Double spanPrecision) { + this.spanPrecision = spanPrecision; + } + + public SyntheticsUptime uptime(Double uptime) { + this.uptime = uptime; + return this; + } + + /** + * The overall uptime. + * + * @return uptime + */ + @jakarta.annotation.Nullable + @JsonProperty(JSON_PROPERTY_UPTIME) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public Double getUptime() { + return uptime; + } + + public void setUptime(Double uptime) { + this.uptime = uptime; + } + + /** + * A container for additional, undeclared properties. This is a holder for any undeclared + * properties as specified with the 'additionalProperties' keyword in the OAS document. + */ + private Map additionalProperties; + + /** + * Set the additional (undeclared) property with the specified name and value. If the property + * does not already exist, create it otherwise replace it. + * + * @param key The arbitrary key to set + * @param value The associated value + * @return SyntheticsUptime + */ + @JsonAnySetter + public SyntheticsUptime putAdditionalProperty(String key, Object value) { + if (this.additionalProperties == null) { + this.additionalProperties = new HashMap(); + } + this.additionalProperties.put(key, value); + return this; + } + + /** + * Return the additional (undeclared) property. + * + * @return The additional properties + */ + @JsonAnyGetter + public Map getAdditionalProperties() { + return additionalProperties; + } + + /** + * Return the additional (undeclared) property with the specified name. + * + * @param key The arbitrary key to get + * @return The specific additional property for the given key + */ + public Object getAdditionalProperty(String key) { + if (this.additionalProperties == null) { + return null; + } + return this.additionalProperties.get(key); + } + + /** Return true if this SyntheticsUptime object is equal to o. */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + SyntheticsUptime syntheticsUptime = (SyntheticsUptime) o; + return Objects.equals(this.errors, syntheticsUptime.errors) + && Objects.equals(this.group, syntheticsUptime.group) + && Objects.equals(this.history, syntheticsUptime.history) + && Objects.equals(this.spanPrecision, syntheticsUptime.spanPrecision) + && Objects.equals(this.uptime, syntheticsUptime.uptime) + && Objects.equals(this.additionalProperties, syntheticsUptime.additionalProperties); + } + + @Override + public int hashCode() { + return Objects.hash(errors, group, history, spanPrecision, uptime, additionalProperties); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class SyntheticsUptime {\n"); + sb.append(" errors: ").append(toIndentedString(errors)).append("\n"); + sb.append(" group: ").append(toIndentedString(group)).append("\n"); + sb.append(" history: ").append(toIndentedString(history)).append("\n"); + sb.append(" spanPrecision: ").append(toIndentedString(spanPrecision)).append("\n"); + sb.append(" uptime: ").append(toIndentedString(uptime)).append("\n"); + sb.append(" additionalProperties: ") + .append(toIndentedString(additionalProperties)) + .append("\n"); + sb.append('}'); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/src/test/resources/cassettes/features/v1/Fetch_uptime_for_multiple_tests_returns_JSON_format_is_wrong_response.freeze b/src/test/resources/cassettes/features/v1/Fetch_uptime_for_multiple_tests_returns_JSON_format_is_wrong_response.freeze new file mode 100644 index 00000000000..0c15e075862 --- /dev/null +++ b/src/test/resources/cassettes/features/v1/Fetch_uptime_for_multiple_tests_returns_JSON_format_is_wrong_response.freeze @@ -0,0 +1 @@ +2024-10-02T14:22:00.562Z \ No newline at end of file diff --git a/src/test/resources/cassettes/features/v1/Fetch_uptime_for_multiple_tests_returns_JSON_format_is_wrong_response.json b/src/test/resources/cassettes/features/v1/Fetch_uptime_for_multiple_tests_returns_JSON_format_is_wrong_response.json new file mode 100644 index 00000000000..029cd04a838 --- /dev/null +++ b/src/test/resources/cassettes/features/v1/Fetch_uptime_for_multiple_tests_returns_JSON_format_is_wrong_response.json @@ -0,0 +1,32 @@ +[ + { + "httpRequest": { + "body": { + "type": "JSON", + "json": "{\"from_ts\":0,\"public_ids\":[],\"to_ts\":0}" + }, + "headers": {}, + "method": "POST", + "path": "/api/v1/synthetics/tests/uptimes", + "keepAlive": false, + "secure": true + }, + "httpResponse": { + "body": "{\"errors\":[\"Minimum number of elements in parameter 'public_ids' should be 1\"]}", + "headers": { + "Content-Type": [ + "application/json" + ] + }, + "statusCode": 400, + "reasonPhrase": "Bad Request" + }, + "times": { + "remainingTimes": 1 + }, + "timeToLive": { + "unlimited": true + }, + "id": "23da9bb7-4dd4-12c2-37ee-8406f9945944" + } +] \ No newline at end of file diff --git a/src/test/resources/cassettes/features/v1/Fetch_uptime_for_multiple_tests_returns_OK_response.freeze b/src/test/resources/cassettes/features/v1/Fetch_uptime_for_multiple_tests_returns_OK_response.freeze new file mode 100644 index 00000000000..87f1a868b8d --- /dev/null +++ b/src/test/resources/cassettes/features/v1/Fetch_uptime_for_multiple_tests_returns_OK_response.freeze @@ -0,0 +1 @@ +2024-09-11T13:09:28.349Z \ No newline at end of file diff --git a/src/test/resources/cassettes/features/v1/Fetch_uptime_for_multiple_tests_returns_OK_response.json b/src/test/resources/cassettes/features/v1/Fetch_uptime_for_multiple_tests_returns_OK_response.json new file mode 100644 index 00000000000..17a62f100e7 --- /dev/null +++ b/src/test/resources/cassettes/features/v1/Fetch_uptime_for_multiple_tests_returns_OK_response.json @@ -0,0 +1,32 @@ +[ + { + "httpRequest": { + "body": { + "type": "JSON", + "json": "{\"from_ts\":1726041488,\"public_ids\":[\"p8m-9gw-nte\"],\"to_ts\":1726055954}" + }, + "headers": {}, + "method": "POST", + "path": "/api/v1/synthetics/tests/uptimes", + "keepAlive": false, + "secure": true + }, + "httpResponse": { + "body": "[{\"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", + "headers": { + "Content-Type": [ + "application/json" + ] + }, + "statusCode": 200, + "reasonPhrase": "OK" + }, + "times": { + "remainingTimes": 1 + }, + "timeToLive": { + "unlimited": true + }, + "id": "5bb349ef-4e23-17c9-3873-95651078521d" + } +] \ No newline at end of file diff --git a/src/test/resources/com/datadog/api/client/v1/api/synthetics.feature b/src/test/resources/com/datadog/api/client/v1/api/synthetics.feature index d2e4068308d..c5e2eae1bdf 100644 --- a/src/test/resources/com/datadog/api/client/v1/api/synthetics.feature +++ b/src/test/resources/com/datadog/api/client/v1/api/synthetics.feature @@ -469,6 +469,23 @@ Feature: Synthetics Then the response status is 200 OK And the response "name" is equal to "{{ synthetics_api_test.name }}-updated" + @team:DataDog/synthetics-ct + Scenario: Fetch uptime for multiple tests returns "- JSON format is wrong" response + Given new "FetchUptimes" request + And body with value {"from_ts": 0, "public_ids": [], "to_ts": 0} + When the request is sent + Then the response status is 400 - JSON format is wrong + + @replay-only @team:DataDog/synthetics-ct + Scenario: Fetch uptime for multiple tests returns "OK." response + Given new "FetchUptimes" request + And body with value {"from_ts": 1726041488, "public_ids": ["p8m-9gw-nte"], "to_ts": 1726055954} + When the request is sent + Then the response status is 200 OK + And the response "[0].public_id" is equal to "p8m-9gw-nte" + And the response "[0].overall.uptime" is equal to 83.05682373046875 + And the response "[0].overall.history" has length 2 + @generated @skip @team:DataDog/synthetics-ct Scenario: Get a Mobile test returns "- Synthetic Monitoring is not activated for the user" response Given new "GetMobileTest" request diff --git a/src/test/resources/com/datadog/api/client/v1/api/undo.json b/src/test/resources/com/datadog/api/client/v1/api/undo.json index a6bfcfb9a25..85e17f2caf4 100644 --- a/src/test/resources/com/datadog/api/client/v1/api/undo.json +++ b/src/test/resources/com/datadog/api/client/v1/api/undo.json @@ -1233,6 +1233,12 @@ "type": "idempotent" } }, + "FetchUptimes": { + "tag": "Synthetics", + "undo": { + "type": "idempotent" + } + }, "GetTest": { "tag": "Synthetics", "undo": {