Skip to content
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

chore: log different selenium timeout errors differently #23290

Merged
merged 2 commits into from
Mar 9, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 35 additions & 15 deletions superset/utils/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,22 +176,42 @@ def get_screenshot(
sleep(selenium_headstart)

try:
logger.debug("Wait for the presence of %s", element_name)
element = WebDriverWait(driver, self._screenshot_locate_wait).until(
EC.presence_of_element_located((By.CLASS_NAME, element_name))
)
try:
# page didn't load
logger.debug("Wait for the presence of %s", element_name)
element = WebDriverWait(driver, self._screenshot_locate_wait).until(
EC.presence_of_element_located((By.CLASS_NAME, element_name))
)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are most likely going to be network errors, i.e., server is down or url is incorrect, or perhaps permissions - user can't access the page.

except TimeoutException as ex:
logger.exception("Selenium timed out requesting url %s", url)
raise ex

logger.debug("Wait for chart containers to draw")
WebDriverWait(driver, self._screenshot_locate_wait).until(
EC.visibility_of_all_elements_located(
(By.CLASS_NAME, "slice_container")
try:
# chart containers didn't render
logger.debug("Wait for chart containers to draw")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a little more detail to these debug statements, such as the url in order to aid debugging?

WebDriverWait(driver, self._screenshot_locate_wait).until(
EC.visibility_of_all_elements_located(
(By.CLASS_NAME, "slice_container")
)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These imo are going to be client errors, and will show as errors on the dashboard when the user views it, not just in reports. This is an example where the client db is down. Also dataset role access will show these errors. There's a flag SCREENSHOT_REPLACE_UNEXPECTED_ERRORS to show better errors here in the screenshots.
trino

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is one area where I think a warning may make sense. @craig-rueda what do you think here?

)
)
except TimeoutException as ex:
logger.exception(
"Selenium timed out waiting for chart containers to draw at url %s",
url,
)
raise ex

logger.debug("Wait for loading element of charts to be gone")
WebDriverWait(driver, self._screenshot_load_wait).until_not(
EC.presence_of_all_elements_located((By.CLASS_NAME, "loading"))
)
try:
# charts took too long to load
logger.debug("Wait for loading element of charts to be gone")
WebDriverWait(driver, self._screenshot_load_wait).until_not(
Copy link
Member Author

@eschutho eschutho Mar 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this error is going to be because the client db took too long to return the data. Some optimization is possible on either the client db or the superset instance to tune timeouts. Warning vs exception here is a little questionable.

EC.presence_of_all_elements_located((By.CLASS_NAME, "loading"))
)
except TimeoutException as ex:
logger.exception(
"Selenium timed out waiting for charts to load at url %s", url
)
raise ex

selenium_animation_wait = current_app.config[
"SCREENSHOT_SELENIUM_ANIMATION_WAIT"
Expand All @@ -215,9 +235,9 @@ def get_screenshot(
)

img = element.screenshot_as_png

except TimeoutException:
logger.exception("Selenium timed out requesting url %s", url)
# raise again for the finally block, but handled above
pass
except StaleElementReferenceException:
logger.exception(
"Selenium got a stale element while requesting url %s",
Expand Down