-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a cost monitor example #2363
Merged
api-clients-generation-pipeline
merged 1 commit into
master
from
datadog-api-spec/generated/3488
Jan 17, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
""" | ||
Create a Cost Monitor returns "OK" response | ||
""" | ||
|
||
from datadog_api_client import ApiClient, Configuration | ||
from datadog_api_client.v1.api.monitors_api import MonitorsApi | ||
from datadog_api_client.v1.model.monitor import Monitor | ||
from datadog_api_client.v1.model.monitor_formula_and_function_cost_aggregator import ( | ||
MonitorFormulaAndFunctionCostAggregator, | ||
) | ||
from datadog_api_client.v1.model.monitor_formula_and_function_cost_data_source import ( | ||
MonitorFormulaAndFunctionCostDataSource, | ||
) | ||
from datadog_api_client.v1.model.monitor_formula_and_function_cost_query_definition import ( | ||
MonitorFormulaAndFunctionCostQueryDefinition, | ||
) | ||
from datadog_api_client.v1.model.monitor_options import MonitorOptions | ||
from datadog_api_client.v1.model.monitor_thresholds import MonitorThresholds | ||
from datadog_api_client.v1.model.monitor_type import MonitorType | ||
|
||
body = Monitor( | ||
name="Example Monitor", | ||
type=MonitorType.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=MonitorOptions( | ||
thresholds=MonitorThresholds( | ||
critical=5.0, | ||
warning=3.0, | ||
), | ||
variables=[ | ||
MonitorFormulaAndFunctionCostQueryDefinition( | ||
data_source=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=MonitorFormulaAndFunctionCostAggregator.SUM, | ||
), | ||
], | ||
include_tags=True, | ||
), | ||
) | ||
|
||
configuration = Configuration() | ||
with ApiClient(configuration) as api_client: | ||
api_instance = MonitorsApi(api_client) | ||
response = api_instance.create_monitor(body=body) | ||
|
||
print(response) |
59 changes: 59 additions & 0 deletions
59
src/datadog_api_client/v1/model/monitor_formula_and_function_cost_aggregator.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# 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. | ||
from __future__ import annotations | ||
|
||
|
||
from datadog_api_client.model_utils import ( | ||
ModelSimple, | ||
cached_property, | ||
) | ||
|
||
from typing import ClassVar | ||
|
||
|
||
class MonitorFormulaAndFunctionCostAggregator(ModelSimple): | ||
""" | ||
Aggregation methods for metric queries. | ||
|
||
:param value: Must be one of ["avg", "sum", "max", "min", "last", "area", "l2norm", "percentile", "stddev"]. | ||
:type value: str | ||
""" | ||
|
||
allowed_values = { | ||
"avg", | ||
"sum", | ||
"max", | ||
"min", | ||
"last", | ||
"area", | ||
"l2norm", | ||
"percentile", | ||
"stddev", | ||
} | ||
AVG: ClassVar["MonitorFormulaAndFunctionCostAggregator"] | ||
SUM: ClassVar["MonitorFormulaAndFunctionCostAggregator"] | ||
MAX: ClassVar["MonitorFormulaAndFunctionCostAggregator"] | ||
MIN: ClassVar["MonitorFormulaAndFunctionCostAggregator"] | ||
LAST: ClassVar["MonitorFormulaAndFunctionCostAggregator"] | ||
AREA: ClassVar["MonitorFormulaAndFunctionCostAggregator"] | ||
L2NORM: ClassVar["MonitorFormulaAndFunctionCostAggregator"] | ||
PERCENTILE: ClassVar["MonitorFormulaAndFunctionCostAggregator"] | ||
STDDEV: ClassVar["MonitorFormulaAndFunctionCostAggregator"] | ||
|
||
@cached_property | ||
def openapi_types(_): | ||
return { | ||
"value": (str,), | ||
} | ||
|
||
|
||
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") |
41 changes: 41 additions & 0 deletions
41
src/datadog_api_client/v1/model/monitor_formula_and_function_cost_data_source.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# 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. | ||
from __future__ import annotations | ||
|
||
|
||
from datadog_api_client.model_utils import ( | ||
ModelSimple, | ||
cached_property, | ||
) | ||
|
||
from typing import ClassVar | ||
|
||
|
||
class MonitorFormulaAndFunctionCostDataSource(ModelSimple): | ||
""" | ||
Data source for cost queries. | ||
|
||
:param value: Must be one of ["metrics", "cloud_cost", "datadog_usage"]. | ||
:type value: str | ||
""" | ||
|
||
allowed_values = { | ||
"metrics", | ||
"cloud_cost", | ||
"datadog_usage", | ||
} | ||
METRICS: ClassVar["MonitorFormulaAndFunctionCostDataSource"] | ||
CLOUD_COST: ClassVar["MonitorFormulaAndFunctionCostDataSource"] | ||
DATADOG_USAGE: ClassVar["MonitorFormulaAndFunctionCostDataSource"] | ||
|
||
@cached_property | ||
def openapi_types(_): | ||
return { | ||
"value": (str,), | ||
} | ||
|
||
|
||
MonitorFormulaAndFunctionCostDataSource.METRICS = MonitorFormulaAndFunctionCostDataSource("metrics") | ||
MonitorFormulaAndFunctionCostDataSource.CLOUD_COST = MonitorFormulaAndFunctionCostDataSource("cloud_cost") | ||
MonitorFormulaAndFunctionCostDataSource.DATADOG_USAGE = MonitorFormulaAndFunctionCostDataSource("datadog_usage") |
78 changes: 78 additions & 0 deletions
78
src/datadog_api_client/v1/model/monitor_formula_and_function_cost_query_definition.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# 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. | ||
from __future__ import annotations | ||
|
||
from typing import Union, TYPE_CHECKING | ||
|
||
from datadog_api_client.model_utils import ( | ||
ModelNormal, | ||
cached_property, | ||
unset, | ||
UnsetType, | ||
) | ||
|
||
|
||
if TYPE_CHECKING: | ||
from datadog_api_client.v1.model.monitor_formula_and_function_cost_aggregator import ( | ||
MonitorFormulaAndFunctionCostAggregator, | ||
) | ||
from datadog_api_client.v1.model.monitor_formula_and_function_cost_data_source import ( | ||
MonitorFormulaAndFunctionCostDataSource, | ||
) | ||
|
||
|
||
class MonitorFormulaAndFunctionCostQueryDefinition(ModelNormal): | ||
@cached_property | ||
def openapi_types(_): | ||
from datadog_api_client.v1.model.monitor_formula_and_function_cost_aggregator import ( | ||
MonitorFormulaAndFunctionCostAggregator, | ||
) | ||
from datadog_api_client.v1.model.monitor_formula_and_function_cost_data_source import ( | ||
MonitorFormulaAndFunctionCostDataSource, | ||
) | ||
|
||
return { | ||
"aggregator": (MonitorFormulaAndFunctionCostAggregator,), | ||
"data_source": (MonitorFormulaAndFunctionCostDataSource,), | ||
"name": (str,), | ||
"query": (str,), | ||
} | ||
|
||
attribute_map = { | ||
"aggregator": "aggregator", | ||
"data_source": "data_source", | ||
"name": "name", | ||
"query": "query", | ||
} | ||
|
||
def __init__( | ||
self_, | ||
data_source: MonitorFormulaAndFunctionCostDataSource, | ||
name: str, | ||
query: str, | ||
aggregator: Union[MonitorFormulaAndFunctionCostAggregator, UnsetType] = unset, | ||
**kwargs, | ||
): | ||
""" | ||
A formula and functions cost query. | ||
|
||
:param aggregator: Aggregation methods for metric queries. | ||
:type aggregator: MonitorFormulaAndFunctionCostAggregator, optional | ||
|
||
:param data_source: Data source for cost queries. | ||
:type data_source: MonitorFormulaAndFunctionCostDataSource | ||
|
||
:param name: Name of the query for use in formulas. | ||
:type name: str | ||
|
||
:param query: The monitor query. | ||
:type query: str | ||
""" | ||
if aggregator is not unset: | ||
kwargs["aggregator"] = aggregator | ||
super().__init__(kwargs) | ||
|
||
self_.data_source = data_source | ||
self_.name = name | ||
self_.query = query |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔴 Code Quality Violation
first parameter of a class function should be self (...read more)
In a class method (that is not a class method nor a static method), the first argument must be
self
by convention.Learn More