Skip to content
Open
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
24 changes: 24 additions & 0 deletions acceptance/bundle/python/alerts-support/databricks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
bundle:
name: my_project

sync: {paths: []} # don't need to copy files

python:
resources:
- "resources:load_resources"
mutators:
- "mutators:update_alert"

resources:
alerts:
my_alert_1:
display_name: "My Alert"
query_text: "SELECT 1"
warehouse_id: "my_warehouse"
evaluation:
comparison_operator: "GREATER_THAN"
source:
name: "column_1"
schedule:
quartz_cron_schedule: "0 0 0 * * ?"
timezone_id: "UTC"
11 changes: 11 additions & 0 deletions acceptance/bundle/python/alerts-support/mutators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from dataclasses import replace

from databricks.bundles.alerts import Alert
from databricks.bundles.core import alert_mutator


@alert_mutator
def update_alert(alert: Alert) -> Alert:
assert isinstance(alert.display_name, str)

return replace(alert, display_name=f"{alert.display_name} (updated)")
3 changes: 3 additions & 0 deletions acceptance/bundle/python/alerts-support/out.test.toml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 50 additions & 0 deletions acceptance/bundle/python/alerts-support/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

>>> uv run [UV_ARGS] -q [CLI] bundle validate --output json
{
"experimental": {
"python": {
"mutators": [
"mutators:update_alert"
],
"resources": [
"resources:load_resources"
]
}
},
"resources": {
"alerts": {
"my_alert_1": {
"display_name": "My Alert (updated)",
"evaluation": {
"comparison_operator": "GREATER_THAN",
"source": {
"name": "column_1"
}
},
"parent_path": "/Workspace/Users/[USERNAME]/.bundle/my_project/default/resources",
"query_text": "SELECT 1",
"schedule": {
"quartz_cron_schedule": "0 0 0 * * ?",
"timezone_id": "UTC"
},
"warehouse_id": "my_warehouse"
},
"my_alert_2": {
"display_name": "My Alert (2) (updated)",
"evaluation": {
"comparison_operator": "LESS_THAN",
"source": {
"name": "column_2"
}
},
"parent_path": "/Workspace/Users/[USERNAME]/.bundle/my_project/default/resources",
"query_text": "SELECT 2",
"schedule": {
"quartz_cron_schedule": "0 0 12 * * ?",
"timezone_id": "UTC"
},
"warehouse_id": "my_warehouse_2"
}
}
}
}
24 changes: 24 additions & 0 deletions acceptance/bundle/python/alerts-support/resources.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from databricks.bundles.core import Resources


def load_resources() -> Resources:
resources = Resources()

resources.add_alert(
"my_alert_2",
{
"display_name": "My Alert (2)",
"query_text": "SELECT 2",
"warehouse_id": "my_warehouse_2",
"evaluation": {
"comparison_operator": "LESS_THAN",
"source": {"name": "column_2"},
},
"schedule": {
"quartz_cron_schedule": "0 0 12 * * ?",
"timezone_id": "UTC",
},
},
)

return resources
5 changes: 5 additions & 0 deletions acceptance/bundle/python/alerts-support/script
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

trace uv run $UV_ARGS -q $CLI bundle validate --output json | \
jq "pick(.experimental.python, .resources)"

rm -fr .databricks __pycache__
4 changes: 4 additions & 0 deletions acceptance/bundle/python/alerts-support/test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Cloud = false # tests don't interact with APIs

# alerts are only supported in the current version of the wheel
EnvMatrix.PYDAB_VERSION = ["current"]
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
)
Loading
Loading