-
Notifications
You must be signed in to change notification settings - Fork 214
Add PyDABs support for SQL Alerts #6335
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
Draft
Sankalp-Mittal
wants to merge
6
commits into
main
Choose a base branch
from
sankalp-mittal/pydabs-support-for-alerts
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d43471f
add alert codegen
Sankalp-Mittal 46757e8
add manual wiring
Sankalp-Mittal b28ad73
add mutators
Sankalp-Mittal 0d500ba
add tests
Sankalp-Mittal ed5b9dc
add Alerts import
Sankalp-Mittal d3e7d64
allow variable article to be used
Sankalp-Mittal 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 hidden or 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 hidden or 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,123 @@ | ||
| __all__ = [ | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
| ) | ||
This file contains hidden or 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,19 @@ | ||
| from enum import Enum | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This entire directory |
||
| 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 | ||
| ) | ||
This file contains hidden or 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,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
22
python/databricks/bundles/alerts/_models/alert_evaluation_state.py
This file contains hidden or 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,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 | ||
| ) |
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.
These 2 had to be added manually but I think they can be found out using BFS and potentially stored in a yaml file