diff --git a/.generator/schemas/v2/openapi.yaml b/.generator/schemas/v2/openapi.yaml index a7568e05b1d..af969a3d7f0 100644 --- a/.generator/schemas/v2/openapi.yaml +++ b/.generator/schemas/v2/openapi.yaml @@ -346,6 +346,16 @@ components: required: true schema: type: string + DisableCorrections: + description: Whether to exclude correction windows from the SLO status calculation. + Defaults to false. + in: query + name: disable_corrections + required: false + schema: + default: false + example: false + type: boolean EntityID: description: UUID or Entity Ref. in: path @@ -457,6 +467,15 @@ components: required: false schema: $ref: '#/components/schemas/RelationType' + FromTimestamp: + description: The starting timestamp for the SLO status query in epoch seconds. + in: query + name: from_ts + required: true + schema: + example: 1690901870 + format: int64 + type: integer GCPSTSServiceAccountID: description: Your GCP STS enabled service account's unique ID. in: path @@ -1104,6 +1123,14 @@ components: required: false schema: type: boolean + SloID: + description: The ID of the SLO. + in: path + name: slo_id + required: true + schema: + example: 00000000-0000-0000-0000-000000000000 + type: string SpansMetricIDParameter: description: The name of the span-based metric. in: path @@ -1125,6 +1152,15 @@ components: required: true schema: type: string + ToTimestamp: + description: The ending timestamp for the SLO status query in epoch seconds. + in: query + name: to_ts + required: true + schema: + example: 1706803070 + format: int64 + type: integer UserID: description: The ID of the user. in: path @@ -46850,6 +46886,22 @@ components: from the other indexes type: string type: object + RawErrorBudgetRemaining: + description: The raw error budget remaining for the SLO. + properties: + unit: + description: The unit of the error budget (for example, `seconds`, `requests`). + example: seconds + type: string + value: + description: The numeric value of the remaining error budget. + example: 86400.5 + format: double + type: number + required: + - value + - unit + type: object ReadinessGate: description: Used to merge multiple branches into a single branch. properties: @@ -57827,6 +57879,70 @@ components: required: - attributes type: object + SloStatusData: + description: The data portion of the SLO status response. + properties: + attributes: + $ref: '#/components/schemas/SloStatusDataAttributes' + id: + description: The ID of the SLO. + example: 00000000-0000-0000-0000-000000000000 + type: string + type: + $ref: '#/components/schemas/SloStatusType' + required: + - id + - type + - attributes + type: object + SloStatusDataAttributes: + description: The attributes of the SLO status. + properties: + error_budget_remaining: + description: The percentage of error budget remaining. + example: 99.5 + format: double + type: number + raw_error_budget_remaining: + $ref: '#/components/schemas/RawErrorBudgetRemaining' + sli: + description: The current Service Level Indicator (SLI) value as a percentage. + example: 99.95 + format: double + type: number + span_precision: + description: The precision of the time span in seconds. + example: 2 + format: int64 + type: integer + state: + description: The current state of the SLO (for example, `breached`, `warning`, + `ok`). + example: ok + type: string + required: + - sli + - error_budget_remaining + - raw_error_budget_remaining + - state + - span_precision + type: object + SloStatusResponse: + description: The SLO status response. + properties: + data: + $ref: '#/components/schemas/SloStatusData' + required: + - data + type: object + SloStatusType: + description: The type of the SLO status resource. + enum: + - slo_status + example: slo_status + type: string + x-enum-varnames: + - SLO_STATUS SoftwareCatalogTriggerWrapper: description: Schema for a Software Catalog-based trigger. properties: @@ -87913,6 +88029,8 @@ paths: - Logs Pipelines: `logs-pipeline` + - Case Management Projects: `case-management-project` + #### Supported relations for resources @@ -87964,7 +88082,9 @@ paths: On-Call Team Routing Rules | `viewer`, `editor` - Logs Pipelines | `viewer`, `processors_editor`, `editor`' + Logs Pipelines | `viewer`, `processors_editor`, `editor` + + Case Management Projects | `viewer`, `contributor`, `manager`' operationId: UpdateRestrictionPolicy parameters: - $ref: '#/components/parameters/ResourceID' @@ -94439,6 +94559,63 @@ paths: x-unstable: '**Note**: This feature is in private beta. To request access, use the request access form in the [Service Level Objectives](https://docs.datadoghq.com/service_management/service_level_objectives/#slo-csv-export) docs.' + /api/v2/slo/{slo_id}/status: + get: + description: 'Get the status of a Service Level Objective (SLO) for a given + time period. + + + This endpoint returns the current SLI value, error budget remaining, and other + status information for the specified SLO.' + operationId: GetSloStatus + parameters: + - $ref: '#/components/parameters/SloID' + - $ref: '#/components/parameters/FromTimestamp' + - $ref: '#/components/parameters/ToTimestamp' + - $ref: '#/components/parameters/DisableCorrections' + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/SloStatusResponse' + description: OK + '400': + content: + application/json: + schema: + $ref: '#/components/schemas/JSONAPIErrorResponse' + description: Bad Request + '403': + content: + application/json: + schema: + $ref: '#/components/schemas/JSONAPIErrorResponse' + description: Forbidden + '404': + content: + application/json: + schema: + $ref: '#/components/schemas/JSONAPIErrorResponse' + description: Not Found + '429': + $ref: '#/components/responses/TooManyRequestsResponse' + security: + - apiKeyAuth: [] + appKeyAuth: [] + - AuthZ: + - slos_read + summary: Get SLO status + tags: + - Service Level Objectives + x-permission: + operator: OR + permissions: + - slos_read + x-unstable: '**Note**: This endpoint is in public beta and it''s subject to + change. + + If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/).' /api/v2/spa/recommendations/{service}: get: description: This endpoint is currently experimental and restricted to Datadog diff --git a/api/datadog/configuration.go b/api/datadog/configuration.go index a952f8795ac..f759a0dda3e 100644 --- a/api/datadog/configuration.go +++ b/api/datadog/configuration.go @@ -813,6 +813,7 @@ func NewConfiguration() *Configuration { "v2.CreateSLOReportJob": false, "v2.GetSLOReport": false, "v2.GetSLOReportJobStatus": false, + "v2.GetSloStatus": false, "v2.GetSPARecommendations": false, "v2.GetSPARecommendationsWithShard": false, "v2.CreateCustomRule": false, diff --git a/api/datadogV2/api_restriction_policies.go b/api/datadogV2/api_restriction_policies.go index 74a34750b1d..facfda64eb2 100644 --- a/api/datadogV2/api_restriction_policies.go +++ b/api/datadogV2/api_restriction_policies.go @@ -206,6 +206,7 @@ func (r *UpdateRestrictionPolicyOptionalParameters) WithAllowSelfLockout(allowSe // - On-Call Escalation Policies: `on-call-escalation-policy` // - On-Call Team Routing Rules: `on-call-team-routing-rules` // - Logs Pipelines: `logs-pipeline` +// - Case Management Projects: `case-management-project` // // #### Supported relations for resources // Resource Type | Supported Relations @@ -233,6 +234,7 @@ func (r *UpdateRestrictionPolicyOptionalParameters) WithAllowSelfLockout(allowSe // On-Call Escalation Policies | `viewer`, `editor` // On-Call Team Routing Rules | `viewer`, `editor` // Logs Pipelines | `viewer`, `processors_editor`, `editor` +// Case Management Projects | `viewer`, `contributor`, `manager` func (a *RestrictionPoliciesApi) UpdateRestrictionPolicy(ctx _context.Context, resourceId string, body RestrictionPolicyUpdateRequest, o ...UpdateRestrictionPolicyOptionalParameters) (RestrictionPolicyResponse, *_nethttp.Response, error) { var ( localVarHTTPMethod = _nethttp.MethodPost diff --git a/api/datadogV2/api_service_level_objectives.go b/api/datadogV2/api_service_level_objectives.go index c4a0dc76929..8c4074d33a5 100644 --- a/api/datadogV2/api_service_level_objectives.go +++ b/api/datadogV2/api_service_level_objectives.go @@ -284,6 +284,134 @@ func (a *ServiceLevelObjectivesApi) GetSLOReportJobStatus(ctx _context.Context, return localVarReturnValue, localVarHTTPResponse, nil } +// GetSloStatusOptionalParameters holds optional parameters for GetSloStatus. +type GetSloStatusOptionalParameters struct { + DisableCorrections *bool +} + +// NewGetSloStatusOptionalParameters creates an empty struct for parameters. +func NewGetSloStatusOptionalParameters() *GetSloStatusOptionalParameters { + this := GetSloStatusOptionalParameters{} + return &this +} + +// WithDisableCorrections sets the corresponding parameter name and returns the struct. +func (r *GetSloStatusOptionalParameters) WithDisableCorrections(disableCorrections bool) *GetSloStatusOptionalParameters { + r.DisableCorrections = &disableCorrections + return r +} + +// GetSloStatus Get SLO status. +// Get the status of a Service Level Objective (SLO) for a given time period. +// +// This endpoint returns the current SLI value, error budget remaining, and other status information for the specified SLO. +func (a *ServiceLevelObjectivesApi) GetSloStatus(ctx _context.Context, sloId string, fromTs int64, toTs int64, o ...GetSloStatusOptionalParameters) (SloStatusResponse, *_nethttp.Response, error) { + var ( + localVarHTTPMethod = _nethttp.MethodGet + localVarPostBody interface{} + localVarReturnValue SloStatusResponse + optionalParams GetSloStatusOptionalParameters + ) + + if len(o) > 1 { + return localVarReturnValue, nil, datadog.ReportError("only one argument of type GetSloStatusOptionalParameters is allowed") + } + if len(o) == 1 { + optionalParams = o[0] + } + + operationId := "v2.GetSloStatus" + isOperationEnabled := a.Client.Cfg.IsUnstableOperationEnabled(operationId) + if !isOperationEnabled { + return localVarReturnValue, nil, datadog.GenericOpenAPIError{ErrorMessage: _fmt.Sprintf("Unstable operation '%s' is disabled", operationId)} + } + if isOperationEnabled && a.Client.Cfg.Debug { + _log.Printf("WARNING: Using unstable operation '%s'", operationId) + } + + localBasePath, err := a.Client.Cfg.ServerURLWithContext(ctx, "v2.ServiceLevelObjectivesApi.GetSloStatus") + if err != nil { + return localVarReturnValue, nil, datadog.GenericOpenAPIError{ErrorMessage: err.Error()} + } + + localVarPath := localBasePath + "/api/v2/slo/{slo_id}/status" + localVarPath = datadog.ReplacePathParameter(localVarPath, "{slo_id}", _neturl.PathEscape(datadog.ParameterToString(sloId, ""))) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := _neturl.Values{} + localVarFormParams := _neturl.Values{} + localVarQueryParams.Add("from_ts", datadog.ParameterToString(fromTs, "")) + localVarQueryParams.Add("to_ts", datadog.ParameterToString(toTs, "")) + if optionalParams.DisableCorrections != nil { + localVarQueryParams.Add("disable_corrections", datadog.ParameterToString(*optionalParams.DisableCorrections, "")) + } + localVarHeaderParams["Accept"] = "application/json" + + if a.Client.Cfg.DelegatedTokenConfig != nil { + err = datadog.UseDelegatedTokenAuth(ctx, &localVarHeaderParams, a.Client.Cfg.DelegatedTokenConfig) + if err != nil { + return localVarReturnValue, nil, err + } + } else { + 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 == 404 { + var v JSONAPIErrorResponse + 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 + } + if 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 +} + // NewServiceLevelObjectivesApi Returns NewServiceLevelObjectivesApi. func NewServiceLevelObjectivesApi(client *datadog.APIClient) *ServiceLevelObjectivesApi { return &ServiceLevelObjectivesApi{ diff --git a/api/datadogV2/doc.go b/api/datadogV2/doc.go index bfd10e6523f..8f75b477557 100644 --- a/api/datadogV2/doc.go +++ b/api/datadogV2/doc.go @@ -665,6 +665,7 @@ // - [ServiceLevelObjectivesApi.CreateSLOReportJob] // - [ServiceLevelObjectivesApi.GetSLOReport] // - [ServiceLevelObjectivesApi.GetSLOReportJobStatus] +// - [ServiceLevelObjectivesApi.GetSloStatus] // - [ServiceScorecardsApi.CreateScorecardOutcomesBatch] // - [ServiceScorecardsApi.CreateScorecardRule] // - [ServiceScorecardsApi.DeleteScorecardRule] diff --git a/api/datadogV2/model_raw_error_budget_remaining.go b/api/datadogV2/model_raw_error_budget_remaining.go new file mode 100644 index 00000000000..d506ff44a8d --- /dev/null +++ b/api/datadogV2/model_raw_error_budget_remaining.go @@ -0,0 +1,133 @@ +// 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 datadogV2 + +import ( + "fmt" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// RawErrorBudgetRemaining The raw error budget remaining for the SLO. +type RawErrorBudgetRemaining struct { + // The unit of the error budget (for example, `seconds`, `requests`). + Unit string `json:"unit"` + // The numeric value of the remaining error budget. + Value float64 `json:"value"` + // 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:"-"` +} + +// NewRawErrorBudgetRemaining instantiates a new RawErrorBudgetRemaining 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 NewRawErrorBudgetRemaining(unit string, value float64) *RawErrorBudgetRemaining { + this := RawErrorBudgetRemaining{} + this.Unit = unit + this.Value = value + return &this +} + +// NewRawErrorBudgetRemainingWithDefaults instantiates a new RawErrorBudgetRemaining 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 NewRawErrorBudgetRemainingWithDefaults() *RawErrorBudgetRemaining { + this := RawErrorBudgetRemaining{} + return &this +} + +// GetUnit returns the Unit field value. +func (o *RawErrorBudgetRemaining) GetUnit() string { + if o == nil { + var ret string + return ret + } + return o.Unit +} + +// GetUnitOk returns a tuple with the Unit field value +// and a boolean to check if the value has been set. +func (o *RawErrorBudgetRemaining) GetUnitOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Unit, true +} + +// SetUnit sets field value. +func (o *RawErrorBudgetRemaining) SetUnit(v string) { + o.Unit = v +} + +// GetValue returns the Value field value. +func (o *RawErrorBudgetRemaining) GetValue() float64 { + if o == nil { + var ret float64 + return ret + } + return o.Value +} + +// GetValueOk returns a tuple with the Value field value +// and a boolean to check if the value has been set. +func (o *RawErrorBudgetRemaining) GetValueOk() (*float64, bool) { + if o == nil { + return nil, false + } + return &o.Value, true +} + +// SetValue sets field value. +func (o *RawErrorBudgetRemaining) SetValue(v float64) { + o.Value = v +} + +// MarshalJSON serializes the struct using spec logic. +func (o RawErrorBudgetRemaining) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + toSerialize["unit"] = o.Unit + toSerialize["value"] = o.Value + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *RawErrorBudgetRemaining) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + Unit *string `json:"unit"` + Value *float64 `json:"value"` + }{} + if err = datadog.Unmarshal(bytes, &all); err != nil { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + if all.Unit == nil { + return fmt.Errorf("required field unit missing") + } + if all.Value == nil { + return fmt.Errorf("required field value missing") + } + additionalProperties := make(map[string]interface{}) + if err = datadog.Unmarshal(bytes, &additionalProperties); err == nil { + datadog.DeleteKeys(additionalProperties, &[]string{"unit", "value"}) + } else { + return err + } + o.Unit = *all.Unit + o.Value = *all.Value + + if len(additionalProperties) > 0 { + o.AdditionalProperties = additionalProperties + } + + return nil +} diff --git a/api/datadogV2/model_slo_status_data.go b/api/datadogV2/model_slo_status_data.go new file mode 100644 index 00000000000..06cc26ad192 --- /dev/null +++ b/api/datadogV2/model_slo_status_data.go @@ -0,0 +1,178 @@ +// 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 datadogV2 + +import ( + "fmt" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// SloStatusData The data portion of the SLO status response. +type SloStatusData struct { + // The attributes of the SLO status. + Attributes SloStatusDataAttributes `json:"attributes"` + // The ID of the SLO. + Id string `json:"id"` + // The type of the SLO status resource. + Type SloStatusType `json:"type"` + // 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:"-"` +} + +// NewSloStatusData instantiates a new SloStatusData 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 NewSloStatusData(attributes SloStatusDataAttributes, id string, typeVar SloStatusType) *SloStatusData { + this := SloStatusData{} + this.Attributes = attributes + this.Id = id + this.Type = typeVar + return &this +} + +// NewSloStatusDataWithDefaults instantiates a new SloStatusData 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 NewSloStatusDataWithDefaults() *SloStatusData { + this := SloStatusData{} + return &this +} + +// GetAttributes returns the Attributes field value. +func (o *SloStatusData) GetAttributes() SloStatusDataAttributes { + if o == nil { + var ret SloStatusDataAttributes + return ret + } + return o.Attributes +} + +// GetAttributesOk returns a tuple with the Attributes field value +// and a boolean to check if the value has been set. +func (o *SloStatusData) GetAttributesOk() (*SloStatusDataAttributes, bool) { + if o == nil { + return nil, false + } + return &o.Attributes, true +} + +// SetAttributes sets field value. +func (o *SloStatusData) SetAttributes(v SloStatusDataAttributes) { + o.Attributes = v +} + +// GetId returns the Id field value. +func (o *SloStatusData) GetId() string { + if o == nil { + var ret string + return ret + } + return o.Id +} + +// GetIdOk returns a tuple with the Id field value +// and a boolean to check if the value has been set. +func (o *SloStatusData) GetIdOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Id, true +} + +// SetId sets field value. +func (o *SloStatusData) SetId(v string) { + o.Id = v +} + +// GetType returns the Type field value. +func (o *SloStatusData) GetType() SloStatusType { + if o == nil { + var ret SloStatusType + return ret + } + return o.Type +} + +// GetTypeOk returns a tuple with the Type field value +// and a boolean to check if the value has been set. +func (o *SloStatusData) GetTypeOk() (*SloStatusType, bool) { + if o == nil { + return nil, false + } + return &o.Type, true +} + +// SetType sets field value. +func (o *SloStatusData) SetType(v SloStatusType) { + o.Type = v +} + +// MarshalJSON serializes the struct using spec logic. +func (o SloStatusData) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + toSerialize["attributes"] = o.Attributes + toSerialize["id"] = o.Id + toSerialize["type"] = o.Type + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *SloStatusData) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + Attributes *SloStatusDataAttributes `json:"attributes"` + Id *string `json:"id"` + Type *SloStatusType `json:"type"` + }{} + if err = datadog.Unmarshal(bytes, &all); err != nil { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + if all.Attributes == nil { + return fmt.Errorf("required field attributes missing") + } + if all.Id == nil { + return fmt.Errorf("required field id missing") + } + if all.Type == nil { + return fmt.Errorf("required field type missing") + } + additionalProperties := make(map[string]interface{}) + if err = datadog.Unmarshal(bytes, &additionalProperties); err == nil { + datadog.DeleteKeys(additionalProperties, &[]string{"attributes", "id", "type"}) + } else { + return err + } + + hasInvalidField := false + if all.Attributes.UnparsedObject != nil && o.UnparsedObject == nil { + hasInvalidField = true + } + o.Attributes = *all.Attributes + o.Id = *all.Id + if !all.Type.IsValid() { + hasInvalidField = true + } else { + o.Type = *all.Type + } + + if len(additionalProperties) > 0 { + o.AdditionalProperties = additionalProperties + } + + if hasInvalidField { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + + return nil +} diff --git a/api/datadogV2/model_slo_status_data_attributes.go b/api/datadogV2/model_slo_status_data_attributes.go new file mode 100644 index 00000000000..ead60df99ee --- /dev/null +++ b/api/datadogV2/model_slo_status_data_attributes.go @@ -0,0 +1,238 @@ +// 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 datadogV2 + +import ( + "fmt" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// SloStatusDataAttributes The attributes of the SLO status. +type SloStatusDataAttributes struct { + // The percentage of error budget remaining. + ErrorBudgetRemaining float64 `json:"error_budget_remaining"` + // The raw error budget remaining for the SLO. + RawErrorBudgetRemaining RawErrorBudgetRemaining `json:"raw_error_budget_remaining"` + // The current Service Level Indicator (SLI) value as a percentage. + Sli float64 `json:"sli"` + // The precision of the time span in seconds. + SpanPrecision int64 `json:"span_precision"` + // The current state of the SLO (for example, `breached`, `warning`, `ok`). + State string `json:"state"` + // 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:"-"` +} + +// NewSloStatusDataAttributes instantiates a new SloStatusDataAttributes 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 NewSloStatusDataAttributes(errorBudgetRemaining float64, rawErrorBudgetRemaining RawErrorBudgetRemaining, sli float64, spanPrecision int64, state string) *SloStatusDataAttributes { + this := SloStatusDataAttributes{} + this.ErrorBudgetRemaining = errorBudgetRemaining + this.RawErrorBudgetRemaining = rawErrorBudgetRemaining + this.Sli = sli + this.SpanPrecision = spanPrecision + this.State = state + return &this +} + +// NewSloStatusDataAttributesWithDefaults instantiates a new SloStatusDataAttributes 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 NewSloStatusDataAttributesWithDefaults() *SloStatusDataAttributes { + this := SloStatusDataAttributes{} + return &this +} + +// GetErrorBudgetRemaining returns the ErrorBudgetRemaining field value. +func (o *SloStatusDataAttributes) GetErrorBudgetRemaining() float64 { + if o == nil { + var ret float64 + return ret + } + return o.ErrorBudgetRemaining +} + +// GetErrorBudgetRemainingOk returns a tuple with the ErrorBudgetRemaining field value +// and a boolean to check if the value has been set. +func (o *SloStatusDataAttributes) GetErrorBudgetRemainingOk() (*float64, bool) { + if o == nil { + return nil, false + } + return &o.ErrorBudgetRemaining, true +} + +// SetErrorBudgetRemaining sets field value. +func (o *SloStatusDataAttributes) SetErrorBudgetRemaining(v float64) { + o.ErrorBudgetRemaining = v +} + +// GetRawErrorBudgetRemaining returns the RawErrorBudgetRemaining field value. +func (o *SloStatusDataAttributes) GetRawErrorBudgetRemaining() RawErrorBudgetRemaining { + if o == nil { + var ret RawErrorBudgetRemaining + return ret + } + return o.RawErrorBudgetRemaining +} + +// GetRawErrorBudgetRemainingOk returns a tuple with the RawErrorBudgetRemaining field value +// and a boolean to check if the value has been set. +func (o *SloStatusDataAttributes) GetRawErrorBudgetRemainingOk() (*RawErrorBudgetRemaining, bool) { + if o == nil { + return nil, false + } + return &o.RawErrorBudgetRemaining, true +} + +// SetRawErrorBudgetRemaining sets field value. +func (o *SloStatusDataAttributes) SetRawErrorBudgetRemaining(v RawErrorBudgetRemaining) { + o.RawErrorBudgetRemaining = v +} + +// GetSli returns the Sli field value. +func (o *SloStatusDataAttributes) GetSli() float64 { + if o == nil { + var ret float64 + return ret + } + return o.Sli +} + +// GetSliOk returns a tuple with the Sli field value +// and a boolean to check if the value has been set. +func (o *SloStatusDataAttributes) GetSliOk() (*float64, bool) { + if o == nil { + return nil, false + } + return &o.Sli, true +} + +// SetSli sets field value. +func (o *SloStatusDataAttributes) SetSli(v float64) { + o.Sli = v +} + +// GetSpanPrecision returns the SpanPrecision field value. +func (o *SloStatusDataAttributes) GetSpanPrecision() int64 { + if o == nil { + var ret int64 + return ret + } + return o.SpanPrecision +} + +// GetSpanPrecisionOk returns a tuple with the SpanPrecision field value +// and a boolean to check if the value has been set. +func (o *SloStatusDataAttributes) GetSpanPrecisionOk() (*int64, bool) { + if o == nil { + return nil, false + } + return &o.SpanPrecision, true +} + +// SetSpanPrecision sets field value. +func (o *SloStatusDataAttributes) SetSpanPrecision(v int64) { + o.SpanPrecision = v +} + +// GetState returns the State field value. +func (o *SloStatusDataAttributes) GetState() string { + if o == nil { + var ret string + return ret + } + return o.State +} + +// GetStateOk returns a tuple with the State field value +// and a boolean to check if the value has been set. +func (o *SloStatusDataAttributes) GetStateOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.State, true +} + +// SetState sets field value. +func (o *SloStatusDataAttributes) SetState(v string) { + o.State = v +} + +// MarshalJSON serializes the struct using spec logic. +func (o SloStatusDataAttributes) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + toSerialize["error_budget_remaining"] = o.ErrorBudgetRemaining + toSerialize["raw_error_budget_remaining"] = o.RawErrorBudgetRemaining + toSerialize["sli"] = o.Sli + toSerialize["span_precision"] = o.SpanPrecision + toSerialize["state"] = o.State + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *SloStatusDataAttributes) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + ErrorBudgetRemaining *float64 `json:"error_budget_remaining"` + RawErrorBudgetRemaining *RawErrorBudgetRemaining `json:"raw_error_budget_remaining"` + Sli *float64 `json:"sli"` + SpanPrecision *int64 `json:"span_precision"` + State *string `json:"state"` + }{} + if err = datadog.Unmarshal(bytes, &all); err != nil { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + if all.ErrorBudgetRemaining == nil { + return fmt.Errorf("required field error_budget_remaining missing") + } + if all.RawErrorBudgetRemaining == nil { + return fmt.Errorf("required field raw_error_budget_remaining missing") + } + if all.Sli == nil { + return fmt.Errorf("required field sli missing") + } + if all.SpanPrecision == nil { + return fmt.Errorf("required field span_precision missing") + } + if all.State == nil { + return fmt.Errorf("required field state missing") + } + additionalProperties := make(map[string]interface{}) + if err = datadog.Unmarshal(bytes, &additionalProperties); err == nil { + datadog.DeleteKeys(additionalProperties, &[]string{"error_budget_remaining", "raw_error_budget_remaining", "sli", "span_precision", "state"}) + } else { + return err + } + + hasInvalidField := false + o.ErrorBudgetRemaining = *all.ErrorBudgetRemaining + if all.RawErrorBudgetRemaining.UnparsedObject != nil && o.UnparsedObject == nil { + hasInvalidField = true + } + o.RawErrorBudgetRemaining = *all.RawErrorBudgetRemaining + o.Sli = *all.Sli + o.SpanPrecision = *all.SpanPrecision + o.State = *all.State + + if len(additionalProperties) > 0 { + o.AdditionalProperties = additionalProperties + } + + if hasInvalidField { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + + return nil +} diff --git a/api/datadogV2/model_slo_status_response.go b/api/datadogV2/model_slo_status_response.go new file mode 100644 index 00000000000..2a6147542fd --- /dev/null +++ b/api/datadogV2/model_slo_status_response.go @@ -0,0 +1,110 @@ +// 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 datadogV2 + +import ( + "fmt" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// SloStatusResponse The SLO status response. +type SloStatusResponse struct { + // The data portion of the SLO status response. + Data SloStatusData `json:"data"` + // 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:"-"` +} + +// NewSloStatusResponse instantiates a new SloStatusResponse 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 NewSloStatusResponse(data SloStatusData) *SloStatusResponse { + this := SloStatusResponse{} + this.Data = data + return &this +} + +// NewSloStatusResponseWithDefaults instantiates a new SloStatusResponse 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 NewSloStatusResponseWithDefaults() *SloStatusResponse { + this := SloStatusResponse{} + return &this +} + +// GetData returns the Data field value. +func (o *SloStatusResponse) GetData() SloStatusData { + if o == nil { + var ret SloStatusData + return ret + } + return o.Data +} + +// GetDataOk returns a tuple with the Data field value +// and a boolean to check if the value has been set. +func (o *SloStatusResponse) GetDataOk() (*SloStatusData, bool) { + if o == nil { + return nil, false + } + return &o.Data, true +} + +// SetData sets field value. +func (o *SloStatusResponse) SetData(v SloStatusData) { + o.Data = v +} + +// MarshalJSON serializes the struct using spec logic. +func (o SloStatusResponse) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + toSerialize["data"] = o.Data + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *SloStatusResponse) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + Data *SloStatusData `json:"data"` + }{} + if err = datadog.Unmarshal(bytes, &all); err != nil { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + if all.Data == nil { + return fmt.Errorf("required field data missing") + } + additionalProperties := make(map[string]interface{}) + if err = datadog.Unmarshal(bytes, &additionalProperties); err == nil { + datadog.DeleteKeys(additionalProperties, &[]string{"data"}) + } else { + return err + } + + hasInvalidField := false + if all.Data.UnparsedObject != nil && o.UnparsedObject == nil { + hasInvalidField = true + } + o.Data = *all.Data + + if len(additionalProperties) > 0 { + o.AdditionalProperties = additionalProperties + } + + if hasInvalidField { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + + return nil +} diff --git a/api/datadogV2/model_slo_status_type.go b/api/datadogV2/model_slo_status_type.go new file mode 100644 index 00000000000..462511a6534 --- /dev/null +++ b/api/datadogV2/model_slo_status_type.go @@ -0,0 +1,64 @@ +// 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 datadogV2 + +import ( + "fmt" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// SloStatusType The type of the SLO status resource. +type SloStatusType string + +// List of SloStatusType. +const ( + SLOSTATUSTYPE_SLO_STATUS SloStatusType = "slo_status" +) + +var allowedSloStatusTypeEnumValues = []SloStatusType{ + SLOSTATUSTYPE_SLO_STATUS, +} + +// GetAllowedValues reeturns the list of possible values. +func (v *SloStatusType) GetAllowedValues() []SloStatusType { + return allowedSloStatusTypeEnumValues +} + +// UnmarshalJSON deserializes the given payload. +func (v *SloStatusType) UnmarshalJSON(src []byte) error { + var value string + err := datadog.Unmarshal(src, &value) + if err != nil { + return err + } + *v = SloStatusType(value) + return nil +} + +// NewSloStatusTypeFromValue returns a pointer to a valid SloStatusType +// for the value passed as argument, or an error if the value passed is not allowed by the enum. +func NewSloStatusTypeFromValue(v string) (*SloStatusType, error) { + ev := SloStatusType(v) + if ev.IsValid() { + return &ev, nil + } + return nil, fmt.Errorf("invalid value '%v' for SloStatusType: valid values are %v", v, allowedSloStatusTypeEnumValues) +} + +// IsValid return true if the value is valid for the enum, false otherwise. +func (v SloStatusType) IsValid() bool { + for _, existing := range allowedSloStatusTypeEnumValues { + if existing == v { + return true + } + } + return false +} + +// Ptr returns reference to SloStatusType value. +func (v SloStatusType) Ptr() *SloStatusType { + return &v +} diff --git a/examples/v2/service-level-objectives/GetSloStatus.go b/examples/v2/service-level-objectives/GetSloStatus.go new file mode 100644 index 00000000000..c57d5cee167 --- /dev/null +++ b/examples/v2/service-level-objectives/GetSloStatus.go @@ -0,0 +1,30 @@ +// Get SLO status 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/datadogV2" +) + +func main() { + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + configuration.SetUnstableOperationEnabled("v2.GetSloStatus", true) + apiClient := datadog.NewAPIClient(configuration) + api := datadogV2.NewServiceLevelObjectivesApi(apiClient) + resp, r, err := api.GetSloStatus(ctx, "00000000-0000-0000-0000-000000000000", 1690901870, 1706803070, *datadogV2.NewGetSloStatusOptionalParameters()) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `ServiceLevelObjectivesApi.GetSloStatus`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `ServiceLevelObjectivesApi.GetSloStatus`:\n%s\n", responseContent) +} diff --git a/tests/scenarios/features/v2/service_level_objectives.feature b/tests/scenarios/features/v2/service_level_objectives.feature index a415d16ccec..4dc11df9e57 100644 --- a/tests/scenarios/features/v2/service_level_objectives.feature +++ b/tests/scenarios/features/v2/service_level_objectives.feature @@ -79,3 +79,33 @@ Feature: Service Level Objectives When the request is sent Then the response status is 200 OK And the response "data.type" is equal to "report_id" + + @generated @skip @team:DataDog/slo-app + Scenario: Get SLO status returns "Bad Request" response + Given operation "GetSloStatus" enabled + And new "GetSloStatus" request + And request contains "slo_id" parameter from "REPLACE.ME" + And request contains "from_ts" parameter from "REPLACE.ME" + And request contains "to_ts" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 400 Bad Request + + @generated @skip @team:DataDog/slo-app + Scenario: Get SLO status returns "Not Found" response + Given operation "GetSloStatus" enabled + And new "GetSloStatus" request + And request contains "slo_id" parameter from "REPLACE.ME" + And request contains "from_ts" parameter from "REPLACE.ME" + And request contains "to_ts" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 404 Not Found + + @generated @skip @team:DataDog/slo-app + Scenario: Get SLO status returns "OK" response + Given operation "GetSloStatus" enabled + And new "GetSloStatus" request + And request contains "slo_id" parameter from "REPLACE.ME" + And request contains "from_ts" parameter from "REPLACE.ME" + And request contains "to_ts" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 200 OK diff --git a/tests/scenarios/features/v2/undo.json b/tests/scenarios/features/v2/undo.json index f77f242ff34..c0ec7dbe41a 100644 --- a/tests/scenarios/features/v2/undo.json +++ b/tests/scenarios/features/v2/undo.json @@ -4762,6 +4762,12 @@ "type": "safe" } }, + "GetSloStatus": { + "tag": "Service Level Objectives", + "undo": { + "type": "safe" + } + }, "GetSPARecommendations": { "tag": "Spa", "undo": {