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

fix: use nullpool in the celery workers #10819

Merged
merged 2 commits into from
Sep 10, 2020

Conversation

bkyryliuk
Copy link
Member

@bkyryliuk bkyryliuk commented Sep 9, 2020

SUMMARY

Changes celery db requests from superset.db to the scoped_session that uses null pool to avoid using same db sessions across multiple celery workers.
More context on the problem can be found in the linked issue.

Fixes #10530

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TEST PLAN

  • unit tests
  • dropbox staging

ADDITIONAL INFORMATION

@villebro
Copy link
Member

villebro commented Sep 9, 2020

Was this confirmed to fix the error? There have been similar errors reported for email alerts, so pretty awesome if this solves these problems completely.

@bkyryliuk bkyryliuk force-pushed the bogdan/nullpool_celery branch 2 times, most recently from e27d728 to c60cdf4 Compare September 9, 2020 19:11
@bkyryliuk
Copy link
Member Author

Was this confirmed to fix the error? There have been similar errors reported for email alerts, so pretty awesome if this solves these problems completely.

@villebro still iterating on it, will post an update once confirmed

@codecov-commenter
Copy link

codecov-commenter commented Sep 9, 2020

Codecov Report

Merging #10819 into master will decrease coverage by 4.04%.
The diff coverage is 71.28%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #10819      +/-   ##
==========================================
- Coverage   65.40%   61.35%   -4.05%     
==========================================
  Files         802      804       +2     
  Lines       37872    37936      +64     
  Branches     3561     3561              
==========================================
- Hits        24770    23277    -1493     
- Misses      12996    14473    +1477     
- Partials      106      186      +80     
Flag Coverage Δ
#cypress ?
#javascript 61.58% <ø> (-0.07%) ⬇️
#python 61.22% <71.28%> (+0.31%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
superset/cli.py 40.00% <33.33%> (+0.06%) ⬆️
superset/tasks/schedules.py 76.87% <62.29%> (+1.12%) ⬆️
superset/utils/celery.py 85.71% <85.71%> (ø)
superset/sql_lab.py 80.28% <100.00%> (+1.59%) ⬆️
superset/tasks/alerts/observer.py 100.00% <100.00%> (ø)
superset-frontend/src/SqlLab/App.jsx 0.00% <0.00%> (-100.00%) ⬇️
superset-frontend/src/explore/App.jsx 0.00% <0.00%> (-100.00%) ⬇️
superset-frontend/src/dashboard/App.jsx 0.00% <0.00%> (-100.00%) ⬇️
superset-frontend/src/explore/index.jsx 0.00% <0.00%> (-100.00%) ⬇️
superset-frontend/src/dashboard/index.jsx 0.00% <0.00%> (-100.00%) ⬇️
... and 201 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3b4a992...1036e9c. Read the comment docs.

@bkyryliuk bkyryliuk force-pushed the bogdan/nullpool_celery branch 2 times, most recently from dd30315 to a9be817 Compare September 10, 2020 03:16
@bkyryliuk
Copy link
Member Author

Was this confirmed to fix the error? There have been similar errors reported for email alerts, so pretty awesome if this solves these problems completely.

@villebro I've confirmed that this fix is working for us, I've ran alerts and reports over night with high frequency & the issue has stopped happening

@bkyryliuk bkyryliuk changed the title fix: use nullpool in the celery workers [WIP] fix: use nullpool in the celery workers Sep 10, 2020
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 with a few small nits/suggestions.

superset/cli.py Outdated
Comment on lines 623 to 630
with session_scope(nullpool=True) as session:
schedule_window(
ScheduleType.alert,
datetime.now() - timedelta(1000),
datetime.now(),
6000,
session,
)
Copy link
Member

Choose a reason for hiding this comment

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

Not yours, but I usually like using named arguments in cases like this to make stuff more readable. 6000 what?

from superset.models.alerts import Alert, SQLObservation
from superset.sql_parse import ParsedQuery

logger = logging.getLogger("tasks.email_reports")


def observe(alert_id: int) -> Optional[str]:
def observe(alert_id: int, session: Session) -> Optional[str]:
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 the idea was to mostly remove references to sessions in sigs (there's lots of them scattered around), as they can usually just be picked up from db, so it might be a good idea to add a comment here that this really needs to be passed along here.

Copy link
Member Author

Choose a reason for hiding this comment

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

good point, added comments and issue reference

@bkyryliuk bkyryliuk merged commit ac2937a into apache:master Sep 10, 2020
@bkyryliuk bkyryliuk deleted the bogdan/nullpool_celery branch September 10, 2020 20:30
auxten pushed a commit to auxten/incubator-superset that referenced this pull request Nov 20, 2020
* Use nullpool in the celery workers

* Address comments

Co-authored-by: bogdan kyryliuk <[email protected]>
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.38.0 labels Mar 12, 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 size/L 🚢 0.38.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

celery SQLAlchemy errors in celery tasks that use sqlalchemy pools
5 participants