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

refactor(Dashboard): Fetch dashboard screenshot via dedicated endpoint #29272

Merged
merged 14 commits into from
Jul 18, 2024

Conversation

geido
Copy link
Member

@geido geido commented Jun 17, 2024

SUMMARY

A dashboard can have an image attached in the markdown component that is hosted on a server that does not have proper CORS settings. Due to limitations of html2canvas, both PDF and image download will fail.

For reference from html2canvas:

All the images that the script uses need to reside under the same origin for it to be able to read them without the assistance of a proxy. Similarly, if you have other canvas elements on the page, which have been tainted with cross-origin content, they will become dirty and no longer readable by html2canvas.

This PR introduces the necessary frontend changes to defer the generation of the screenshot to a newly built endpoint. See #29187

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TESTING INSTRUCTIONS

  1. Select a Dashboard and a specific tab
  2. Download the dashboard as an image or PDF via the dedicated menu items
  3. Wait for the download to complete
  4. The screenshot should be of the chosen type and depict the target tab

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

@geido geido requested a review from fisjac June 20, 2024 15:00
@geido geido marked this pull request as ready for review June 25, 2024 16:28
@dosubot dosubot bot added change:frontend Requires changing the frontend dashboard:export Related to exporting dashboards labels Jun 25, 2024
@john-bodley john-bodley requested a review from justinpark June 25, 2024 17:32
@geido geido requested review from kgabryje, rusackas and eschutho June 27, 2024 11:38
@kgabryje
Copy link
Member

/testenv up

Copy link
Contributor

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

@kgabryje
Copy link
Member

kgabryje commented Jun 27, 2024

I couldn't get it to work on ephemeral env (both image and pdf)

EDIT: Sorry, I didn't notice that the endpoint PR is not merged yet.

@geido
Copy link
Member Author

geido commented Jul 8, 2024

/testenv up

Copy link
Contributor

github-actions bot commented Jul 8, 2024

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

@geido
Copy link
Member Author

geido commented Jul 8, 2024

/testenv up

Copy link
Contributor

github-actions bot commented Jul 8, 2024

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

Copy link
Member

@kgabryje kgabryje left a comment

Choose a reason for hiding this comment

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

LGTM

@geido geido merged commit 1e412a8 into master Jul 18, 2024
34 checks passed
Copy link
Contributor

Ephemeral environment shutdown and build artifacts deleted.

@lwandrebeck
Copy link

lwandrebeck commented Sep 9, 2024

Hi there.
Hitting #29719 too, I’ve updated to 4.1.0rc2. When exporting as PDF, I now get
image
(dis)appearing several times, but I never get the PDF output.

Python 3.11.7 venv on Rocky Linux 9.4 x86_64, backend is PostgreSQL 16.4 through pgbouncer 1.23.1 (coming from PGDG repo) using pool_mode=session.
I do lack logs, the only thing I have is:

Sep 09 07:53:28 superset gunicorn[2297879]:     df = self.database.get_df(
Sep 09 07:53:28 superset gunicorn[2297879]:          ^^^^^^^^^^^^^^^^^^^^^
Sep 09 07:53:28 superset gunicorn[2297879]:   File "/home/ZZZ/superset_3.11/lib64/python3.11/site-packages/superset/models/core.py", line 677, in get_df
Sep 09 07:53:28 superset gunicorn[2297879]:     self.db_engine_spec.execute(cursor, sql_, self)
Sep 09 07:53:28 superset gunicorn[2297879]:   File "/home/ZZZ/superset_3.11/lib64/python3.11/site-packages/superset/db_engine_specs/base.py", line 1835, in execute
Sep 09 07:53:28 superset gunicorn[2297879]:     raise cls.get_dbapi_mapped_exception(ex) from ex
Sep 09 07:53:28 superset gunicorn[2297879]:   File "/home/ZZZ/superset_3.11/lib64/python3.11/site-packages/superset/db_engine_specs/base.py", line 1831, in execute
Sep 09 07:53:28 superset gunicorn[2297879]:     cursor.execute(query)
Sep 09 07:53:28 superset gunicorn[2297879]: psycopg2.errors.DivisionByZero: division by zero
Sep 09 07:55:44 superset gunicorn[2297879]: 2024-09-09 07:55:44,224:INFO:superset.dashboards.api:Triggering screenshot ASYNC

Trying to dig deeper and have proper logs. If anyone has a clue, I can give it a try.
Thanks !
EDIT: div by zero error is very likely due to a SQL query ran from the dashboard, so it’s not the good path. Have found nothing about export or pdf in logs, still digging (btw had to roll back to 4.0.2 as cross-filtering looked broken and it’s heavily used so I won’t be able to debug 4.1.0rc2 pdf export much further)

@lwandrebeck
Copy link

Sep 09 06:18:35 superset gunicorn[2297879]: 2024-09-09 06:18:35,167:ERROR:superset.utils.json:JSON is not valid Expecting value: line 1 column 1 (char 0)
Sep 09 06:18:35 superset gunicorn[2297879]: Traceback (most recent call last):
Sep 09 06:18:35 superset gunicorn[2297879]:   File "/home/ZZZ/superset_3.11/lib64/python3.11/site-packages/superset/utils/json.py", line 244, in loads
Sep 09 06:18:35 superset gunicorn[2297879]:     return simplejson.loads(
Sep 09 06:18:35 superset gunicorn[2297879]:            ^^^^^^^^^^^^^^^^^
Sep 09 06:18:35 superset gunicorn[2297879]:   File "/home/ZZZ/superset_3.11/lib64/python3.11/site-packages/simplejson/__init__.py", line 514, in loads
Sep 09 06:18:35 superset gunicorn[2297879]:     return _default_decoder.decode(s)
Sep 09 06:18:35 superset gunicorn[2297879]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^
Sep 09 06:18:35 superset gunicorn[2297879]:   File "/home/ZZZ/superset_3.11/lib64/python3.11/site-packages/simplejson/decoder.py", line 386, in decode
Sep 09 06:18:35 superset gunicorn[2297879]:     obj, end = self.raw_decode(s)
Sep 09 06:18:35 superset gunicorn[2297879]:                ^^^^^^^^^^^^^^^^^^
Sep 09 06:18:35 superset gunicorn[2297879]:   File "/home/ZZZ/superset_3.11/lib64/python3.11/site-packages/simplejson/decoder.py", line 416, in raw_decode
Sep 09 06:18:35 superset gunicorn[2297879]:     return self.scan_once(s, idx=_w(s, idx).end())
Sep 09 06:18:35 superset gunicorn[2297879]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This may be the culprit of PDF export failure but can’t be sure about that.

Hope that helps anyway.
Thanks

@rusackas rusackas deleted the geido/refactor/dashboard-screenshot branch September 27, 2024 20:55
@github-actions github-actions bot added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 4.1.0 labels Nov 14, 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 change:frontend Requires changing the frontend dashboard:export Related to exporting dashboards dependencies:npm size/XL 🚢 4.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants