-
Notifications
You must be signed in to change notification settings - Fork 13.8k
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
feat(reports): execute as other than selenium user #21931
Conversation
Codecov Report
@@ Coverage Diff @@
## master #21931 +/- ##
==========================================
+ Coverage 66.92% 66.98% +0.05%
==========================================
Files 1807 1808 +1
Lines 69238 69289 +51
Branches 7407 7407
==========================================
+ Hits 46338 46412 +74
+ Misses 20991 20968 -23
Partials 1909 1909
Flags with carried forward coverage won't be shown. Click here to find out more.
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
69ed115
to
0af896d
Compare
superset/reports/commands/execute.py
Outdated
if user_type == "selenium": | ||
return app.config["THUMBNAIL_SELENIUM_USER"] | ||
if user_type == "creator": | ||
if user := report_schedule.created_by: |
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.
@villebro the walrus operator isn't supported in Python 3.8.
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.
Hmm, I do believe it is: https://docs.python.org/3/whatsnew/3.8.html#assignment-expressions
dashboard_state = self._report_schedule.extra.get("dashboard") | ||
if dashboard_state: | ||
permalink_key = CreateDashboardPermalinkCommand( | ||
dashboard_id=self._report_schedule.dashboard_id, | ||
dashboard_id=str(self._report_schedule.dashboard_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.
Is Mypy not working as expected? Also why should the ID be a string?
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.
Mypy actually picked this up. This is due to slugs and ids being used interchangeably in the codebase (I remember being frustrated about this when working on the permalink feature). In older dashboard and chart code this is usually referred to as id_or_slug
which is a str
, but in the permalink code we decided to just go with (dashboard|chart)_id
.
1dfe1ca
to
e833ea3
Compare
@@ -15,6 +15,8 @@ | |||
# specific language governing permissions and limitations | |||
# under the License. | |||
|
|||
from __future__ import annotations |
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.
Minor bycatches
class ReportScheduleSelleniumUserNotFoundError(CommandException): | ||
message = _("Report Schedule sellenium user not found") | ||
class ReportScheduleUserNotFoundError(CommandException): | ||
message = _("Report Schedule user not found") |
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.
There was a typo here + we should make this more generic now as it's not really bound to a specific Selenium user
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.
Tested in my local, and work as expected. leave a non-blocked suggestions.
Could output the Report/Alert's sender in the logging? Because it's hard to determine who send the notification from the current logging.
[2022-10-27 15:38:00,050: INFO/ForkPoolWorker-8] Scheduling alert Test Report eta: 2022-10-27 07:38:00
Executing alert/report, task id: 0aa521ec-670d-4c0f-aec7-78c13fb7ba79, scheduled_dttm: 2022-10-27T07:38:00
[2022-10-27 15:38:00,059: INFO/ForkPoolWorker-8] Executing alert/report, task id: 0aa521ec-670d-4c0f-aec7-78c13fb7ba79, scheduled_dttm: 2022-10-27T07:38:00
session is validated: id 4, executionid: 0aa521ec-670d-4c0f-aec7-78c13fb7ba79
[2022-10-27 15:38:00,060: INFO/ForkPoolWorker-8] session is validated: id 4, executionid: 0aa521ec-670d-4c0f-aec7-78c13fb7ba79
Getting chart from http://127.0.0.1:8088/api/v1/chart/316/data/?format=json&type=post_processed&force=true
[2022-10-27 15:38:00,135: INFO/ForkPoolWorker-8] Getting chart from http://127.0.0.1:8088/api/v1/chart/316/data/?format=json&type=post_processed&force=true
Would send notification for alert Test Report, to {"target": "foo@foo.com"}
[2022-10-27 15:38:00,398: INFO/ForkPoolWorker-8] Would send notification for alert Test Report, to {"target": "foo@foo.com"}
@zhaoyongjie that's an excellent idea! 👏 I will add it |
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.
Looks great. I love the new logging because it makes debugging so easy.
Let's avoid logging user emails please |
98eb58e
to
6575aa7
Compare
6575aa7
to
adeaeb2
Compare
Hello @villebro! |
@Always-prog yes, I'm actually using this locally and it works as expected. Endless execution usually implies that the report wasn't able to render successfully. To double check that there's a regression, are you able to revert this PR and make it work again? Also, did you try to execute as the Selenium user with this PR as is the default? Doing it like this should work similarly as before - if not there may very well be a regression that I'm not aware of. |
Thank you for answer. I'll test it again. |
Sorry, my bad! |
@Always-prog thanks for confirming 👍 |
@villebro, Thanks for your commitment :) |
SUMMARY
Currently Alerts & Reports only supports executing the report and alert queries as the
THUMBNAIL_SELENIUM_USER
. This can be problematic in a scenario where user impersonation is enabled and there isn't a service account that has full access to all datasources or Superset objects.To remedy this, this PR adds a config option
ALERT_REPORTS_EXECUTE_AS
making it possible to execute reports asTHUMBNAIL_SELENIUM_USER
The config is a list of values, meaning that if the first option isn't found (e.g. in the case of alerts/reports created programmatically where the
created_by
,changed_by
orowners
is undefined), it will move to the next option. By default it will be set to use theselenium
user so as to not introduce a breaking change.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
TESTING INSTRUCTIONS
ADDITIONAL INFORMATION