You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by "tvalentyn (via GitHub)" <gi...@apache.org> on 2023/05/18 03:43:56 UTC

[GitHub] [beam] tvalentyn opened a new pull request, #26753: Don't fail if creating venv didn't succeed. Also provide a way to disable creating a venv.

tvalentyn opened a new pull request, #26753:
URL: https://github.com/apache/beam/pull/26753

   https://github.com/apache/beam/pull/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.
   
   Additionally, this PR provides an option to disable venv creation, which may benefit users who wish to re-use a precreated virtual environment on their image. 
   
   ------------------------
   
   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](https://www.apache.org/licenses/icla.pdf).
   
   See the [Contributor Guide](https://beam.apache.org/contribute) for more tips on [how to make review process smoother](https://beam.apache.org/contribute/get-started-contributing/#make-the-reviewers-job-easier).
   
   To check the build health, please visit [https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md](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](https://github.com/apache/beam/workflows/Build%20python%20source%20distribution%20and%20wheels/badge.svg?branch=master&event=schedule)](https://github.com/apache/beam/actions?query=workflow%3A%22Build+python+source+distribution+and+wheels%22+branch%3Amaster+event%3Aschedule)
   [![Python tests](https://github.com/apache/beam/workflows/Python%20tests/badge.svg?branch=master&event=schedule)](https://github.com/apache/beam/actions?query=workflow%3A%22Python+Tests%22+branch%3Amaster+event%3Aschedule)
   [![Java tests](https://github.com/apache/beam/workflows/Java%20Tests/badge.svg?branch=master&event=schedule)](https://github.com/apache/beam/actions?query=workflow%3A%22Java+Tests%22+branch%3Amaster+event%3Aschedule)
   [![Go tests](https://github.com/apache/beam/workflows/Go%20tests/badge.svg?branch=master&event=schedule)](https://github.com/apache/beam/actions?query=workflow%3A%22Go+tests%22+branch%3Amaster+event%3Aschedule)
   
   See [CI.md](https://github.com/apache/beam/blob/master/CI.md) for more information about GitHub Actions CI.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] liferoad commented on pull request #26753: Don't fail if creating a venv didn't succeed. Also provide a way to disable creating separate venvs.

Posted by "liferoad (via GitHub)" <gi...@apache.org>.
liferoad commented on PR #26753:
URL: https://github.com/apache/beam/pull/26753#issuecomment-1552380627

   R: @lostluck
   For Go.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] liferoad commented on a diff in pull request #26753: Don't fail if creating a venv didn't succeed. Also provide a way to disable creating separate venvs.

Posted by "liferoad (via GitHub)" <gi...@apache.org>.
liferoad commented on code in PR #26753:
URL: https://github.com/apache/beam/pull/26753#discussion_r1197344472


##########
sdks/python/container/boot.go:
##########
@@ -157,15 +156,20 @@ func launchSDKProcess() error {
 	signalChannel := make(chan os.Signal, 1)
 	signal.Notify(signalChannel, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM)
 
-	venvDir, err := setupVenv(ctx, logger, "/opt/apache/beam-venv", *id)
-	if err != nil {
-		return errors.New("failed to initialize Python venv")
-	}
-	cleanupFunc := func() {
-		os.RemoveAll(venvDir)
-		logger.Printf(ctx, "Cleaned up temporary venv for worker %v.", *id)
+	// Create a separate virtual envirionment (with access to globally installed packages), unless disabled by the user.
+	// This improves usability on runners that persit the execution environment for the boot entrypoint between multiple pipeline executions.
+	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())

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



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] tvalentyn commented on pull request #26753: Don't fail if creating a venv didn't succeed. Also provide a way to disable creating separate venvs.

Posted by "tvalentyn (via GitHub)" <gi...@apache.org>.
tvalentyn commented on PR #26753:
URL: https://github.com/apache/beam/pull/26753#issuecomment-1553721410

   cc: @phoerious FYI.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] codecov[bot] commented on pull request #26753: Don't fail if creating a venv didn't succeed. Also provide a way to disable creating separate venvs.

Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #26753:
URL: https://github.com/apache/beam/pull/26753#issuecomment-1552368696

   ## [Codecov](https://app.codecov.io/gh/apache/beam/pull/26753?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   > :exclamation: No coverage uploaded for pull request base (`master@e1396db`). [Click here to learn what that means](https://docs.codecov.io/docs/error-reference?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#section-missing-base-commit).
   > The diff coverage is `n/a`.
   
   ```diff
   @@            Coverage Diff            @@
   ##             master   #26753   +/-   ##
   =========================================
     Coverage          ?   72.04%           
   =========================================
     Files             ?      745           
     Lines             ?   101204           
     Branches          ?        0           
   =========================================
     Hits              ?    72917           
     Misses            ?    26828           
     Partials          ?     1459           
   ```
   
   | Flag | Coverage Δ | |
   |---|---|---|
   | python | `81.07% <ø> (?)` | |
   
   Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
   
   
   :mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] tvalentyn commented on pull request #26753: Don't fail if creating a venv didn't succeed. Also provide a way to disable creating separate venvs.

Posted by "tvalentyn (via GitHub)" <gi...@apache.org>.
tvalentyn commented on PR #26753:
URL: https://github.com/apache/beam/pull/26753#issuecomment-1552370963

   cc: @riteshghorse 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] lostluck commented on a diff in pull request #26753: Don't fail if creating a venv didn't succeed. Also provide a way to disable creating separate venvs.

Posted by "lostluck (via GitHub)" <gi...@apache.org>.
lostluck commented on code in PR #26753:
URL: https://github.com/apache/beam/pull/26753#discussion_r1198049182


##########
sdks/python/container/boot.go:
##########
@@ -157,15 +156,20 @@ func launchSDKProcess() error {
 	signalChannel := make(chan os.Signal, 1)
 	signal.Notify(signalChannel, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM)
 
-	venvDir, err := setupVenv(ctx, logger, "/opt/apache/beam-venv", *id)
-	if err != nil {
-		return errors.New("failed to initialize Python venv")
-	}
-	cleanupFunc := func() {
-		os.RemoveAll(venvDir)
-		logger.Printf(ctx, "Cleaned up temporary venv for worker %v.", *id)
+	// Create a separate virtual envirionment (with access to globally installed packages), unless disabled by the user.
+	// This improves usability on runners that persit the execution environment for the boot entrypoint between multiple pipeline executions.
+	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())

Review Comment:
   ```suggestion
   			logger.Printf(ctx, "Using default environment, since creating a virtual environment for the SDK harness didn't succeed: %v", err)
   ```



##########
sdks/python/container/boot.go:
##########
@@ -308,9 +312,8 @@ func StartCommandEnv(env map[string]string, prog string, args ...string) *exec.C
 
 // setupVenv initializes a local Python venv and sets the corresponding env variables
 func setupVenv(ctx context.Context, logger *tools.Logger, baseDir, workerId string) (string, error) {
-	logger.Printf(ctx, "Initializing temporary Python venv ...")
-
 	dir := filepath.Join(baseDir, "beam-venv-worker-"+workerId)
+	logger.Printf(ctx, "Initializing temporary Python venv in "+dir)

Review Comment:
   ```suggestion
   	logger.Printf(ctx, "Initializing temporary Python venv in %v", dir)
   ```



##########
sdks/python/container/boot.go:
##########
@@ -157,15 +156,20 @@ func launchSDKProcess() error {
 	signalChannel := make(chan os.Signal, 1)
 	signal.Notify(signalChannel, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM)
 
-	venvDir, err := setupVenv(ctx, logger, "/opt/apache/beam-venv", *id)
-	if err != nil {
-		return errors.New("failed to initialize Python venv")
-	}
-	cleanupFunc := func() {
-		os.RemoveAll(venvDir)
-		logger.Printf(ctx, "Cleaned up temporary venv for worker %v.", *id)
+	// Create a separate virtual envirionment (with access to globally installed packages), unless disabled by the user.
+	// This improves usability on runners that persit the execution environment for the boot entrypoint between multiple pipeline executions.
+	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())

Review Comment:
   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.



##########
sdks/python/container/boot.go:
##########
@@ -157,15 +156,20 @@ func launchSDKProcess() error {
 	signalChannel := make(chan os.Signal, 1)
 	signal.Notify(signalChannel, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM)
 
-	venvDir, err := setupVenv(ctx, logger, "/opt/apache/beam-venv", *id)
-	if err != nil {
-		return errors.New("failed to initialize Python venv")
-	}
-	cleanupFunc := func() {
-		os.RemoveAll(venvDir)
-		logger.Printf(ctx, "Cleaned up temporary venv for worker %v.", *id)
+	// Create a separate virtual envirionment (with access to globally installed packages), unless disabled by the user.
+	// This improves usability on runners that persit the execution environment for the boot entrypoint between multiple pipeline executions.

Review Comment:
   ```suggestion
   	// Create a separate virtual environment (with access to globally installed packages), unless disabled by the user.
   	// This improves usability on runners that persist the execution environment for the boot entrypoint between multiple pipeline executions.
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] github-actions[bot] commented on pull request #26753: Don't fail if creating a venv didn't succeed. Also provide a way to disable creating separate venvs.

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #26753:
URL: https://github.com/apache/beam/pull/26753#issuecomment-1552366745

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


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] tvalentyn commented on pull request #26753: Don't fail if creating a venv didn't succeed. Also provide a way to disable creating separate venvs.

Posted by "tvalentyn (via GitHub)" <gi...@apache.org>.
tvalentyn commented on PR #26753:
URL: https://github.com/apache/beam/pull/26753#issuecomment-1552366018

   r: @liferoad 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] tvalentyn commented on pull request #26753: Don't fail if creating a venv didn't succeed. Also provide a way to disable creating separate venvs.

Posted by "tvalentyn (via GitHub)" <gi...@apache.org>.
tvalentyn commented on PR #26753:
URL: https://github.com/apache/beam/pull/26753#issuecomment-1553807713

   Run PythonDocker PreCommit


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] tvalentyn commented on pull request #26753: Don't fail if creating a venv didn't succeed. Also provide a way to disable creating separate venvs.

Posted by "tvalentyn (via GitHub)" <gi...@apache.org>.
tvalentyn commented on PR #26753:
URL: https://github.com/apache/beam/pull/26753#issuecomment-1553808111

   Run Python_PVR_Flink PreCommit


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] tvalentyn commented on a diff in pull request #26753: Don't fail if creating a venv didn't succeed. Also provide a way to disable creating separate venvs.

Posted by "tvalentyn (via GitHub)" <gi...@apache.org>.
tvalentyn commented on code in PR #26753:
URL: https://github.com/apache/beam/pull/26753#discussion_r1198349126


##########
sdks/python/container/boot.go:
##########
@@ -157,15 +156,20 @@ func launchSDKProcess() error {
 	signalChannel := make(chan os.Signal, 1)
 	signal.Notify(signalChannel, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM)
 
-	venvDir, err := setupVenv(ctx, logger, "/opt/apache/beam-venv", *id)
-	if err != nil {
-		return errors.New("failed to initialize Python venv")
-	}
-	cleanupFunc := func() {
-		os.RemoveAll(venvDir)
-		logger.Printf(ctx, "Cleaned up temporary venv for worker %v.", *id)
+	// Create a separate virtual envirionment (with access to globally installed packages), unless disabled by the user.
+	// This improves usability on runners that persit the execution environment for the boot entrypoint between multiple pipeline executions.
+	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())

Review Comment:
   Given this error is not critical, Info level is appropriate.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] tvalentyn commented on pull request #26753: Don't fail if creating a venv didn't succeed. Also provide a way to disable creating separate venvs.

Posted by "tvalentyn (via GitHub)" <gi...@apache.org>.
tvalentyn commented on PR #26753:
URL: https://github.com/apache/beam/pull/26753#issuecomment-1553720393

   Thank you very much, all.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] tvalentyn merged pull request #26753: Don't fail if creating a venv didn't succeed. Also provide a way to disable creating separate venvs.

Posted by "tvalentyn (via GitHub)" <gi...@apache.org>.
tvalentyn merged PR #26753:
URL: https://github.com/apache/beam/pull/26753


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org