Skip to content

Commit a14d009

Browse files
authored
Improve logging in boot.go to facilitate future triaging (#38342)
1 parent 802331b commit a14d009

1 file changed

Lines changed: 19 additions & 11 deletions

File tree

sdks/python/container/boot.go

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,14 @@ func launchSDKProcess() error {
185185
}
186186

187187
experiments := getExperiments(options)
188+
logger.Printf(ctx, "Experiments=%v", experiments)
189+
188190
pipNoBuildIsolation = false
189191
if slices.Contains(experiments, "pip_no_build_isolation") {
190192
pipNoBuildIsolation = true
191-
logger.Printf(ctx, "Disabled build isolation when installing packages with pip")
193+
logger.Printf(ctx, "Build isolation disabled when installing packages with pip")
194+
} else {
195+
logger.Printf(ctx, "Build isolation enabled when installing packages with pip")
192196
}
193197

194198
// (2) Retrieve and install the staged packages.
@@ -403,10 +407,14 @@ func setupVenv(ctx context.Context, logger *tools.Logger, baseDir, workerId stri
403407
return dir, nil
404408
}
405409

406-
// installSetupPackages installs Beam SDK and user dependencies.
410+
// installSetupPackages installs user dependencies.
407411
func installSetupPackages(ctx context.Context, logger *tools.Logger, files []string, workDir string, requirementsFiles []string) error {
408412
bufLogger := tools.NewBufferedLogger(logger)
409-
bufLogger.Printf(ctx, "Installing setup packages ...")
413+
bufLogger.Printf(ctx, "Installing user dependencies ...")
414+
415+
if err := logRuntimeDependencies(ctx, bufLogger, "initial runtime environment"); err != nil {
416+
bufLogger.Printf(ctx, "Failed to fetch the runtime python dependencies: %v", err)
417+
}
410418

411419
// Install the Dataflow Python SDK if one was staged. In released
412420
// container images, SDK is already installed, but can be overriden
@@ -432,11 +440,11 @@ func installSetupPackages(ctx context.Context, logger *tools.Logger, files []str
432440
if err := pipInstallPackage(ctx, logger, files, workDir, workflowFile, false, true, nil); err != nil {
433441
return fmt.Errorf("failed to install workflow: %v", err)
434442
}
435-
if err := logRuntimeDependencies(ctx, bufLogger); err != nil {
436-
bufLogger.Printf(ctx, "couldn't fetch the runtime python dependencies: %v", err)
443+
if err := logRuntimeDependencies(ctx, bufLogger, "final runtime environment"); err != nil {
444+
bufLogger.Printf(ctx, "Failed to fetch the runtime python dependencies: %v", err)
437445
}
438446
if err := logSubmissionEnvDependencies(ctx, bufLogger, workDir); err != nil {
439-
bufLogger.Printf(ctx, "couldn't fetch the submission environment dependencies: %v", err)
447+
bufLogger.Printf(ctx, "Failed to fetch the submission environment dependencies: %v", err)
440448
}
441449

442450
return nil
@@ -485,20 +493,20 @@ func processArtifactsInSetupOnlyMode() {
485493

486494
// logRuntimeDependencies logs the python dependencies
487495
// installed in the runtime environment.
488-
func logRuntimeDependencies(ctx context.Context, bufLogger *tools.BufferedLogger) error {
496+
func logRuntimeDependencies(ctx context.Context, bufLogger *tools.BufferedLogger, phase string) error {
489497
pythonVersion, err := expansionx.GetPythonVersion()
490498
if err != nil {
491499
return err
492500
}
493-
bufLogger.Printf(ctx, "Using Python version:")
501+
bufLogger.Printf(ctx, "Python version in %s:", phase)
494502
args := []string{"--version"}
495503
if err := execx.ExecuteEnvWithIO(nil, os.Stdin, bufLogger, bufLogger, pythonVersion, args...); err != nil {
496504
bufLogger.FlushAtError(ctx)
497505
} else {
498506
bufLogger.FlushAtDebug(ctx)
499507
}
500-
bufLogger.Printf(ctx, "Logging runtime dependencies:")
501-
args = []string{"-m", "pip", "freeze"}
508+
bufLogger.Printf(ctx, "Dependencies in %s:", phase)
509+
args = []string{"-m", "pip", "freeze", "--all"}
502510
if err := execx.ExecuteEnvWithIO(nil, os.Stdin, bufLogger, bufLogger, pythonVersion, args...); err != nil {
503511
bufLogger.FlushAtError(ctx)
504512
} else {
@@ -510,7 +518,7 @@ func logRuntimeDependencies(ctx context.Context, bufLogger *tools.BufferedLogger
510518
// logSubmissionEnvDependencies logs the python dependencies
511519
// installed in the submission environment.
512520
func logSubmissionEnvDependencies(ctx context.Context, bufLogger *tools.BufferedLogger, dir string) error {
513-
bufLogger.Printf(ctx, "Logging submission environment dependencies:")
521+
bufLogger.Printf(ctx, "Dependencies in submission environment:")
514522
// path for submission environment dependencies should match with the
515523
// one defined in apache_beam/runners/portability/stager.py.
516524
filename := filepath.Join(dir, "submission_environment_dependencies.txt")

0 commit comments

Comments
 (0)