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

Don't fail if creating a venv didn't succeed. Also provide a way to disable creating separate venvs. #26753

Merged
merged 2 commits into from
May 19, 2023

Conversation

tvalentyn
Copy link
Contributor

@tvalentyn tvalentyn commented May 18, 2023

#16658 made a change to Python SDK harness container boot sequence to launch SDK processes in separately created virtual environments.

It appears that the venv dependency is sometimes not available on non-beam Python container images. Users who supply custom containers may run into errors when python3-venv is not installed, and need to install it separately, which is inconvenient.

Creating a venv is not strictly required, therefore we can fallback on prior behavior to use global environment.

Drive-by changes:

  • Log why creating a venv didn't succeed.
  • Provide an way to disable venv creation, which may benefit users who wish to re-use a precreated virtual environment on their image. To disable creating isolated venvs, users can add the following line to their Dockerfiles:
    ENV RUN_PYTHON_SDK_IN_DEFAULT_ENVIRONMENT=1

Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:

  • Mention the appropriate issue in your description (for example: addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment fixes #<ISSUE NUMBER> instead.
  • Update CHANGES.md with noteworthy changes.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

See the Contributor Guide for more tips on how to make review process smoother.

To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md

GitHub Actions Tests Status (on master branch)

Build python source distribution and wheels
Python tests
Java tests
Go tests

See CI.md for more information about GitHub Actions CI.

@tvalentyn tvalentyn changed the title Don't fail if creating venv didn't succeed. Also provide a way to disable creating a venv. Don't fail if creating a venv didn't succeed. Also provide a way to disable creating separate venvs. May 18, 2023
@tvalentyn
Copy link
Contributor Author

r: @liferoad

@github-actions
Copy link
Contributor

Stopping reviewer notifications for this pull request: review requested by someone other than the bot, ceding control

@codecov
Copy link

codecov bot commented May 18, 2023

Codecov Report

Merging #26753 (47a2d89) into master (e1396db) will decrease coverage by 0.08%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##           master   #26753      +/-   ##
==========================================
- Coverage   72.05%   71.97%   -0.08%     
==========================================
  Files         745      747       +2     
  Lines      101204   101306     +102     
==========================================
- Hits        72921    72916       -5     
- Misses      26824    26931     +107     
  Partials     1459     1459              
Flag Coverage Δ
python 80.95% <ø> (-0.13%) ⬇️

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

see 8 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@tvalentyn
Copy link
Contributor Author

cc: @riteshghorse

if os.Getenv("RUN_PYTHON_SDK_IN_DEFAULT_ENVIRONMENT") == "" {
venvDir, err := setupVenv(ctx, logger, "/opt/apache/beam-venv", *id)
if err != nil {
logger.Printf(ctx, "Using default environment, since creating a virtual environment for the SDK harness didn't succeed: "+err.Error())
Copy link
Collaborator

Choose a reason for hiding this comment

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

If my Go knowledge is correct, this will be still logged as INFO?

Copy link
Contributor

Choose a reason for hiding this comment

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

As implemented, that's correct. The logger is just a lightweight wrapper to actually send it through the logging service instead of it hopefully getting picked up via STDOut + Err (with those being a fallback). Info logs currently, since it doesn't seem valuable to differentiate at this time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Given this error is not critical, Info level is appropriate.

@liferoad
Copy link
Collaborator

R: @lostluck
For Go.

Copy link
Contributor

@lostluck lostluck left a comment

Choose a reason for hiding this comment

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

Fixed up some typos, and corrected some uses of concatenating in a Printf call...

sdks/python/container/boot.go Outdated Show resolved Hide resolved
sdks/python/container/boot.go Outdated Show resolved Hide resolved
sdks/python/container/boot.go Outdated Show resolved Hide resolved
if os.Getenv("RUN_PYTHON_SDK_IN_DEFAULT_ENVIRONMENT") == "" {
venvDir, err := setupVenv(ctx, logger, "/opt/apache/beam-venv", *id)
if err != nil {
logger.Printf(ctx, "Using default environment, since creating a virtual environment for the SDK harness didn't succeed: "+err.Error())
Copy link
Contributor

Choose a reason for hiding this comment

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

As implemented, that's correct. The logger is just a lightweight wrapper to actually send it through the logging service instead of it hopefully getting picked up via STDOut + Err (with those being a fallback). Info logs currently, since it doesn't seem valuable to differentiate at this time.

Co-authored-by: Robert Burke <lostluck@users.noreply.github.com>
@tvalentyn
Copy link
Contributor Author

Thank you very much, all.

@tvalentyn
Copy link
Contributor Author

cc: @phoerious FYI.

@tvalentyn
Copy link
Contributor Author

Run PythonDocker PreCommit

@tvalentyn
Copy link
Contributor Author

Run Python_PVR_Flink PreCommit

@tvalentyn tvalentyn merged commit f2400c8 into apache:master May 19, 2023
@tvalentyn tvalentyn deleted the venv_fp branch May 19, 2023 00:18
cushon pushed a commit to cushon/beam that referenced this pull request May 24, 2024
…isable creating separate venvs. (apache#26753)

Co-authored-by: Robert Burke <lostluck@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants