-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Metabase channel #43924
Metabase channel #43924
Conversation
|
@@ -42,7 +42,8 @@ | |||
(process-query)) | |||
(process-query))] | |||
{:card card | |||
:result result})) | |||
:result result | |||
:type :card})) |
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.
adding a :type here so execute-card
this is considered a part
, which is an internal data type that both alert and dashboard subscription usees for rendering.
:bcc? true}) | ||
(mt/regex-email-bodies #"Daily Sad Toucans"))))))) | ||
|
||
(deftest send-placeholder-card-test-pulse-test |
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.
this is an old use case with pulse, it's no longer needed because this test endpoint only works on dashboard, and on dashboard all cards are saved.
;; This test follows a flow that the user/UI would follow by first creating a pulse, then making a small change to | ||
;; that pulse and testing it. The primary purpose of this test is to ensure tha the pulse/test endpoint accepts data | ||
;; of the same format that the pulse GET returns | ||
(deftest update-flow-test |
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.
same with above, it's an use case with the old pulse.
@@ -861,40 +752,6 @@ | |||
processed)) | |||
(is (= @titles ["a.png"])))))) | |||
|
|||
(deftest multi-channel-test |
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.
we have many tests for alert send to email and slack, this is not needed.
|
||
(deftest bcc-enabled-pulse-test |
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.
moved to metabase.channel.email_test
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.
99% of the code here and slack are moved from metabase.pulse
{:title card-name | ||
:titleUrl (urls/card-url card-id) | ||
:alertSchedule (alert-schedule-text channel) | ||
:notificationText (if (nil? non-user-email) |
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.
this was a bug before, alert email for non-user doesn't have the manage subscriptions link.
@@ -293,7 +293,7 @@ | |||
"Fetch a single *Pulse*, and hydrate it with a set of 'standard' hydrations; remove Alert columns, since this is a | |||
*Pulse* and they will all be unset." | |||
[pulse-or-id] | |||
(some-> (t2/select-one Pulse :id (u/the-id pulse-or-id), :alert_condition nil) | |||
(some-> (t2/select-one Pulse :id (u/the-id pulse-or-id)) |
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.
in principle we shouldn't use this function anymore because there is no longer pulse
, we should use retrieve-alert
instead. But the problem is that alert has :card
instead of :cards
like pulse does, so lots of rendering code will break if we change to retrieve-alert
.
I plan to rework this on the 2nd milestone, where we remove pulse alltogether
@@ -0,0 +1,102 @@ | |||
(ns metabase.channel.email |
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.
99% of the code here and slack are moved from metabase.pulse
This is a fairly big PR. So before I have a look, can you confirm what subset of the tech doc this PR completes? And can I read it as-is to understand the high-level design, or have the plans changed somewhat? |
@calherries This should partially address the Channel section in that tech doc. Specifically, this PR introduces 2 multimethods, |
((if (= :email channel-type) | ||
:channel/email | ||
:channel/slack) | ||
(pulse.test-util/with-captured-channel-send-messages! |
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.
if you look at how tests were written before you'll see 2 different approaches with email and slack.
For slack, the assertions are made against the result of (send-pulse!)
, this is done by having a bunch of redefs to make (send-pulse!)
return the rendered-notification for slack only.
But for email, the test ignore the result of (send-pulse!)
, instead it checks results from the global (mt/inbox)
atom.
I also think the recent flakes with pulse is because we were using this global inbox
atom, it could be that parallel tests mutate the inbox while a test is running.
So I create a new pulse.test-util/with-captured-channel-send-messages!
macro which will capture all calls to (channel/send!)
, this function should take a message
that is already rendered and is ready to send. Which means: for email, it's a html with recipients info, for slack: It contains all the rendered attachments and text.
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.
I also believe this will fix our flakes with pulse recently.
:email (thunk) | ||
:slack (pulse.test-util/slack-test-setup! (thunk))))))))) | ||
|
||
(defn- tests! |
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.
this test helper uses redefs so it must end with !
(fn [_ _] | ||
(is (= (rasta-pulse-email) | ||
(mt/summarize-multipart-email #"Pulse Name")))) | ||
(fn [_ [email]] |
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.
the result here is a list of emails, since this test only sends one we can take the first.
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.
IDK, aside from nitpicks - seems like this is exactly what is planned. :)
Introducing a new module: Channel™.
See the tech doc: https://www.notion.so/metabase/Notification-high-level-design-9620a4a69db0494f806a146cc9174964?pvs=4 for a detailed design.
What this PR does:
render-notification
andsend!
This PR shouldn't generate any behavior changes, though you'll see a bunch of tests got updated because many of our tests were written when we still have: pulse -- which is a notification with one or more cards. So I had to update those tests, some are reworked to alert test, some are removed.
Walk through of this PR and repl demo: loom
Results
Dashboard subscriptions
Email
Before
![Screenshot 2024-06-11 at 18 42 49](https://private-user-images.githubusercontent.com/25661381/338568557-c52307f9-d315-4da7-9728-e51a419da7ea.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTkyMzIzMDAsIm5iZiI6MTcxOTIzMjAwMCwicGF0aCI6Ii8yNTY2MTM4MS8zMzg1Njg1NTctYzUyMzA3ZjktZDMxNS00ZGE3LTk3MjgtZTUxYTQxOWRhN2VhLnBuZz9YLUFtei1BbGdvcml0aG09QVd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2Y5NzRkYzYyNDVmYmUzODQ3NmMyMTUwODMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.HpX2dU4waG7RoN_pp-og7xl-uYRiHmsxjdSqT5mxyuY)
Slack
Before
![Screenshot 2024-06-11 at 18 45 29](https://private-user-images.githubusercontent.com/25661381/338569329-2ce131da-0b1e-4413-a0f7-df86e79f0d69.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTkyMzIzMDAsIm5iZiI6MTcxOTIzMjAwMCwicGF0aCI6Ii8yNTY2MTM4MS8zMzg1NjkzMjktMmNlMTMxZGEtMGIxZS00NDEzLWEwZjctZGY4NmU3OWYwZDY5LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA2MjQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjI0VDEyMjY0MFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTNiYjJiNWE3MDgyZDVhY2YxNTZmM2Y0NDcwODVhMjA1OGQyYzViNjEyZWM2ODRmZjcwMGE1M2VjM2YxZjhjMTYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.g9wqUCyFuRBB9u92vEvuaGwl3d4OIgbwE9eWB-AcTrA)
After
![Screenshot 2024-06-11 at 18 44 25](https://private-user-images.githubusercontent.com/25661381/338569042-f95abe64-968a-4f97-84f3-9c4994aeae85.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTkyMzIzMDAsIm5iZiI6MTcxOTIzMjAwMCwicGF0aCI6Ii8yNTY2MTM4MS8zMzg1NjkwNDItZjk1YWJlNjQtOTY4YS00Zjk3LTg0ZjMtOWM0OTk0YWVhZTg1LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA2MjQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjI0VDEyMjY0MFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTNjYWQzYTEwNjgzNWJkNWEwMmYxNzg0MjA3MTFkOTQ1YTgxZTRmMTU3YWY1Nzk1ODljYzUyNmM1MWUzYzYyOWEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.XVrV2cr6-Ci3niOp7U5gy42FBjPRhpJuaCC6zAjelnM)
Alert
Email
Before
![Screenshot 2024-06-11 at 18 56 37](https://private-user-images.githubusercontent.com/25661381/338572444-94f43f16-7615-404c-94ee-668a15744d6e.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTkyMzIzMDAsIm5iZiI6MTcxOTIzMjAwMCwicGF0aCI6Ii8yNTY2MTM4MS8zMzg1NzI0NDQtOTRmNDNmMTYtNzYxNS00MDRjLTk0ZWUtNjY4YTE1NzQ0ZDZlLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA2MjQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjI0VDEyMjY0MFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWJkNDY0ZmM1MWIwMzRkNzRiODFiZTJkYmQ2ODNhNDFmZDAwNWJkM2Q1MzkxNWNlZWI1OTU5Y2RkOWIwZTQ1MDEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.h8UWGi0LAQsK76xWQQ58aWuH1WfFrZY--NHzyNm2kEc)
After
![Screenshot 2024-06-11 at 18 52 09](https://private-user-images.githubusercontent.com/25661381/338571424-296f9c94-73eb-4d59-977d-af8a98fb0516.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTkyMzIzMDAsIm5iZiI6MTcxOTIzMjAwMCwicGF0aCI6Ii8yNTY2MTM4MS8zMzg1NzE0MjQtMjk2ZjljOTQtNzNlYi00ZDU5LTk3N2QtYWY4YTk4ZmIwNTE2LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA2MjQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjI0VDEyMjY0MFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWFmZDllZWU4ZDc1NGEyMzE0N2I5OTVlZjk5OGNjMjdlOTVmMTA0NmQyODk4OWNlOGY5OTdlYzhmYzUzZjY5MjUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.tNiIeFGWr83oOV6HApVqR8Jx7mXDhh4ANsEhh2WL3tA)
Slack
Before
![Screenshot 2024-06-11 at 18 56 54](https://private-user-images.githubusercontent.com/25661381/338572486-baba3c1c-0801-482c-a64c-9fd5d57d420f.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTkyMzIzMDAsIm5iZiI6MTcxOTIzMjAwMCwicGF0aCI6Ii8yNTY2MTM4MS8zMzg1NzI0ODYtYmFiYTNjMWMtMDgwMS00ODJjLWE2NGMtOWZkNWQ1N2Q0MjBmLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA2MjQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjI0VDEyMjY0MFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTE4NmNlM2JkMmI3ZjZlZDVlYThjZGU1MzFlMmZmNzZjNDY1NzkwNGZhYmVjNzcwNmYzZjlhZGZiMjM3OTBhNmEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.vhJLdCVzCwA4Zfy6MNxCA7oaPw1BH-IGXgo1SRiL3b4)
After
![Screenshot 2024-06-11 at 18 55 23](https://private-user-images.githubusercontent.com/25661381/338572084-d02b15bd-7064-48ce-9b31-871578ec0a5b.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTkyMzIzMDAsIm5iZiI6MTcxOTIzMjAwMCwicGF0aCI6Ii8yNTY2MTM4MS8zMzg1NzIwODQtZDAyYjE1YmQtNzA2NC00OGNlLTliMzEtODcxNTc4ZWMwYTViLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA2MjQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjI0VDEyMjY0MFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWNiOGI0MjZjNTFiMDFmZWNmOGMzNTA3OGIzNTMxNWNhMmJmYmRkYTU4NmQ2ZTUzYjM5MWRkZTlkYjY2ZDI4NTgmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.Fp57QlleZvVZGYo_ErE-OQot6nnULwM9rpCKSEdJ2Bg)
Note on testing update:
you'll see a lot of changes are about adding
alert_condition = rows
to the Pulse, this is because previously we have the Pulse feature -- which is a notification with one or more cards, it's different from dashboard subscriptions in that it doesn't associate with a dashboard. or you can think of it like : Alert is a special case of Pulse where it has only one card.Since this feature is deprecated, I've converted most of the pulse tests to alert tests to change from a pulse to an alert; it's simply by adding an
alert_condition
.Milestone 1 of: #43822