Add extra configration to the email reports (#9342)
Superset email. Fix slice url Make WEBDRIVER_BASEURL a function Co-authored-by: bogdan kyryliuk <bogdankyryliuk@dropbox.com>
This commit is contained in:
parent
b532c4609f
commit
1d3b264a36
|
|
@ -751,6 +751,11 @@ WEBDRIVER_CONFIGURATION: Dict[Any, Any] = {}
|
|||
|
||||
# The base URL to query for accessing the user interface
|
||||
WEBDRIVER_BASEURL = "http://0.0.0.0:8080/"
|
||||
# The base URL for the email report hyperlinks.
|
||||
WEBDRIVER_BASEURL_USER_FRIENDLY = WEBDRIVER_BASEURL
|
||||
# Time in seconds, selenium will wait for the page to load
|
||||
# and render for the email report.
|
||||
EMAIL_PAGE_RENDER_WAIT = 30
|
||||
|
||||
# Send user to a link where they can report bugs
|
||||
BUG_REPORT_URL = None
|
||||
|
|
|
|||
|
|
@ -58,9 +58,9 @@ config = app.config
|
|||
logger = logging.getLogger("tasks.email_reports")
|
||||
logger.setLevel(logging.INFO)
|
||||
|
||||
# Time in seconds, we will wait for the page to load and render
|
||||
PAGE_RENDER_WAIT = 30
|
||||
|
||||
EMAIL_PAGE_RENDER_WAIT = config["EMAIL_PAGE_RENDER_WAIT"]
|
||||
WEBDRIVER_BASEURL = config["WEBDRIVER_BASEURL"]
|
||||
WEBDRIVER_BASEURL_USER_FRIENDLY = config["WEBDRIVER_BASEURL_USER_FRIENDLY"]
|
||||
|
||||
EmailContent = namedtuple("EmailContent", ["body", "data", "images"])
|
||||
|
||||
|
|
@ -152,11 +152,12 @@ def _get_auth_cookies() -> List[TypeConversionDict]:
|
|||
return cookies
|
||||
|
||||
|
||||
def _get_url_path(view: str, **kwargs: Any) -> str:
|
||||
def _get_url_path(view: str, user_friendly: bool = False, **kwargs: Any) -> str:
|
||||
with app.test_request_context():
|
||||
return urllib.parse.urljoin(
|
||||
str(config["WEBDRIVER_BASEURL"]), url_for(view, **kwargs)
|
||||
base_url = (
|
||||
WEBDRIVER_BASEURL_USER_FRIENDLY if user_friendly else WEBDRIVER_BASEURL
|
||||
)
|
||||
return urllib.parse.urljoin(str(base_url), url_for(view, **kwargs))
|
||||
|
||||
|
||||
def create_webdriver() -> Union[
|
||||
|
|
@ -225,19 +226,22 @@ def deliver_dashboard(schedule: DashboardEmailSchedule) -> None:
|
|||
dashboard = schedule.dashboard
|
||||
|
||||
dashboard_url = _get_url_path("Superset.dashboard", dashboard_id=dashboard.id)
|
||||
dashboard_url_user_friendly = _get_url_path(
|
||||
"Superset.dashboard", user_friendly=True, dashboard_id=dashboard.id
|
||||
)
|
||||
|
||||
# Create a driver, fetch the page, wait for the page to render
|
||||
driver = create_webdriver()
|
||||
window = config["WEBDRIVER_WINDOW"]["dashboard"]
|
||||
driver.set_window_size(*window)
|
||||
driver.get(dashboard_url)
|
||||
time.sleep(PAGE_RENDER_WAIT)
|
||||
time.sleep(EMAIL_PAGE_RENDER_WAIT)
|
||||
|
||||
# Set up a function to retry once for the element.
|
||||
# This is buggy in certain selenium versions with firefox driver
|
||||
get_element = getattr(driver, "find_element_by_class_name")
|
||||
element = retry_call(
|
||||
get_element, fargs=["grid-container"], tries=2, delay=PAGE_RENDER_WAIT
|
||||
get_element, fargs=["grid-container"], tries=2, delay=EMAIL_PAGE_RENDER_WAIT
|
||||
)
|
||||
|
||||
try:
|
||||
|
|
@ -251,7 +255,7 @@ def deliver_dashboard(schedule: DashboardEmailSchedule) -> None:
|
|||
|
||||
# Generate the email body and attachments
|
||||
email = _generate_mail_content(
|
||||
schedule, screenshot, dashboard.dashboard_title, dashboard_url
|
||||
schedule, screenshot, dashboard.dashboard_title, dashboard_url_user_friendly
|
||||
)
|
||||
|
||||
subject = __(
|
||||
|
|
@ -271,7 +275,9 @@ def _get_slice_data(schedule: SliceEmailSchedule) -> EmailContent:
|
|||
)
|
||||
|
||||
# URL to include in the email
|
||||
url = _get_url_path("Superset.slice", slice_id=slc.id)
|
||||
slice_url_user_friendly = _get_url_path(
|
||||
"Superset.slice", slice_id=slc.id, user_friendly=True
|
||||
)
|
||||
|
||||
cookies = {}
|
||||
for cookie in _get_auth_cookies():
|
||||
|
|
@ -298,7 +304,7 @@ def _get_slice_data(schedule: SliceEmailSchedule) -> EmailContent:
|
|||
columns=columns,
|
||||
rows=rows,
|
||||
name=slc.slice_name,
|
||||
link=url,
|
||||
link=slice_url_user_friendly,
|
||||
)
|
||||
|
||||
elif schedule.delivery_type == EmailDeliveryType.attachment:
|
||||
|
|
@ -306,7 +312,7 @@ def _get_slice_data(schedule: SliceEmailSchedule) -> EmailContent:
|
|||
body = __(
|
||||
'<b><a href="%(url)s">Explore in Superset</a></b><p></p>',
|
||||
name=slc.slice_name,
|
||||
url=url,
|
||||
url=slice_url_user_friendly,
|
||||
)
|
||||
|
||||
return EmailContent(body, data, None)
|
||||
|
|
@ -321,9 +327,12 @@ def _get_slice_visualization(schedule: SliceEmailSchedule) -> EmailContent:
|
|||
driver.set_window_size(*window)
|
||||
|
||||
slice_url = _get_url_path("Superset.slice", slice_id=slc.id)
|
||||
slice_url_user_friendly = _get_url_path(
|
||||
"Superset.slice", slice_id=slc.id, user_friendly=True
|
||||
)
|
||||
|
||||
driver.get(slice_url)
|
||||
time.sleep(PAGE_RENDER_WAIT)
|
||||
time.sleep(EMAIL_PAGE_RENDER_WAIT)
|
||||
|
||||
# Set up a function to retry once for the element.
|
||||
# This is buggy in certain selenium versions with firefox driver
|
||||
|
|
@ -331,7 +340,7 @@ def _get_slice_visualization(schedule: SliceEmailSchedule) -> EmailContent:
|
|||
driver.find_element_by_class_name,
|
||||
fargs=["chart-container"],
|
||||
tries=2,
|
||||
delay=PAGE_RENDER_WAIT,
|
||||
delay=EMAIL_PAGE_RENDER_WAIT,
|
||||
)
|
||||
|
||||
try:
|
||||
|
|
@ -344,7 +353,9 @@ def _get_slice_visualization(schedule: SliceEmailSchedule) -> EmailContent:
|
|||
destroy_webdriver(driver)
|
||||
|
||||
# Generate the email body and attachments
|
||||
return _generate_mail_content(schedule, screenshot, slc.slice_name, slice_url)
|
||||
return _generate_mail_content(
|
||||
schedule, screenshot, slc.slice_name, slice_url_user_friendly
|
||||
)
|
||||
|
||||
|
||||
def deliver_slice(schedule: Union[DashboardEmailSchedule, SliceEmailSchedule]) -> None:
|
||||
|
|
|
|||
Loading…
Reference in New Issue