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 Synthetics endpoint to fetch uptimes in API spec #1984

Merged
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:18.542573",
"spec_repo_commit": "e02e4f4c"
"regenerated": "2024-10-02 14:33:47.262024",
"spec_repo_commit": "3b4747f4"
},
"v2": {
"apigentools_version": "1.6.6",
"regenerated": "2024-10-02 13:39:18.559270",
"spec_repo_commit": "e02e4f4c"
"regenerated": "2024-10-02 14:33:47.276476",
"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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2024-09-11T13:09:28.349Z

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions examples/v1/synthetics/FetchUptimes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Fetch uptime for multiple tests returns "OK." response

require "datadog_api_client"
api_instance = DatadogAPIClient::V1::SyntheticsAPI.new

body = DatadogAPIClient::V1::SyntheticsFetchUptimesPayload.new({
from_ts: 1726041488,
public_ids: [
"p8m-9gw-nte",
],
Comment on lines +8 to +10

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Quality Violation

Consider using the %W syntax instead (...read more)

The rule "Prefer %w to the literal array syntax" is a Ruby style guideline that encourages the use of %w notation instead of the traditional array syntax when defining arrays of strings. This rule is part of the Ruby community's efforts to promote readability and simplicity in Ruby code.

This rule is important because it helps to keep the code concise and easy to read. The %w notation allows you to define an array of strings without having to use quotes and commas. This can make the code cleaner and easier to understand, especially when dealing with large arrays.

To follow this rule, replace the traditional array syntax with the %w notation. For example, instead of writing ['foo', 'bar', 'baz'], you should write %w[foo bar baz]. This will create the same array, but in a more readable and concise way. By following this rule, you can help to make your Ruby code cleaner and easier to understand.

View in Datadog  Leave us feedback  Documentation

to_ts: 1726055954,
})
p api_instance.fetch_uptimes(body)
3 changes: 3 additions & 0 deletions features/scenarios_model_mapping.rb
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,9 @@
"v1.TriggerCITests" => {
"body" => "SyntheticsCITestBody",
},
"v1.FetchUptimes" => {
"body" => "SyntheticsFetchUptimesPayload",
},
Comment on lines +759 to +761

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Quality Violation

Consider using symbols instead of string hash keys (...read more)

In Ruby, it is a best practice to use symbols instead of strings as hash keys. This rule emphasizes that it's more efficient and idiomatic to use symbols for this purpose. Symbols are immutable and unique, which makes them ideal for identifying things, whereas strings are mutable and can create multiple objects for the same sequence of characters.

The importance of this rule lies in the performance and memory usage of your Ruby application. Using symbols as hash keys reduces memory usage because they are stored in memory only once during a Ruby process. This can make a significant difference in the efficiency of your application, especially when dealing with large data sets.

To ensure you're following good coding practices, always use symbols for hash keys unless there's a specific reason to use a string. A simple refactoring from values = { 'foo' => 42, 'bar' => 99, 'baz' => 123 } to values = { foo: 42, bar: 99, baz: 123 } will make your code compliant with this rule. This not only improves your code's performance but also makes it more readable and consistent with Ruby's conventions.

View in Datadog  Leave us feedback  Documentation

"v1.GetTest" => {
"public_id" => "String",
},
Expand Down
4 changes: 4 additions & 0 deletions features/support/templating.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ def lookup(dotted_path)
result = self
dotted_path.split('.').each do |dot_part|
dot_part.split('[').each do |part|
if part == ''
next
end

if part.include?(']')
index = part.to_i
result = result[index]
Expand Down
17 changes: 17 additions & 0 deletions features/v1/synthetics.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions features/v1/undo.json
Original file line number Diff line number Diff line change
Expand Up @@ -1233,6 +1233,12 @@
"type": "idempotent"
}
},
"FetchUptimes": {
"tag": "Synthetics",
"undo": {
"type": "idempotent"
}
},
"GetTest": {
"tag": "Synthetics",
"undo": {
Expand Down
3 changes: 3 additions & 0 deletions lib/datadog_api_client/inflector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,7 @@ def overrides
"v1.synthetics_delete_tests_response" => "SyntheticsDeleteTestsResponse",
"v1.synthetics_device" => "SyntheticsDevice",
"v1.synthetics_device_id" => "SyntheticsDeviceID",
"v1.synthetics_fetch_uptimes_payload" => "SyntheticsFetchUptimesPayload",
"v1.synthetics_get_api_test_latest_results_response" => "SyntheticsGetAPITestLatestResultsResponse",
"v1.synthetics_get_browser_test_latest_results_response" => "SyntheticsGetBrowserTestLatestResultsResponse",
"v1.synthetics_global_variable" => "SyntheticsGlobalVariable",
Expand Down Expand Up @@ -695,13 +696,15 @@ def overrides
"v1.synthetics_test_request_certificate_item" => "SyntheticsTestRequestCertificateItem",
"v1.synthetics_test_request_port" => "SyntheticsTestRequestPort",
"v1.synthetics_test_request_proxy" => "SyntheticsTestRequestProxy",
"v1.synthetics_test_uptime" => "SyntheticsTestUptime",
"v1.synthetics_timing" => "SyntheticsTiming",
"v1.synthetics_trigger_body" => "SyntheticsTriggerBody",
"v1.synthetics_trigger_ci_test_location" => "SyntheticsTriggerCITestLocation",
"v1.synthetics_trigger_ci_test_run_result" => "SyntheticsTriggerCITestRunResult",
"v1.synthetics_trigger_ci_tests_response" => "SyntheticsTriggerCITestsResponse",
"v1.synthetics_trigger_test" => "SyntheticsTriggerTest",
"v1.synthetics_update_test_pause_status_payload" => "SyntheticsUpdateTestPauseStatusPayload",
"v1.synthetics_uptime" => "SyntheticsUptime",
"v1.synthetics_variable_parser" => "SyntheticsVariableParser",
"v1.synthetics_warning_type" => "SyntheticsWarningType",
"v1.table_widget_cell_display_mode" => "TableWidgetCellDisplayMode",
Expand Down
Loading
Loading