damccorm commented on code in PR #22225:
URL: https://github.com/apache/beam/pull/22225#discussion_r918443656


##########
sdks/go/pkg/beam/util/diagnostics/diagnostics.go:
##########
@@ -0,0 +1,68 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements.  See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License.  You may obtain a copy of the License at
+//
+//    http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package diagnostics
+
+import (
+       "bufio"
+       "context"
+       "os"
+
+       "runtime/debug"
+
+       "github.com/apache/beam/sdks/v2/go/pkg/beam/io/filesystem"
+       _ "github.com/apache/beam/sdks/v2/go/pkg/beam/io/filesystem/gcs"
+)
+
+func UploadHeapDump(ctx context.Context, dest string, additionalDataToWrite 
string) error {
+       heapDumpLoc := "heapDump"
+
+       f, err := os.Create(heapDumpLoc)
+       if err != nil {
+               return err
+       }
+       debug.WriteHeapDump(f.Fd())
+
+       heapDump, err := os.Open(heapDumpLoc)
+       if err != nil {
+               return err
+       }
+       defer heapDump.Close()
+       heapDumpReader := bufio.NewReader(heapDump)
+
+       fs, err := filesystem.New(ctx, dest)
+       if err != nil {
+               return err
+       }
+       defer fs.Close()
+       fd, err := fs.OpenWrite(ctx, dest)
+       if err != nil {
+               return err
+       }
+       buf := bufio.NewWriterSize(fd, 1<<20) // use 1MB buffer
+
+       buf.WriteString(additionalDataToWrite)

Review Comment:
   Whoops, forgot I still had that in there - that was for debugging when I was 
having a hard time getting the temp_directory to show up (I'd forgotten it was 
still masked in dataflow.go). I just removed it. I think this should also make 
actually getting the heap dump to show up easier.



##########
sdks/go/container/boot.go:
##########
@@ -115,7 +119,19 @@ func main() {
                os.Setenv("RUNNER_CAPABILITIES", 
strings.Join(info.GetRunnerCapabilities(), " "))
        }
 
-       log.Fatalf("User program exited: %v", execx.Execute(prog, args...))
+       err = execx.Execute(prog, args...)
+
+       if err != nil {
+               var opt runtime.RawOptionsWrapper
+               err = json.Unmarshal([]byte(options), &opt)
+               if err == nil {
+                       if tempLocation, ok := 
opt.Options.Options["temp_location"]; ok {
+                               diagnostics.UploadHeapDump(ctx, 
fmt.Sprintf("%v/heapDumps/dump-%v-%d", strings.TrimSuffix(tempLocation, "/"), 
*id, time.Now().Unix()), fmt.Sprintf("Options %v", opt))

Review Comment:
   I just removed this



-- 
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]

Reply via email to