feat: allow more structured slack messages#2144
Conversation
Slack allows more structured notifications than a console or an email. This changes the base class so it passes down more information from the notification to concrete implementations. For slack, it will convert this information into a more structure message. For other text-based targets, the anther base class is now available.
sqlmesh/core/notification_target.py
Outdated
| f"*Model*: `{audit_error.model_name}`", | ||
| f"*Count*: `{audit_error.count}`", | ||
| ), | ||
| slack.preformatted_rich_text_block(str(audit_error.query)), |
There was a problem hiding this comment.
Instead of doing
str(audit_error.query)
You can do:
audit_error.sql(dialect=audit_error.audit.dialect)
If you also want to format the query you can do:
audit_error.sql(dialect=audit_error.model.dialect, pretty=True)
There was a problem hiding this comment.
Please note that audit_error.model is optional, so the None check might be required.
There was a problem hiding this comment.
@izeigerman thanks for the guidance.
AuditError doesn't seem to hold on to Audit (see here). Should I:
- add an
audit: Auditfield - add a
dialect: strfield and populate it fromaudit.dialect - add a
dialect: strfield and populate it fromengine_adapter.dialect - add a
dialect: strfield and populate it fromsnapshot.model.dialect
All of these options would happen around here
There was a problem hiding this comment.
I suggest the engine_adapter dialect since that would be the dialect used to actually run the audit. Another option would be to stored the rendered audit query in the error, but then you'd lose the flexibility to format it (I guess you could parse it back into a sqlglot expression again).
|
@plaflamme this looks great, thank you!
Left a comment with the explanation. |
Also adds a `sql` helper method on `AuditError` to obtain the sql statement.
This change allows more structure in slack messages.
Specifically, audit failures and general failures are now formatted using a code block. Furthermore, audit failures will show the audit name, model and count failures more prominently.
Here's an example of what an audit failure message should look like
The other thing I'd like to improve is to have the audit's SQL be in the correct dialect. Not sure what the recommended approach for that would be: any guidance would be appreciated.