Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions python/codegen/codegen/packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"resources.Catalog": "catalogs",
"resources.Schema": "schemas",
"resources.Volume": "volumes",
"resources.Alert": "alerts",
}

RESOURCE_TYPES = list(RESOURCE_NAMESPACE.keys())
Expand All @@ -21,6 +22,8 @@
"pipelines",
"resources",
"catalog",
"sql",

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

These 2 had to be added manually but I think they can be found out using BFS and potentially stored in a yaml file

"iam",
]

RENAMES = {
Expand Down
123 changes: 123 additions & 0 deletions python/databricks/bundles/alerts/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
__all__ = [

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This file is also auto generated

"Aggregation",
"AggregationParam",
"Alert",
"AlertDict",
"AlertEvaluationState",
"AlertEvaluationStateParam",
"AlertParam",
"AlertStatementParameter",
"AlertStatementParameterDict",
"AlertStatementParameterParam",
"AlertV2Evaluation",
"AlertV2EvaluationDict",
"AlertV2EvaluationParam",
"AlertV2Notification",
"AlertV2NotificationDict",
"AlertV2NotificationParam",
"AlertV2Operand",
"AlertV2OperandColumn",
"AlertV2OperandColumnDict",
"AlertV2OperandColumnParam",
"AlertV2OperandDict",
"AlertV2OperandParam",
"AlertV2OperandValue",
"AlertV2OperandValueDict",
"AlertV2OperandValueParam",
"AlertV2RunAs",
"AlertV2RunAsDict",
"AlertV2RunAsParam",
"AlertV2Subscription",
"AlertV2SubscriptionDict",
"AlertV2SubscriptionParam",
"ComparisonOperator",
"ComparisonOperatorParam",
"CronSchedule",
"CronScheduleDict",
"CronScheduleParam",
"Lifecycle",
"LifecycleDict",
"LifecycleParam",
"Permission",
"PermissionDict",
"PermissionLevel",
"PermissionLevelParam",
"PermissionParam",
"SchedulePauseStatus",
"SchedulePauseStatusParam",
]


from databricks.bundles.alerts._models.aggregation import Aggregation, AggregationParam
from databricks.bundles.alerts._models.alert import Alert, AlertDict, AlertParam
from databricks.bundles.alerts._models.alert_evaluation_state import (
AlertEvaluationState,
AlertEvaluationStateParam,
)
from databricks.bundles.alerts._models.alert_statement_parameter import (
AlertStatementParameter,
AlertStatementParameterDict,
AlertStatementParameterParam,
)
from databricks.bundles.alerts._models.alert_v2_evaluation import (
AlertV2Evaluation,
AlertV2EvaluationDict,
AlertV2EvaluationParam,
)
from databricks.bundles.alerts._models.alert_v2_notification import (
AlertV2Notification,
AlertV2NotificationDict,
AlertV2NotificationParam,
)
from databricks.bundles.alerts._models.alert_v2_operand import (
AlertV2Operand,
AlertV2OperandDict,
AlertV2OperandParam,
)
from databricks.bundles.alerts._models.alert_v2_operand_column import (
AlertV2OperandColumn,
AlertV2OperandColumnDict,
AlertV2OperandColumnParam,
)
from databricks.bundles.alerts._models.alert_v2_operand_value import (
AlertV2OperandValue,
AlertV2OperandValueDict,
AlertV2OperandValueParam,
)
from databricks.bundles.alerts._models.alert_v2_run_as import (
AlertV2RunAs,
AlertV2RunAsDict,
AlertV2RunAsParam,
)
from databricks.bundles.alerts._models.alert_v2_subscription import (
AlertV2Subscription,
AlertV2SubscriptionDict,
AlertV2SubscriptionParam,
)
from databricks.bundles.alerts._models.comparison_operator import (
ComparisonOperator,
ComparisonOperatorParam,
)
from databricks.bundles.alerts._models.cron_schedule import (
CronSchedule,
CronScheduleDict,
CronScheduleParam,
)
from databricks.bundles.alerts._models.lifecycle import (
Lifecycle,
LifecycleDict,
LifecycleParam,
)
from databricks.bundles.alerts._models.permission import (
Permission,
PermissionDict,
PermissionParam,
)
from databricks.bundles.alerts._models.permission_level import (
PermissionLevel,
PermissionLevelParam,
)
from databricks.bundles.alerts._models.schedule_pause_status import (
SchedulePauseStatus,
SchedulePauseStatusParam,
)
19 changes: 19 additions & 0 deletions python/databricks/bundles/alerts/_models/aggregation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from enum import Enum

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This entire directory _models/ is autogenerated

from typing import Literal


class Aggregation(Enum):
SUM = "SUM"
COUNT = "COUNT"
COUNT_DISTINCT = "COUNT_DISTINCT"
AVG = "AVG"
MEDIAN = "MEDIAN"
MIN = "MIN"
MAX = "MAX"
STDDEV = "STDDEV"


AggregationParam = (
Literal["SUM", "COUNT", "COUNT_DISTINCT", "AVG", "MEDIAN", "MIN", "MAX", "STDDEV"]
| Aggregation
)
191 changes: 191 additions & 0 deletions python/databricks/bundles/alerts/_models/alert.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
from dataclasses import dataclass, field
from typing import TYPE_CHECKING, TypedDict

from databricks.bundles.alerts._models.alert_statement_parameter import (
AlertStatementParameter,
AlertStatementParameterParam,
)
from databricks.bundles.alerts._models.alert_v2_evaluation import (
AlertV2Evaluation,
AlertV2EvaluationParam,
)
from databricks.bundles.alerts._models.alert_v2_run_as import (
AlertV2RunAs,
AlertV2RunAsParam,
)
from databricks.bundles.alerts._models.cron_schedule import (
CronSchedule,
CronScheduleParam,
)
from databricks.bundles.alerts._models.lifecycle import Lifecycle, LifecycleParam
from databricks.bundles.alerts._models.permission import Permission, PermissionParam
from databricks.bundles.core._resource import Resource
from databricks.bundles.core._transform import _transform
from databricks.bundles.core._transform_to_json import _transform_to_json_value
from databricks.bundles.core._variable import (
VariableOr,
VariableOrList,
VariableOrOptional,
)

if TYPE_CHECKING:
from typing_extensions import Self


@dataclass(kw_only=True)
class Alert(Resource):
""""""

display_name: VariableOr[str]
"""
The display name of the alert.
"""

evaluation: VariableOr[AlertV2Evaluation]

query_text: VariableOr[str]
"""
Text of the query to be run.
"""

schedule: VariableOr[CronSchedule]

warehouse_id: VariableOr[str]
"""
ID of the SQL warehouse attached to the alert.
"""

custom_description: VariableOrOptional[str] = None
"""
Custom description for the alert. support mustache template.
"""

custom_summary: VariableOrOptional[str] = None
"""
Custom summary for the alert. support mustache template.
"""

file_path: VariableOrOptional[str] = None

lifecycle: VariableOrOptional[Lifecycle] = None
"""
Settings that control the deployment lifecycle of the resource, such as preventing it from being destroyed.
"""

parameters: VariableOrList[AlertStatementParameter] = field(default_factory=list)
"""
:meta private: [EXPERIMENTAL]

[Private Preview] Query parameters bound when executing the alert query, referenced in the
query text with `:name` syntax. Static values only.
"""

parent_path: VariableOrOptional[str] = None
"""
The workspace path of the folder containing the alert. Can only be set on create, and cannot be updated.
"""

permissions: VariableOrList[Permission] = field(default_factory=list)
"""
The permissions to apply to this resource.
"""

run_as: VariableOrOptional[AlertV2RunAs] = None
"""
Specifies the identity that will be used to run the alert.
This field allows you to configure alerts to run as a specific user or service principal.
- For user identity: Set `user_name` to the email of an active workspace user. Users can only set this to their own email.
- For service principal: Set `service_principal_name` to the application ID. Requires the `servicePrincipal/user` role.
If not specified, the alert will run as the request user.
"""

run_as_user_name: VariableOrOptional[str] = None
"""
[DEPRECATED] The run as username or application ID of service principal.
On Create and Update, this field can be set to application ID of an active service principal. Setting this field requires the servicePrincipal/user role.
Deprecated: Use `run_as` field instead. This field will be removed in a future release.
"""

@classmethod
def from_dict(cls, value: "AlertDict") -> "Self":
return _transform(cls, value)

def as_dict(self) -> "AlertDict":
return _transform_to_json_value(self) # type:ignore


class AlertDict(TypedDict, total=False):
""""""

display_name: VariableOr[str]
"""
The display name of the alert.
"""

evaluation: VariableOr[AlertV2EvaluationParam]

query_text: VariableOr[str]
"""
Text of the query to be run.
"""

schedule: VariableOr[CronScheduleParam]

warehouse_id: VariableOr[str]
"""
ID of the SQL warehouse attached to the alert.
"""

custom_description: VariableOrOptional[str]
"""
Custom description for the alert. support mustache template.
"""

custom_summary: VariableOrOptional[str]
"""
Custom summary for the alert. support mustache template.
"""

file_path: VariableOrOptional[str]

lifecycle: VariableOrOptional[LifecycleParam]
"""
Settings that control the deployment lifecycle of the resource, such as preventing it from being destroyed.
"""

parameters: VariableOrList[AlertStatementParameterParam]
"""
:meta private: [EXPERIMENTAL]

[Private Preview] Query parameters bound when executing the alert query, referenced in the
query text with `:name` syntax. Static values only.
"""

parent_path: VariableOrOptional[str]
"""
The workspace path of the folder containing the alert. Can only be set on create, and cannot be updated.
"""

permissions: VariableOrList[PermissionParam]
"""
The permissions to apply to this resource.
"""

run_as: VariableOrOptional[AlertV2RunAsParam]
"""
Specifies the identity that will be used to run the alert.
This field allows you to configure alerts to run as a specific user or service principal.
- For user identity: Set `user_name` to the email of an active workspace user. Users can only set this to their own email.
- For service principal: Set `service_principal_name` to the application ID. Requires the `servicePrincipal/user` role.
If not specified, the alert will run as the request user.
"""

run_as_user_name: VariableOrOptional[str]
"""
[DEPRECATED] The run as username or application ID of service principal.
On Create and Update, this field can be set to application ID of an active service principal. Setting this field requires the servicePrincipal/user role.
Deprecated: Use `run_as` field instead. This field will be removed in a future release.
"""


AlertParam = AlertDict | Alert
22 changes: 22 additions & 0 deletions python/databricks/bundles/alerts/_models/alert_evaluation_state.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from enum import Enum
from typing import Literal


class AlertEvaluationState(Enum):
"""
UNSPECIFIED - default unspecify value for proto enum, do not use it in the code
UNKNOWN - alert not yet evaluated
TRIGGERED - alert is triggered
OK - alert is not triggered
ERROR - alert evaluation failed
"""

UNKNOWN = "UNKNOWN"
TRIGGERED = "TRIGGERED"
OK = "OK"
ERROR = "ERROR"


AlertEvaluationStateParam = (
Literal["UNKNOWN", "TRIGGERED", "OK", "ERROR"] | AlertEvaluationState
)
Loading
Loading