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

feat: Implement using Playwright for taking screenshots in reports #25247

Merged
merged 16 commits into from
Oct 4, 2023

Conversation

kgabryje
Copy link
Member

@kgabryje kgabryje commented Sep 10, 2023

SUMMARY

Implements SIP-98.

If a feature flag PLAYWRIGHT_REPORTS_AND_THUMBNAILS is on, use Playwright instead of Selenium to take screenshots of dashboards and charts when preparing reports and thumbnails.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

The change should be visible when running a report on a dashboard that contains deck.gl charts.
Before:

image

After:

image

TESTING INSTRUCTIONS

  1. Enable PLAYWRIGHT_REPORTS_AND_THUMBNAILS ff
  2. Setup reports (https://superset.apache.org/docs/installation/alerts-reports/)
  3. Create a report and verify that the screenshot was taken correctly. If possible, also verify using deck.gl charts
  4. Generate thumbnails (https://superset.apache.org/docs/installation/cache/#caching-thumbnails)
  5. Verify that thumbnails screenshots were taken correctly (including deck.gl charts)
  6. If the feature flag is disabled, the screenshots should be taken using Selenium - no changes.

ADDITIONAL INFORMATION

Copy link
Member

@villebro villebro left a comment

Choose a reason for hiding this comment

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

Exciting stuff. First pass, comments mainly related to whether or not we should add the deps as required vs optional. I also have some unrelated grievances with how the current Allerts & Reports feature handles errors, but let's chat about those separately (=this is a good opportunity to think about improving this as we're refactoring the code that detects whether or not the page has rendered).

Comment on lines 234 to 235
playwright==1.37.0
# via apache-superset
Copy link
Member

Choose a reason for hiding this comment

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

I think this should probably go into the dev, integration or test deps

Copy link
Member Author

Choose a reason for hiding this comment

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

Could you explain why? Isn't reports one of the basic flows? Or maybe I misunderstand the purpose of those files

Copy link
Member

Choose a reason for hiding this comment

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

The fact that it's marked as an optional dependency in setup.py IMO means it should not be in base.txt. Was this entry added by hand, or via pip-compile-multi? I assume we'd need to change requirements/base.in as follows to autogenerate this:

-e file:.[playwright]

setup.py Outdated
@@ -108,6 +108,7 @@ def get_git_sha() -> str:
"pandas[performance]>=2.0.3, <2.1",
"parsedatetime",
"pgsanity",
"playwright",
Copy link
Member

Choose a reason for hiding this comment

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

Should we move this into an optional dep until selenium is deprecated?

Copy link
Member Author

Choose a reason for hiding this comment

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

Where are the optional deps located?

Copy link
Member

Choose a reason for hiding this comment

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

That's a good idea. @kgabryje in extras_require below.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, moved

@@ -31,6 +31,8 @@ fi
if [ -f "${REQUIREMENTS_LOCAL}" ]; then
echo "Installing local overrides at ${REQUIREMENTS_LOCAL}"
pip install --no-cache-dir -r "${REQUIREMENTS_LOCAL}"
playwright install-deps
playwright install chromium
Copy link
Member

Choose a reason for hiding this comment

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

What's the correlation between the local overwrite config and installing playwright?

Copy link
Member Author

Choose a reason for hiding this comment

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

There isn't, it's a leftover from my tests in POC phase 🤦 updated

Copy link
Member Author

Choose a reason for hiding this comment

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

@eschutho Actually, now that we moved playwright to optional packages, I think we should make installing additional deps conditional. Do we have an established pattern for that?

@@ -23,6 +23,7 @@

from flask import current_app, Flask, request, Response, session
from flask_login import login_user
from playwright.sync_api import BrowserContext
Copy link
Member

Choose a reason for hiding this comment

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

you can move this import down to the authenticate_playwright_browser_context method if you get errors on it not loading when the feature flag is not on.

Copy link
Member Author

Choose a reason for hiding this comment

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

I put the import behind a feature flag check - I couldn't move it to the method as it was used for typing that method

Copy link
Member Author

Choose a reason for hiding this comment

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

Scratch that, importing feature_flag_manager causes a circular import

elif request.cookies:
cookies = request.cookies
else:
cookies = {}
Copy link
Member

Choose a reason for hiding this comment

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

should we try to dry this up from the other authenticate method?

@kgabryje
Copy link
Member Author

/testenv up FEATURE_PLAYWRIGHT_REPORTS_AND_THUMBNAILS=true

@github-actions
Copy link
Contributor

@kgabryje Ephemeral environment spinning up at http://18.236.98.170:8080. Credentials are admin/admin. Please allow several minutes for bootstrapping and startup.

Copy link
Member

@villebro villebro left a comment

Choose a reason for hiding this comment

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

I think this is good to go after we decide on how to handle this new dependency.

Comment on lines 234 to 235
playwright==1.37.0
# via apache-superset
Copy link
Member

Choose a reason for hiding this comment

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

The fact that it's marked as an optional dependency in setup.py IMO means it should not be in base.txt. Was this entry added by hand, or via pip-compile-multi? I assume we'd need to change requirements/base.in as follows to autogenerate this:

-e file:.[playwright]

setup.py Outdated Show resolved Hide resolved
Copy link
Member

@villebro villebro left a comment

Choose a reason for hiding this comment

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

I think we should be consistent in either having separate func overrides in the constructor if the authenticate methods are separate, or merge them so as to only support one screenshot mechanism.

docker/docker-bootstrap.sh Show resolved Hide resolved
superset/utils/machine_auth.py Outdated Show resolved Hide resolved
Copy link
Member

@villebro villebro left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for all the hard work here! ❤️

Copy link
Member

@eschutho eschutho left a comment

Choose a reason for hiding this comment

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

Looks great @kgabryje!

@kgabryje kgabryje merged commit ff95d0f into apache:master Oct 4, 2023
29 checks passed
@github-actions
Copy link
Contributor

github-actions bot commented Oct 4, 2023

Ephemeral environment shutdown and build artifacts deleted.

@kgabryje
Copy link
Member Author

kgabryje commented Oct 4, 2023

Thank you @villebro @eschutho for your comments and help to get this PR merged!

@eschutho eschutho added the risk:breaking-change Issues or PRs that will introduce breaking changes label Oct 4, 2023
@eschutho
Copy link
Member

eschutho commented Oct 4, 2023

@kgabryje I left a comment on a part that may break existing functionality. I'd suggest let's see if we can quickly fix forward.

sadpandajoe added a commit to preset-io/superset that referenced this pull request Oct 6, 2023
jinghua-qa added a commit to preset-io/superset that referenced this pull request Oct 10, 2023
cccs-rc pushed a commit to CybercentreCanada/superset that referenced this pull request Mar 6, 2024
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 3.1.0 labels Mar 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels risk:breaking-change Issues or PRs that will introduce breaking changes size/L 🚢 3.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants