cozos commented on code in PR #38246:
URL: https://github.com/apache/beam/pull/38246#discussion_r3114745360
##########
sdks/python/container/boot.go:
##########
@@ -314,23 +314,47 @@ func launchSDKProcess() error {
var wg sync.WaitGroup
wg.Add(len(workerIds))
- for _, workerId := range workerIds {
- go func(workerId string) {
- defer wg.Done()
-
- bufLogger := tools.NewBufferedLogger(logger)
- errorCount := 0
- for {
- childPids.mu.Lock()
- if childPids.canceled {
- childPids.mu.Unlock()
- return
- }
- logger.Printf(ctx, "Executing Python (worker
%v): python %v", workerId, strings.Join(args, " "))
- cmd :=
StartCommandEnv(map[string]string{"WORKER_ID": workerId}, os.Stdin, bufLogger,
bufLogger, "python", args...)
- childPids.v = append(childPids.v,
cmd.Process.Pid)
- childPids.mu.Unlock()
-
+for _, workerId := range workerIds {
+ go func(workerId string) {
+ defer wg.Done()
+
+ workerCtx := grpcx.WriteWorkerID(ctx, workerId)
+
+ // Create a separate logger per worker so that each worker initializes
+ // its own Fn logging stream with the correct worker_id metadata.
+ // Shared loggers would reuse the first stream and cause incorrect
+ // portability_worker_id attribution across workers.
+ workerLogger := &tools.Logger{
+ Endpoint: *loggingEndpoint,
+ }
+
+ bufLogger := tools.NewBufferedLogger(workerLogger)
Review Comment:
I think this won't work because we need to pass `workerCtx` to
`BufferedLogger`. `NewBufferedLogger` creates its own `periodicFlushContext:
context.Background()` which ignores `workerCtx`:
https://github.com/apache/beam/blob/25370f50b39f2703ee1a15780b76fa52464fc581/sdks/go/container/tools/buffered_logging.go#L45-L47
That's why I think we need to use `NewBufferedLoggerWithFlushInterval` which
accepts a `ctx` argument:
https://github.com/apache/beam/blob/25370f50b39f2703ee1a15780b76fa52464fc581/sdks/go/container/tools/buffered_logging.go#L51-L53
That `ctx` is then forwarded to the Fn logger here:
https://github.com/apache/beam/blob/25370f50b39f2703ee1a15780b76fa52464fc581/sdks/go/container/tools/buffered_logging.go#L69
TL:DR need to plumb `workerCtx` with something like:
```go
bufLogger := tools.NewBufferedLoggerWithFlushInterval(workerCtx,
workerLogger, 100*time.Millisecond)
```
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]