diff --git a/.apigentools-info b/.apigentools-info index 1bf6c9ed380..0415576311d 100644 --- a/.apigentools-info +++ b/.apigentools-info @@ -4,13 +4,13 @@ "spec_versions": { "v1": { "apigentools_version": "1.6.6", - "regenerated": "2025-01-17 21:03:23.618184", - "spec_repo_commit": "617655da" + "regenerated": "2025-01-17 21:41:17.843758", + "spec_repo_commit": "27e609f7" }, "v2": { "apigentools_version": "1.6.6", - "regenerated": "2025-01-17 21:03:23.634365", - "spec_repo_commit": "617655da" + "regenerated": "2025-01-17 21:41:17.859150", + "spec_repo_commit": "27e609f7" } } } \ No newline at end of file diff --git a/.generator/schemas/v1/openapi.yaml b/.generator/schemas/v1/openapi.yaml index 8e9949afea3..655dc2c655a 100644 --- a/.generator/schemas/v1/openapi.yaml +++ b/.generator/schemas/v1/openapi.yaml @@ -6784,6 +6784,62 @@ components: - FIREFOX_LAPTOP_LARGE - FIREFOX_TABLET - FIREFOX_MOBILE_SMALL + MonitorFormulaAndFunctionCostAggregator: + description: Aggregation methods for metric queries. + enum: + - avg + - sum + - max + - min + - last + - area + - l2norm + - percentile + - stddev + example: avg + type: string + x-enum-varnames: + - AVG + - SUM + - MAX + - MIN + - LAST + - AREA + - L2NORM + - PERCENTILE + - STDDEV + MonitorFormulaAndFunctionCostDataSource: + description: Data source for cost queries. + enum: + - metrics + - cloud_cost + - datadog_usage + example: cloud_cost + type: string + x-enum-varnames: + - METRICS + - CLOUD_COST + - DATADOG_USAGE + MonitorFormulaAndFunctionCostQueryDefinition: + description: A formula and functions cost query. + properties: + aggregator: + $ref: '#/components/schemas/MonitorFormulaAndFunctionCostAggregator' + data_source: + $ref: '#/components/schemas/MonitorFormulaAndFunctionCostDataSource' + name: + description: Name of the query for use in formulas. + example: query1 + type: string + query: + description: The monitor query. + example: sum:all.cost{*}.rollup(sum, 86400) + type: string + required: + - name + - data_source + - query + type: object MonitorFormulaAndFunctionEventAggregation: description: Aggregation methods for event platform queries. enum: @@ -6934,6 +6990,7 @@ components: description: A formula and function query. oneOf: - $ref: '#/components/schemas/MonitorFormulaAndFunctionEventQueryDefinition' + - $ref: '#/components/schemas/MonitorFormulaAndFunctionCostQueryDefinition' MonitorGroupSearchResponse: description: The response of a monitor group search. example: diff --git a/api/datadogV1/model_monitor_formula_and_function_cost_aggregator.go b/api/datadogV1/model_monitor_formula_and_function_cost_aggregator.go new file mode 100644 index 00000000000..7175ac4b9df --- /dev/null +++ b/api/datadogV1/model_monitor_formula_and_function_cost_aggregator.go @@ -0,0 +1,80 @@ +// 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" +) + +// MonitorFormulaAndFunctionCostAggregator Aggregation methods for metric queries. +type MonitorFormulaAndFunctionCostAggregator string + +// List of MonitorFormulaAndFunctionCostAggregator. +const ( + MONITORFORMULAANDFUNCTIONCOSTAGGREGATOR_AVG MonitorFormulaAndFunctionCostAggregator = "avg" + MONITORFORMULAANDFUNCTIONCOSTAGGREGATOR_SUM MonitorFormulaAndFunctionCostAggregator = "sum" + MONITORFORMULAANDFUNCTIONCOSTAGGREGATOR_MAX MonitorFormulaAndFunctionCostAggregator = "max" + MONITORFORMULAANDFUNCTIONCOSTAGGREGATOR_MIN MonitorFormulaAndFunctionCostAggregator = "min" + MONITORFORMULAANDFUNCTIONCOSTAGGREGATOR_LAST MonitorFormulaAndFunctionCostAggregator = "last" + MONITORFORMULAANDFUNCTIONCOSTAGGREGATOR_AREA MonitorFormulaAndFunctionCostAggregator = "area" + MONITORFORMULAANDFUNCTIONCOSTAGGREGATOR_L2NORM MonitorFormulaAndFunctionCostAggregator = "l2norm" + MONITORFORMULAANDFUNCTIONCOSTAGGREGATOR_PERCENTILE MonitorFormulaAndFunctionCostAggregator = "percentile" + MONITORFORMULAANDFUNCTIONCOSTAGGREGATOR_STDDEV MonitorFormulaAndFunctionCostAggregator = "stddev" +) + +var allowedMonitorFormulaAndFunctionCostAggregatorEnumValues = []MonitorFormulaAndFunctionCostAggregator{ + MONITORFORMULAANDFUNCTIONCOSTAGGREGATOR_AVG, + MONITORFORMULAANDFUNCTIONCOSTAGGREGATOR_SUM, + MONITORFORMULAANDFUNCTIONCOSTAGGREGATOR_MAX, + MONITORFORMULAANDFUNCTIONCOSTAGGREGATOR_MIN, + MONITORFORMULAANDFUNCTIONCOSTAGGREGATOR_LAST, + MONITORFORMULAANDFUNCTIONCOSTAGGREGATOR_AREA, + MONITORFORMULAANDFUNCTIONCOSTAGGREGATOR_L2NORM, + MONITORFORMULAANDFUNCTIONCOSTAGGREGATOR_PERCENTILE, + MONITORFORMULAANDFUNCTIONCOSTAGGREGATOR_STDDEV, +} + +// GetAllowedValues reeturns the list of possible values. +func (v *MonitorFormulaAndFunctionCostAggregator) GetAllowedValues() []MonitorFormulaAndFunctionCostAggregator { + return allowedMonitorFormulaAndFunctionCostAggregatorEnumValues +} + +// UnmarshalJSON deserializes the given payload. +func (v *MonitorFormulaAndFunctionCostAggregator) UnmarshalJSON(src []byte) error { + var value string + err := datadog.Unmarshal(src, &value) + if err != nil { + return err + } + *v = MonitorFormulaAndFunctionCostAggregator(value) + return nil +} + +// NewMonitorFormulaAndFunctionCostAggregatorFromValue returns a pointer to a valid MonitorFormulaAndFunctionCostAggregator +// for the value passed as argument, or an error if the value passed is not allowed by the enum. +func NewMonitorFormulaAndFunctionCostAggregatorFromValue(v string) (*MonitorFormulaAndFunctionCostAggregator, error) { + ev := MonitorFormulaAndFunctionCostAggregator(v) + if ev.IsValid() { + return &ev, nil + } + return nil, fmt.Errorf("invalid value '%v' for MonitorFormulaAndFunctionCostAggregator: valid values are %v", v, allowedMonitorFormulaAndFunctionCostAggregatorEnumValues) +} + +// IsValid return true if the value is valid for the enum, false otherwise. +func (v MonitorFormulaAndFunctionCostAggregator) IsValid() bool { + for _, existing := range allowedMonitorFormulaAndFunctionCostAggregatorEnumValues { + if existing == v { + return true + } + } + return false +} + +// Ptr returns reference to MonitorFormulaAndFunctionCostAggregator value. +func (v MonitorFormulaAndFunctionCostAggregator) Ptr() *MonitorFormulaAndFunctionCostAggregator { + return &v +} diff --git a/api/datadogV1/model_monitor_formula_and_function_cost_data_source.go b/api/datadogV1/model_monitor_formula_and_function_cost_data_source.go new file mode 100644 index 00000000000..0212575d1a7 --- /dev/null +++ b/api/datadogV1/model_monitor_formula_and_function_cost_data_source.go @@ -0,0 +1,68 @@ +// 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" +) + +// MonitorFormulaAndFunctionCostDataSource Data source for cost queries. +type MonitorFormulaAndFunctionCostDataSource string + +// List of MonitorFormulaAndFunctionCostDataSource. +const ( + MONITORFORMULAANDFUNCTIONCOSTDATASOURCE_METRICS MonitorFormulaAndFunctionCostDataSource = "metrics" + MONITORFORMULAANDFUNCTIONCOSTDATASOURCE_CLOUD_COST MonitorFormulaAndFunctionCostDataSource = "cloud_cost" + MONITORFORMULAANDFUNCTIONCOSTDATASOURCE_DATADOG_USAGE MonitorFormulaAndFunctionCostDataSource = "datadog_usage" +) + +var allowedMonitorFormulaAndFunctionCostDataSourceEnumValues = []MonitorFormulaAndFunctionCostDataSource{ + MONITORFORMULAANDFUNCTIONCOSTDATASOURCE_METRICS, + MONITORFORMULAANDFUNCTIONCOSTDATASOURCE_CLOUD_COST, + MONITORFORMULAANDFUNCTIONCOSTDATASOURCE_DATADOG_USAGE, +} + +// GetAllowedValues reeturns the list of possible values. +func (v *MonitorFormulaAndFunctionCostDataSource) GetAllowedValues() []MonitorFormulaAndFunctionCostDataSource { + return allowedMonitorFormulaAndFunctionCostDataSourceEnumValues +} + +// UnmarshalJSON deserializes the given payload. +func (v *MonitorFormulaAndFunctionCostDataSource) UnmarshalJSON(src []byte) error { + var value string + err := datadog.Unmarshal(src, &value) + if err != nil { + return err + } + *v = MonitorFormulaAndFunctionCostDataSource(value) + return nil +} + +// NewMonitorFormulaAndFunctionCostDataSourceFromValue returns a pointer to a valid MonitorFormulaAndFunctionCostDataSource +// for the value passed as argument, or an error if the value passed is not allowed by the enum. +func NewMonitorFormulaAndFunctionCostDataSourceFromValue(v string) (*MonitorFormulaAndFunctionCostDataSource, error) { + ev := MonitorFormulaAndFunctionCostDataSource(v) + if ev.IsValid() { + return &ev, nil + } + return nil, fmt.Errorf("invalid value '%v' for MonitorFormulaAndFunctionCostDataSource: valid values are %v", v, allowedMonitorFormulaAndFunctionCostDataSourceEnumValues) +} + +// IsValid return true if the value is valid for the enum, false otherwise. +func (v MonitorFormulaAndFunctionCostDataSource) IsValid() bool { + for _, existing := range allowedMonitorFormulaAndFunctionCostDataSourceEnumValues { + if existing == v { + return true + } + } + return false +} + +// Ptr returns reference to MonitorFormulaAndFunctionCostDataSource value. +func (v MonitorFormulaAndFunctionCostDataSource) Ptr() *MonitorFormulaAndFunctionCostDataSource { + return &v +} diff --git a/api/datadogV1/model_monitor_formula_and_function_cost_query_definition.go b/api/datadogV1/model_monitor_formula_and_function_cost_query_definition.go new file mode 100644 index 00000000000..a3742eec48b --- /dev/null +++ b/api/datadogV1/model_monitor_formula_and_function_cost_query_definition.go @@ -0,0 +1,214 @@ +// 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" +) + +// MonitorFormulaAndFunctionCostQueryDefinition A formula and functions cost query. +type MonitorFormulaAndFunctionCostQueryDefinition struct { + // Aggregation methods for metric queries. + Aggregator *MonitorFormulaAndFunctionCostAggregator `json:"aggregator,omitempty"` + // Data source for cost queries. + DataSource MonitorFormulaAndFunctionCostDataSource `json:"data_source"` + // Name of the query for use in formulas. + Name string `json:"name"` + // The monitor query. + Query string `json:"query"` + // 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:"-"` +} + +// NewMonitorFormulaAndFunctionCostQueryDefinition instantiates a new MonitorFormulaAndFunctionCostQueryDefinition 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 NewMonitorFormulaAndFunctionCostQueryDefinition(dataSource MonitorFormulaAndFunctionCostDataSource, name string, query string) *MonitorFormulaAndFunctionCostQueryDefinition { + this := MonitorFormulaAndFunctionCostQueryDefinition{} + this.DataSource = dataSource + this.Name = name + this.Query = query + return &this +} + +// NewMonitorFormulaAndFunctionCostQueryDefinitionWithDefaults instantiates a new MonitorFormulaAndFunctionCostQueryDefinition 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 NewMonitorFormulaAndFunctionCostQueryDefinitionWithDefaults() *MonitorFormulaAndFunctionCostQueryDefinition { + this := MonitorFormulaAndFunctionCostQueryDefinition{} + return &this +} + +// GetAggregator returns the Aggregator field value if set, zero value otherwise. +func (o *MonitorFormulaAndFunctionCostQueryDefinition) GetAggregator() MonitorFormulaAndFunctionCostAggregator { + if o == nil || o.Aggregator == nil { + var ret MonitorFormulaAndFunctionCostAggregator + return ret + } + return *o.Aggregator +} + +// GetAggregatorOk returns a tuple with the Aggregator field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *MonitorFormulaAndFunctionCostQueryDefinition) GetAggregatorOk() (*MonitorFormulaAndFunctionCostAggregator, bool) { + if o == nil || o.Aggregator == nil { + return nil, false + } + return o.Aggregator, true +} + +// HasAggregator returns a boolean if a field has been set. +func (o *MonitorFormulaAndFunctionCostQueryDefinition) HasAggregator() bool { + return o != nil && o.Aggregator != nil +} + +// SetAggregator gets a reference to the given MonitorFormulaAndFunctionCostAggregator and assigns it to the Aggregator field. +func (o *MonitorFormulaAndFunctionCostQueryDefinition) SetAggregator(v MonitorFormulaAndFunctionCostAggregator) { + o.Aggregator = &v +} + +// GetDataSource returns the DataSource field value. +func (o *MonitorFormulaAndFunctionCostQueryDefinition) GetDataSource() MonitorFormulaAndFunctionCostDataSource { + if o == nil { + var ret MonitorFormulaAndFunctionCostDataSource + return ret + } + return o.DataSource +} + +// GetDataSourceOk returns a tuple with the DataSource field value +// and a boolean to check if the value has been set. +func (o *MonitorFormulaAndFunctionCostQueryDefinition) GetDataSourceOk() (*MonitorFormulaAndFunctionCostDataSource, bool) { + if o == nil { + return nil, false + } + return &o.DataSource, true +} + +// SetDataSource sets field value. +func (o *MonitorFormulaAndFunctionCostQueryDefinition) SetDataSource(v MonitorFormulaAndFunctionCostDataSource) { + o.DataSource = v +} + +// GetName returns the Name field value. +func (o *MonitorFormulaAndFunctionCostQueryDefinition) GetName() string { + if o == nil { + var ret string + return ret + } + return o.Name +} + +// GetNameOk returns a tuple with the Name field value +// and a boolean to check if the value has been set. +func (o *MonitorFormulaAndFunctionCostQueryDefinition) GetNameOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Name, true +} + +// SetName sets field value. +func (o *MonitorFormulaAndFunctionCostQueryDefinition) SetName(v string) { + o.Name = v +} + +// GetQuery returns the Query field value. +func (o *MonitorFormulaAndFunctionCostQueryDefinition) GetQuery() string { + if o == nil { + var ret string + return ret + } + return o.Query +} + +// GetQueryOk returns a tuple with the Query field value +// and a boolean to check if the value has been set. +func (o *MonitorFormulaAndFunctionCostQueryDefinition) GetQueryOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Query, true +} + +// SetQuery sets field value. +func (o *MonitorFormulaAndFunctionCostQueryDefinition) SetQuery(v string) { + o.Query = v +} + +// MarshalJSON serializes the struct using spec logic. +func (o MonitorFormulaAndFunctionCostQueryDefinition) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + if o.Aggregator != nil { + toSerialize["aggregator"] = o.Aggregator + } + toSerialize["data_source"] = o.DataSource + toSerialize["name"] = o.Name + toSerialize["query"] = o.Query + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *MonitorFormulaAndFunctionCostQueryDefinition) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + Aggregator *MonitorFormulaAndFunctionCostAggregator `json:"aggregator,omitempty"` + DataSource *MonitorFormulaAndFunctionCostDataSource `json:"data_source"` + Name *string `json:"name"` + Query *string `json:"query"` + }{} + if err = datadog.Unmarshal(bytes, &all); err != nil { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + if all.DataSource == nil { + return fmt.Errorf("required field data_source missing") + } + if all.Name == nil { + return fmt.Errorf("required field name missing") + } + if all.Query == nil { + return fmt.Errorf("required field query missing") + } + additionalProperties := make(map[string]interface{}) + if err = datadog.Unmarshal(bytes, &additionalProperties); err == nil { + datadog.DeleteKeys(additionalProperties, &[]string{"aggregator", "data_source", "name", "query"}) + } else { + return err + } + + hasInvalidField := false + if all.Aggregator != nil && !all.Aggregator.IsValid() { + hasInvalidField = true + } else { + o.Aggregator = all.Aggregator + } + if !all.DataSource.IsValid() { + hasInvalidField = true + } else { + o.DataSource = *all.DataSource + } + o.Name = *all.Name + o.Query = *all.Query + + if len(additionalProperties) > 0 { + o.AdditionalProperties = additionalProperties + } + + if hasInvalidField { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + + return nil +} diff --git a/api/datadogV1/model_monitor_formula_and_function_query_definition.go b/api/datadogV1/model_monitor_formula_and_function_query_definition.go index 18e0c211892..3128d7cb014 100644 --- a/api/datadogV1/model_monitor_formula_and_function_query_definition.go +++ b/api/datadogV1/model_monitor_formula_and_function_query_definition.go @@ -11,6 +11,7 @@ import ( // MonitorFormulaAndFunctionQueryDefinition - A formula and function query. type MonitorFormulaAndFunctionQueryDefinition struct { MonitorFormulaAndFunctionEventQueryDefinition *MonitorFormulaAndFunctionEventQueryDefinition + MonitorFormulaAndFunctionCostQueryDefinition *MonitorFormulaAndFunctionCostQueryDefinition // UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct UnparsedObject interface{} @@ -21,6 +22,11 @@ func MonitorFormulaAndFunctionEventQueryDefinitionAsMonitorFormulaAndFunctionQue return MonitorFormulaAndFunctionQueryDefinition{MonitorFormulaAndFunctionEventQueryDefinition: v} } +// MonitorFormulaAndFunctionCostQueryDefinitionAsMonitorFormulaAndFunctionQueryDefinition is a convenience function that returns MonitorFormulaAndFunctionCostQueryDefinition wrapped in MonitorFormulaAndFunctionQueryDefinition. +func MonitorFormulaAndFunctionCostQueryDefinitionAsMonitorFormulaAndFunctionQueryDefinition(v *MonitorFormulaAndFunctionCostQueryDefinition) MonitorFormulaAndFunctionQueryDefinition { + return MonitorFormulaAndFunctionQueryDefinition{MonitorFormulaAndFunctionCostQueryDefinition: v} +} + // UnmarshalJSON turns data into one of the pointers in the struct. func (obj *MonitorFormulaAndFunctionQueryDefinition) UnmarshalJSON(data []byte) error { var err error @@ -42,9 +48,27 @@ func (obj *MonitorFormulaAndFunctionQueryDefinition) UnmarshalJSON(data []byte) obj.MonitorFormulaAndFunctionEventQueryDefinition = nil } + // try to unmarshal data into MonitorFormulaAndFunctionCostQueryDefinition + err = datadog.Unmarshal(data, &obj.MonitorFormulaAndFunctionCostQueryDefinition) + if err == nil { + if obj.MonitorFormulaAndFunctionCostQueryDefinition != nil && obj.MonitorFormulaAndFunctionCostQueryDefinition.UnparsedObject == nil { + jsonMonitorFormulaAndFunctionCostQueryDefinition, _ := datadog.Marshal(obj.MonitorFormulaAndFunctionCostQueryDefinition) + if string(jsonMonitorFormulaAndFunctionCostQueryDefinition) == "{}" { // empty struct + obj.MonitorFormulaAndFunctionCostQueryDefinition = nil + } else { + match++ + } + } else { + obj.MonitorFormulaAndFunctionCostQueryDefinition = nil + } + } else { + obj.MonitorFormulaAndFunctionCostQueryDefinition = nil + } + if match != 1 { // more than 1 match // reset to nil obj.MonitorFormulaAndFunctionEventQueryDefinition = nil + obj.MonitorFormulaAndFunctionCostQueryDefinition = nil return datadog.Unmarshal(data, &obj.UnparsedObject) } return nil // exactly one match @@ -56,6 +80,10 @@ func (obj MonitorFormulaAndFunctionQueryDefinition) MarshalJSON() ([]byte, error return datadog.Marshal(&obj.MonitorFormulaAndFunctionEventQueryDefinition) } + if obj.MonitorFormulaAndFunctionCostQueryDefinition != nil { + return datadog.Marshal(&obj.MonitorFormulaAndFunctionCostQueryDefinition) + } + if obj.UnparsedObject != nil { return datadog.Marshal(obj.UnparsedObject) } @@ -68,6 +96,10 @@ func (obj *MonitorFormulaAndFunctionQueryDefinition) GetActualInstance() interfa return obj.MonitorFormulaAndFunctionEventQueryDefinition } + if obj.MonitorFormulaAndFunctionCostQueryDefinition != nil { + return obj.MonitorFormulaAndFunctionCostQueryDefinition + } + // all schemas are nil return nil } diff --git a/examples/v1/monitors/CreateMonitor_1303514967.go b/examples/v1/monitors/CreateMonitor_1303514967.go new file mode 100644 index 00000000000..ba2250e4b81 --- /dev/null +++ b/examples/v1/monitors/CreateMonitor_1303514967.go @@ -0,0 +1,56 @@ +// Create a Cost Monitor 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.Monitor{ + Name: datadog.PtrString("Example Monitor"), + Type: datadogV1.MONITORTYPE_COST_ALERT, + Query: `formula("exclude_null(query1)").last("7d").anomaly(direction="above", threshold=10) >= 5`, + Message: datadog.PtrString("some message Notify: @hipchat-channel"), + Tags: []string{ + "test:examplemonitor", + "env:ci", + }, + Priority: *datadog.NewNullableInt64(datadog.PtrInt64(3)), + Options: &datadogV1.MonitorOptions{ + Thresholds: &datadogV1.MonitorThresholds{ + Critical: datadog.PtrFloat64(5), + Warning: *datadog.NewNullableFloat64(datadog.PtrFloat64(3)), + }, + Variables: []datadogV1.MonitorFormulaAndFunctionQueryDefinition{ + datadogV1.MonitorFormulaAndFunctionQueryDefinition{ + MonitorFormulaAndFunctionCostQueryDefinition: &datadogV1.MonitorFormulaAndFunctionCostQueryDefinition{ + DataSource: datadogV1.MONITORFORMULAANDFUNCTIONCOSTDATASOURCE_CLOUD_COST, + Query: "sum:aws.cost.net.amortized.shared.resources.allocated{aws_product IN (amplify ,athena, backup, bedrock ) } by {aws_product}.rollup(sum, 86400)", + Name: "query1", + Aggregator: datadogV1.MONITORFORMULAANDFUNCTIONCOSTAGGREGATOR_SUM.Ptr(), + }}, + }, + IncludeTags: datadog.PtrBool(true), + }, + } + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + api := datadogV1.NewMonitorsApi(apiClient) + resp, r, err := api.CreateMonitor(ctx, body) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `MonitorsApi.CreateMonitor`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `MonitorsApi.CreateMonitor`:\n%s\n", responseContent) +} diff --git a/tests/scenarios/cassettes/TestScenarios/v1/Feature_Monitors/Scenario_Create_a_Cost_Monitor_returns_OK_response.freeze b/tests/scenarios/cassettes/TestScenarios/v1/Feature_Monitors/Scenario_Create_a_Cost_Monitor_returns_OK_response.freeze new file mode 100644 index 00000000000..8cea032a9d7 --- /dev/null +++ b/tests/scenarios/cassettes/TestScenarios/v1/Feature_Monitors/Scenario_Create_a_Cost_Monitor_returns_OK_response.freeze @@ -0,0 +1 @@ +2025-01-17T11:21:26.452Z \ No newline at end of file diff --git a/tests/scenarios/cassettes/TestScenarios/v1/Feature_Monitors/Scenario_Create_a_Cost_Monitor_returns_OK_response.yaml b/tests/scenarios/cassettes/TestScenarios/v1/Feature_Monitors/Scenario_Create_a_Cost_Monitor_returns_OK_response.yaml new file mode 100644 index 00000000000..41e6104a0e4 --- /dev/null +++ b/tests/scenarios/cassettes/TestScenarios/v1/Feature_Monitors/Scenario_Create_a_Cost_Monitor_returns_OK_response.yaml @@ -0,0 +1,47 @@ +interactions: +- request: + body: | + {"message":"some message Notify: @hipchat-channel","name":"Example Monitor","options":{"include_tags":true,"thresholds":{"critical":5,"warning":3},"variables":[{"aggregator":"sum","data_source":"cloud_cost","name":"query1","query":"sum:aws.cost.net.amortized.shared.resources.allocated{aws_product IN (amplify ,athena, backup, bedrock ) } by {aws_product}.rollup(sum, 86400)"}]},"priority":3,"query":"formula(\"exclude_null(query1)\").last(\"7d\").anomaly(direction=\"above\", threshold=10) \u003e= 5","tags":["test:examplemonitor","env:ci"],"type":"cost alert"} + form: {} + headers: + Accept: + - application/json + Content-Type: + - application/json + id: 0 + method: POST + url: https://api.datadoghq.com/api/v1/monitor + response: + body: '{"id":162921056,"org_id":321813,"type":"cost alert","name":"Example Monitor","message":"some + message Notify: @hipchat-channel","tags":["test:examplemonitor","env:ci"],"query":"formula(\"exclude_null(query1)\").last(\"7d\").anomaly(direction=\"above\", + threshold=10) >= 5","options":{"include_tags":true,"thresholds":{"critical":5.0,"warning":3.0},"variables":[{"aggregator":"sum","data_source":"cloud_cost","name":"query1","query":"sum:aws.cost.net.amortized.shared.resources.allocated{aws_product + IN (amplify ,athena, backup, bedrock ) } by {aws_product}.rollup(sum, 86400)"}],"notify_no_data":false,"notify_audit":false,"new_host_delay":300,"silenced":{}},"multi":false,"created_at":1737112886000,"created":"2025-01-17T11:21:26.560275+00:00","modified":"2025-01-17T11:21:26.560275+00:00","deleted":null,"priority":3,"restricted_roles":null,"restriction_policy":null,"overall_state_modified":null,"overall_state":"No + Data","creator":{"name":"CI Account","handle":"9919ec9b-ebc7-49ee-8dc8-03626e717cca","email":"team-intg-tools-libs-spam@datadoghq.com","id":2320499}} + + ' + code: 200 + duration: 0ms + headers: + Content-Type: + - application/json + status: 200 OK +- request: + body: '' + form: {} + headers: + Accept: + - application/json + id: 1 + method: DELETE + url: https://api.datadoghq.com/api/v1/monitor/162921056 + response: + body: '{"deleted_monitor_id":162921056} + + ' + code: 200 + duration: 0ms + headers: + Content-Type: + - application/json + status: 200 OK +version: 2 diff --git a/tests/scenarios/features/v1/monitors.feature b/tests/scenarios/features/v1/monitors.feature index 8154cd7a879..bb344afd780 100644 --- a/tests/scenarios/features/v1/monitors.feature +++ b/tests/scenarios/features/v1/monitors.feature @@ -33,6 +33,13 @@ Feature: Monitors Then the response status is 200 OK And the response "data.ok[0]" has the same value as "monitor.id" + @team:DataDog/monitor-app + Scenario: Create a Cost Monitor returns "OK" response + Given new "CreateMonitor" request + And body with value {"name": "Example Monitor", "type": "cost alert", "query": "formula(\"exclude_null(query1)\").last(\"7d\").anomaly(direction=\"above\", threshold=10) >= 5", "message": "some message Notify: @hipchat-channel", "tags": ["test:examplemonitor", "env:ci"], "priority": 3, "options": {"thresholds": {"critical": 5, "warning": 3}, "variables": [{"data_source": "cloud_cost", "query": "sum:aws.cost.net.amortized.shared.resources.allocated{aws_product IN (amplify ,athena, backup, bedrock ) } by {aws_product}.rollup(sum, 86400)", "name": "query1", "aggregator": "sum"}], "include_tags": true}} + When the request is sent + Then the response status is 200 OK + @team:DataDog/monitor-app Scenario: Create a RUM formula and functions monitor returns "OK" response Given new "CreateMonitor" request