diff --git a/.apigentools-info b/.apigentools-info index 95accb04dbe..7e34c502f6d 100644 --- a/.apigentools-info +++ b/.apigentools-info @@ -4,13 +4,13 @@ "spec_versions": { "v1": { "apigentools_version": "1.6.6", - "regenerated": "2024-09-18 14:45:12.928672", - "spec_repo_commit": "bae57ce1" + "regenerated": "2024-09-20 14:33:45.623064", + "spec_repo_commit": "d7132162" }, "v2": { "apigentools_version": "1.6.6", - "regenerated": "2024-09-18 14:45:12.947003", - "spec_repo_commit": "bae57ce1" + "regenerated": "2024-09-20 14:33:45.638566", + "spec_repo_commit": "d7132162" } } } \ No newline at end of file diff --git a/.generator/schemas/v1/openapi.yaml b/.generator/schemas/v1/openapi.yaml index e45da8ea46d..3a15142ed16 100644 --- a/.generator/schemas/v1/openapi.yaml +++ b/.generator/schemas/v1/openapi.yaml @@ -15182,6 +15182,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: @@ -16481,6 +16507,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. @@ -16604,6 +16648,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: @@ -31307,6 +31407,49 @@ paths: tags: - Synthetics x-codegen-request-body-name: body + /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/api/datadogV1/api_synthetics.go b/api/datadogV1/api_synthetics.go index b3a7709e577..47cbe65ff15 100644 --- a/api/datadogV1/api_synthetics.go +++ b/api/datadogV1/api_synthetics.go @@ -578,6 +578,79 @@ func (a *SyntheticsApi) EditGlobalVariable(ctx _context.Context, variableId stri return localVarReturnValue, localVarHTTPResponse, nil } +// FetchUptimes Fetch uptime for multiple tests. +// Fetch uptime for multiple Synthetic tests by ID. +func (a *SyntheticsApi) FetchUptimes(ctx _context.Context, body SyntheticsFetchUptimesPayload) ([]SyntheticsTestUptime, *_nethttp.Response, error) { + var ( + localVarHTTPMethod = _nethttp.MethodPost + localVarPostBody interface{} + localVarReturnValue []SyntheticsTestUptime + ) + + localBasePath, err := a.Client.Cfg.ServerURLWithContext(ctx, "v1.SyntheticsApi.FetchUptimes") + if err != nil { + return localVarReturnValue, nil, datadog.GenericOpenAPIError{ErrorMessage: err.Error()} + } + + localVarPath := localBasePath + "/api/v1/synthetics/tests/uptimes" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := _neturl.Values{} + localVarFormParams := _neturl.Values{} + localVarHeaderParams["Content-Type"] = "application/json" + localVarHeaderParams["Accept"] = "application/json" + + // body params + localVarPostBody = &body + datadog.SetAuthKeys( + ctx, + &localVarHeaderParams, + [2]string{"apiKeyAuth", "DD-API-KEY"}, + [2]string{"appKeyAuth", "DD-APPLICATION-KEY"}, + ) + req, err := a.Client.PrepareRequest(ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, nil) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.Client.CallAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := datadog.ReadBody(localVarHTTPResponse) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := datadog.GenericOpenAPIError{ + ErrorBody: localVarBody, + ErrorMessage: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 || localVarHTTPResponse.StatusCode == 403 || localVarHTTPResponse.StatusCode == 429 { + var v APIErrorResponse + err = a.Client.Decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.ErrorModel = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.Client.Decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := datadog.GenericOpenAPIError{ + ErrorBody: localVarBody, + ErrorMessage: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + // GetAPITest Get an API test. // Get the detailed configuration associated with // a Synthetic API test. diff --git a/api/datadogV1/doc.go b/api/datadogV1/doc.go index 9d8b94fbd90..c535ce201d1 100644 --- a/api/datadogV1/doc.go +++ b/api/datadogV1/doc.go @@ -156,6 +156,7 @@ // - [SyntheticsApi.DeletePrivateLocation] // - [SyntheticsApi.DeleteTests] // - [SyntheticsApi.EditGlobalVariable] +// - [SyntheticsApi.FetchUptimes] // - [SyntheticsApi.GetAPITest] // - [SyntheticsApi.GetAPITestLatestResults] // - [SyntheticsApi.GetAPITestResult] diff --git a/api/datadogV1/model_synthetics_fetch_uptimes_payload.go b/api/datadogV1/model_synthetics_fetch_uptimes_payload.go new file mode 100644 index 00000000000..5fb2201982d --- /dev/null +++ b/api/datadogV1/model_synthetics_fetch_uptimes_payload.go @@ -0,0 +1,165 @@ +// 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 datadogV1 + +import ( + "fmt" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// SyntheticsFetchUptimesPayload Object containing IDs of Synthetic tests and a timeframe. +type SyntheticsFetchUptimesPayload struct { + // Timestamp in seconds (Unix epoch) for the start of uptime. + FromTs int64 `json:"from_ts"` + // An array of Synthetic test IDs you want to delete. + PublicIds []string `json:"public_ids"` + // Timestamp in seconds (Unix epoch) for the end of uptime. + ToTs int64 `json:"to_ts"` + // UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct + UnparsedObject map[string]interface{} `json:"-"` + AdditionalProperties map[string]interface{} `json:"-"` +} + +// NewSyntheticsFetchUptimesPayload instantiates a new SyntheticsFetchUptimesPayload object. +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed. +func NewSyntheticsFetchUptimesPayload(fromTs int64, publicIds []string, toTs int64) *SyntheticsFetchUptimesPayload { + this := SyntheticsFetchUptimesPayload{} + this.FromTs = fromTs + this.PublicIds = publicIds + this.ToTs = toTs + return &this +} + +// NewSyntheticsFetchUptimesPayloadWithDefaults instantiates a new SyntheticsFetchUptimesPayload object. +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set. +func NewSyntheticsFetchUptimesPayloadWithDefaults() *SyntheticsFetchUptimesPayload { + this := SyntheticsFetchUptimesPayload{} + return &this +} + +// GetFromTs returns the FromTs field value. +func (o *SyntheticsFetchUptimesPayload) GetFromTs() int64 { + if o == nil { + var ret int64 + return ret + } + return o.FromTs +} + +// GetFromTsOk returns a tuple with the FromTs field value +// and a boolean to check if the value has been set. +func (o *SyntheticsFetchUptimesPayload) GetFromTsOk() (*int64, bool) { + if o == nil { + return nil, false + } + return &o.FromTs, true +} + +// SetFromTs sets field value. +func (o *SyntheticsFetchUptimesPayload) SetFromTs(v int64) { + o.FromTs = v +} + +// GetPublicIds returns the PublicIds field value. +func (o *SyntheticsFetchUptimesPayload) GetPublicIds() []string { + if o == nil { + var ret []string + return ret + } + return o.PublicIds +} + +// GetPublicIdsOk returns a tuple with the PublicIds field value +// and a boolean to check if the value has been set. +func (o *SyntheticsFetchUptimesPayload) GetPublicIdsOk() (*[]string, bool) { + if o == nil { + return nil, false + } + return &o.PublicIds, true +} + +// SetPublicIds sets field value. +func (o *SyntheticsFetchUptimesPayload) SetPublicIds(v []string) { + o.PublicIds = v +} + +// GetToTs returns the ToTs field value. +func (o *SyntheticsFetchUptimesPayload) GetToTs() int64 { + if o == nil { + var ret int64 + return ret + } + return o.ToTs +} + +// GetToTsOk returns a tuple with the ToTs field value +// and a boolean to check if the value has been set. +func (o *SyntheticsFetchUptimesPayload) GetToTsOk() (*int64, bool) { + if o == nil { + return nil, false + } + return &o.ToTs, true +} + +// SetToTs sets field value. +func (o *SyntheticsFetchUptimesPayload) SetToTs(v int64) { + o.ToTs = v +} + +// MarshalJSON serializes the struct using spec logic. +func (o SyntheticsFetchUptimesPayload) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + toSerialize["from_ts"] = o.FromTs + toSerialize["public_ids"] = o.PublicIds + toSerialize["to_ts"] = o.ToTs + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *SyntheticsFetchUptimesPayload) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + FromTs *int64 `json:"from_ts"` + PublicIds *[]string `json:"public_ids"` + ToTs *int64 `json:"to_ts"` + }{} + if err = datadog.Unmarshal(bytes, &all); err != nil { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + if all.FromTs == nil { + return fmt.Errorf("required field from_ts missing") + } + if all.PublicIds == nil { + return fmt.Errorf("required field public_ids missing") + } + if all.ToTs == nil { + return fmt.Errorf("required field to_ts missing") + } + additionalProperties := make(map[string]interface{}) + if err = datadog.Unmarshal(bytes, &additionalProperties); err == nil { + datadog.DeleteKeys(additionalProperties, &[]string{"from_ts", "public_ids", "to_ts"}) + } else { + return err + } + o.FromTs = *all.FromTs + o.PublicIds = *all.PublicIds + o.ToTs = *all.ToTs + + if len(additionalProperties) > 0 { + o.AdditionalProperties = additionalProperties + } + + return nil +} diff --git a/api/datadogV1/model_synthetics_test_uptime.go b/api/datadogV1/model_synthetics_test_uptime.go new file mode 100644 index 00000000000..735815af9db --- /dev/null +++ b/api/datadogV1/model_synthetics_test_uptime.go @@ -0,0 +1,216 @@ +// 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 datadogV1 + +import ( + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// SyntheticsTestUptime Object containing the uptime for a Synthetic test ID. +type SyntheticsTestUptime struct { + // Timestamp in seconds for the start of uptime. + FromTs *int64 `json:"from_ts,omitempty"` + // Object containing the uptime information. + Overall *SyntheticsUptime `json:"overall,omitempty"` + // A Synthetic test ID. + PublicId *string `json:"public_id,omitempty"` + // Timestamp in seconds for the end of uptime. + ToTs *int64 `json:"to_ts,omitempty"` + // UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct + UnparsedObject map[string]interface{} `json:"-"` + AdditionalProperties map[string]interface{} `json:"-"` +} + +// NewSyntheticsTestUptime instantiates a new SyntheticsTestUptime object. +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed. +func NewSyntheticsTestUptime() *SyntheticsTestUptime { + this := SyntheticsTestUptime{} + return &this +} + +// NewSyntheticsTestUptimeWithDefaults instantiates a new SyntheticsTestUptime object. +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set. +func NewSyntheticsTestUptimeWithDefaults() *SyntheticsTestUptime { + this := SyntheticsTestUptime{} + return &this +} + +// GetFromTs returns the FromTs field value if set, zero value otherwise. +func (o *SyntheticsTestUptime) GetFromTs() int64 { + if o == nil || o.FromTs == nil { + var ret int64 + return ret + } + return *o.FromTs +} + +// GetFromTsOk returns a tuple with the FromTs field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *SyntheticsTestUptime) GetFromTsOk() (*int64, bool) { + if o == nil || o.FromTs == nil { + return nil, false + } + return o.FromTs, true +} + +// HasFromTs returns a boolean if a field has been set. +func (o *SyntheticsTestUptime) HasFromTs() bool { + return o != nil && o.FromTs != nil +} + +// SetFromTs gets a reference to the given int64 and assigns it to the FromTs field. +func (o *SyntheticsTestUptime) SetFromTs(v int64) { + o.FromTs = &v +} + +// GetOverall returns the Overall field value if set, zero value otherwise. +func (o *SyntheticsTestUptime) GetOverall() SyntheticsUptime { + if o == nil || o.Overall == nil { + var ret SyntheticsUptime + return ret + } + return *o.Overall +} + +// GetOverallOk returns a tuple with the Overall field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *SyntheticsTestUptime) GetOverallOk() (*SyntheticsUptime, bool) { + if o == nil || o.Overall == nil { + return nil, false + } + return o.Overall, true +} + +// HasOverall returns a boolean if a field has been set. +func (o *SyntheticsTestUptime) HasOverall() bool { + return o != nil && o.Overall != nil +} + +// SetOverall gets a reference to the given SyntheticsUptime and assigns it to the Overall field. +func (o *SyntheticsTestUptime) SetOverall(v SyntheticsUptime) { + o.Overall = &v +} + +// GetPublicId returns the PublicId field value if set, zero value otherwise. +func (o *SyntheticsTestUptime) GetPublicId() string { + if o == nil || o.PublicId == nil { + var ret string + return ret + } + return *o.PublicId +} + +// GetPublicIdOk returns a tuple with the PublicId field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *SyntheticsTestUptime) GetPublicIdOk() (*string, bool) { + if o == nil || o.PublicId == nil { + return nil, false + } + return o.PublicId, true +} + +// HasPublicId returns a boolean if a field has been set. +func (o *SyntheticsTestUptime) HasPublicId() bool { + return o != nil && o.PublicId != nil +} + +// SetPublicId gets a reference to the given string and assigns it to the PublicId field. +func (o *SyntheticsTestUptime) SetPublicId(v string) { + o.PublicId = &v +} + +// GetToTs returns the ToTs field value if set, zero value otherwise. +func (o *SyntheticsTestUptime) GetToTs() int64 { + if o == nil || o.ToTs == nil { + var ret int64 + return ret + } + return *o.ToTs +} + +// GetToTsOk returns a tuple with the ToTs field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *SyntheticsTestUptime) GetToTsOk() (*int64, bool) { + if o == nil || o.ToTs == nil { + return nil, false + } + return o.ToTs, true +} + +// HasToTs returns a boolean if a field has been set. +func (o *SyntheticsTestUptime) HasToTs() bool { + return o != nil && o.ToTs != nil +} + +// SetToTs gets a reference to the given int64 and assigns it to the ToTs field. +func (o *SyntheticsTestUptime) SetToTs(v int64) { + o.ToTs = &v +} + +// MarshalJSON serializes the struct using spec logic. +func (o SyntheticsTestUptime) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + if o.FromTs != nil { + toSerialize["from_ts"] = o.FromTs + } + if o.Overall != nil { + toSerialize["overall"] = o.Overall + } + if o.PublicId != nil { + toSerialize["public_id"] = o.PublicId + } + if o.ToTs != nil { + toSerialize["to_ts"] = o.ToTs + } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *SyntheticsTestUptime) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + FromTs *int64 `json:"from_ts,omitempty"` + Overall *SyntheticsUptime `json:"overall,omitempty"` + PublicId *string `json:"public_id,omitempty"` + ToTs *int64 `json:"to_ts,omitempty"` + }{} + if err = datadog.Unmarshal(bytes, &all); err != nil { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + additionalProperties := make(map[string]interface{}) + if err = datadog.Unmarshal(bytes, &additionalProperties); err == nil { + datadog.DeleteKeys(additionalProperties, &[]string{"from_ts", "overall", "public_id", "to_ts"}) + } else { + return err + } + + hasInvalidField := false + o.FromTs = all.FromTs + if all.Overall != nil && all.Overall.UnparsedObject != nil && o.UnparsedObject == nil { + hasInvalidField = true + } + o.Overall = all.Overall + o.PublicId = all.PublicId + o.ToTs = all.ToTs + + if len(additionalProperties) > 0 { + o.AdditionalProperties = additionalProperties + } + + if hasInvalidField { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + + return nil +} diff --git a/api/datadogV1/model_synthetics_uptime.go b/api/datadogV1/model_synthetics_uptime.go new file mode 100644 index 00000000000..76b0750e0d7 --- /dev/null +++ b/api/datadogV1/model_synthetics_uptime.go @@ -0,0 +1,247 @@ +// 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 datadogV1 + +import ( + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// SyntheticsUptime Object containing the uptime information. +type SyntheticsUptime struct { + // An array of error objects returned while querying the history data for the service level objective. + Errors []SLOHistoryResponseErrorWithType `json:"errors,omitempty"` + // The location name + Group *string `json:"group,omitempty"` + // 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. + History [][]float64 `json:"history,omitempty"` + // The number of decimal places to which the SLI value is accurate for the given from-to timestamps. + SpanPrecision *float64 `json:"span_precision,omitempty"` + // The overall uptime. + Uptime *float64 `json:"uptime,omitempty"` + // UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct + UnparsedObject map[string]interface{} `json:"-"` + AdditionalProperties map[string]interface{} `json:"-"` +} + +// NewSyntheticsUptime instantiates a new SyntheticsUptime object. +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed. +func NewSyntheticsUptime() *SyntheticsUptime { + this := SyntheticsUptime{} + return &this +} + +// NewSyntheticsUptimeWithDefaults instantiates a new SyntheticsUptime object. +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set. +func NewSyntheticsUptimeWithDefaults() *SyntheticsUptime { + this := SyntheticsUptime{} + return &this +} + +// GetErrors returns the Errors field value if set, zero value otherwise (both if not set or set to explicit null). +func (o *SyntheticsUptime) GetErrors() []SLOHistoryResponseErrorWithType { + if o == nil { + var ret []SLOHistoryResponseErrorWithType + return ret + } + return o.Errors +} + +// GetErrorsOk returns a tuple with the Errors field value if set, nil otherwise +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned. +func (o *SyntheticsUptime) GetErrorsOk() (*[]SLOHistoryResponseErrorWithType, bool) { + if o == nil || o.Errors == nil { + return nil, false + } + return &o.Errors, true +} + +// HasErrors returns a boolean if a field has been set. +func (o *SyntheticsUptime) HasErrors() bool { + return o != nil && o.Errors != nil +} + +// SetErrors gets a reference to the given []SLOHistoryResponseErrorWithType and assigns it to the Errors field. +func (o *SyntheticsUptime) SetErrors(v []SLOHistoryResponseErrorWithType) { + o.Errors = v +} + +// GetGroup returns the Group field value if set, zero value otherwise. +func (o *SyntheticsUptime) GetGroup() string { + if o == nil || o.Group == nil { + var ret string + return ret + } + return *o.Group +} + +// GetGroupOk returns a tuple with the Group field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *SyntheticsUptime) GetGroupOk() (*string, bool) { + if o == nil || o.Group == nil { + return nil, false + } + return o.Group, true +} + +// HasGroup returns a boolean if a field has been set. +func (o *SyntheticsUptime) HasGroup() bool { + return o != nil && o.Group != nil +} + +// SetGroup gets a reference to the given string and assigns it to the Group field. +func (o *SyntheticsUptime) SetGroup(v string) { + o.Group = &v +} + +// GetHistory returns the History field value if set, zero value otherwise. +func (o *SyntheticsUptime) GetHistory() [][]float64 { + if o == nil || o.History == nil { + var ret [][]float64 + return ret + } + return o.History +} + +// GetHistoryOk returns a tuple with the History field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *SyntheticsUptime) GetHistoryOk() (*[][]float64, bool) { + if o == nil || o.History == nil { + return nil, false + } + return &o.History, true +} + +// HasHistory returns a boolean if a field has been set. +func (o *SyntheticsUptime) HasHistory() bool { + return o != nil && o.History != nil +} + +// SetHistory gets a reference to the given [][]float64 and assigns it to the History field. +func (o *SyntheticsUptime) SetHistory(v [][]float64) { + o.History = v +} + +// GetSpanPrecision returns the SpanPrecision field value if set, zero value otherwise. +func (o *SyntheticsUptime) GetSpanPrecision() float64 { + if o == nil || o.SpanPrecision == nil { + var ret float64 + return ret + } + return *o.SpanPrecision +} + +// GetSpanPrecisionOk returns a tuple with the SpanPrecision field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *SyntheticsUptime) GetSpanPrecisionOk() (*float64, bool) { + if o == nil || o.SpanPrecision == nil { + return nil, false + } + return o.SpanPrecision, true +} + +// HasSpanPrecision returns a boolean if a field has been set. +func (o *SyntheticsUptime) HasSpanPrecision() bool { + return o != nil && o.SpanPrecision != nil +} + +// SetSpanPrecision gets a reference to the given float64 and assigns it to the SpanPrecision field. +func (o *SyntheticsUptime) SetSpanPrecision(v float64) { + o.SpanPrecision = &v +} + +// GetUptime returns the Uptime field value if set, zero value otherwise. +func (o *SyntheticsUptime) GetUptime() float64 { + if o == nil || o.Uptime == nil { + var ret float64 + return ret + } + return *o.Uptime +} + +// GetUptimeOk returns a tuple with the Uptime field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *SyntheticsUptime) GetUptimeOk() (*float64, bool) { + if o == nil || o.Uptime == nil { + return nil, false + } + return o.Uptime, true +} + +// HasUptime returns a boolean if a field has been set. +func (o *SyntheticsUptime) HasUptime() bool { + return o != nil && o.Uptime != nil +} + +// SetUptime gets a reference to the given float64 and assigns it to the Uptime field. +func (o *SyntheticsUptime) SetUptime(v float64) { + o.Uptime = &v +} + +// MarshalJSON serializes the struct using spec logic. +func (o SyntheticsUptime) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + if o.Errors != nil { + toSerialize["errors"] = o.Errors + } + if o.Group != nil { + toSerialize["group"] = o.Group + } + if o.History != nil { + toSerialize["history"] = o.History + } + if o.SpanPrecision != nil { + toSerialize["span_precision"] = o.SpanPrecision + } + if o.Uptime != nil { + toSerialize["uptime"] = o.Uptime + } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *SyntheticsUptime) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + Errors []SLOHistoryResponseErrorWithType `json:"errors,omitempty"` + Group *string `json:"group,omitempty"` + History [][]float64 `json:"history,omitempty"` + SpanPrecision *float64 `json:"span_precision,omitempty"` + Uptime *float64 `json:"uptime,omitempty"` + }{} + if err = datadog.Unmarshal(bytes, &all); err != nil { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + additionalProperties := make(map[string]interface{}) + if err = datadog.Unmarshal(bytes, &additionalProperties); err == nil { + datadog.DeleteKeys(additionalProperties, &[]string{"errors", "group", "history", "span_precision", "uptime"}) + } else { + return err + } + o.Errors = all.Errors + o.Group = all.Group + o.History = all.History + o.SpanPrecision = all.SpanPrecision + o.Uptime = all.Uptime + + if len(additionalProperties) > 0 { + o.AdditionalProperties = additionalProperties + } + + return nil +} diff --git a/examples/v1/synthetics/FetchUptimes.go b/examples/v1/synthetics/FetchUptimes.go new file mode 100644 index 00000000000..6fb96b46752 --- /dev/null +++ b/examples/v1/synthetics/FetchUptimes.go @@ -0,0 +1,36 @@ +// Fetch uptime for multiple tests returns "OK." response + +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" + "github.com/DataDog/datadog-api-client-go/v2/api/datadogV1" +) + +func main() { + body := datadogV1.SyntheticsFetchUptimesPayload{ + FromTs: 1726041488, + PublicIds: []string{ + "p8m-9gw-nte", + }, + ToTs: 1726055954, + } + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + api := datadogV1.NewSyntheticsApi(apiClient) + resp, r, err := api.FetchUptimes(ctx, body) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `SyntheticsApi.FetchUptimes`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `SyntheticsApi.FetchUptimes`:\n%s\n", responseContent) +} diff --git a/tests/scenarios/cassettes/TestScenarios/v1/Feature_Synthetics/Scenario_Fetch_uptime_for_multiple_tests_returns_OK._response.freeze b/tests/scenarios/cassettes/TestScenarios/v1/Feature_Synthetics/Scenario_Fetch_uptime_for_multiple_tests_returns_OK._response.freeze new file mode 100644 index 00000000000..87f1a868b8d --- /dev/null +++ b/tests/scenarios/cassettes/TestScenarios/v1/Feature_Synthetics/Scenario_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/tests/scenarios/cassettes/TestScenarios/v1/Feature_Synthetics/Scenario_Fetch_uptime_for_multiple_tests_returns_OK._response.yaml b/tests/scenarios/cassettes/TestScenarios/v1/Feature_Synthetics/Scenario_Fetch_uptime_for_multiple_tests_returns_OK._response.yaml new file mode 100644 index 00000000000..5e7466d7606 --- /dev/null +++ b/tests/scenarios/cassettes/TestScenarios/v1/Feature_Synthetics/Scenario_Fetch_uptime_for_multiple_tests_returns_OK._response.yaml @@ -0,0 +1,25 @@ +interactions: +- request: + body: | + {"from_ts":1726041488,"public_ids":["p8m-9gw-nte"],"to_ts":1726055954} + form: {} + headers: + Accept: + - application/json + Content-Type: + - application/json + id: 0 + method: POST + url: https://api.datadoghq.com/api/v1/synthetics/tests/uptimes + response: + 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":[]}] + + ' + code: 200 + duration: 0ms + headers: + Content-Type: + - application/json + status: 200 OK +version: 2 diff --git a/tests/scenarios/features/v1/synthetics.feature b/tests/scenarios/features/v1/synthetics.feature index 943f0f65588..db66fbf3955 100644 --- a/tests/scenarios/features/v1/synthetics.feature +++ b/tests/scenarios/features/v1/synthetics.feature @@ -413,6 +413,23 @@ Feature: Synthetics Then the response status is 200 OK And the response "name" is equal to "{{ synthetics_api_test.name }}-updated" + @generated @skip @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 browser test result returns "- Synthetic Monitoring is not activated for the user" response Given new "GetBrowserTestResult" request diff --git a/tests/scenarios/features/v1/undo.json b/tests/scenarios/features/v1/undo.json index 16982e7aa54..a39d7c99104 100644 --- a/tests/scenarios/features/v1/undo.json +++ b/tests/scenarios/features/v1/undo.json @@ -1208,6 +1208,12 @@ "type": "idempotent" } }, + "FetchUptimes": { + "tag": "Synthetics", + "undo": { + "type": "idempotent" + } + }, "GetTest": { "tag": "Synthetics", "undo": {