Skip to content

Commit

Permalink
revert signal handling
Browse files Browse the repository at this point in the history
  • Loading branch information
rosstimothy committed Jul 29, 2024
1 parent 6ff15cc commit dede267
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 98 deletions.
92 changes: 0 additions & 92 deletions integrations/event-handler/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ package main

import (
"context"
"os"
"path/filepath"
"runtime"
"runtime/pprof"
runtimetrace "runtime/trace"
"strconv"
"time"

"github.com/gravitational/trace"
Expand Down Expand Up @@ -253,89 +247,3 @@ func (a *App) RegisterSession(ctx context.Context, e *TeleportEvent) {
log.Error("Registering session: ", err)
}
}

// Profile captures various Go pprof profiles and writes
// them under the configured storage directory.
func (a *App) Profile() {
dir := filepath.Join(a.Config.StorageDir, "profiles")
if err := os.MkdirAll(dir, storageDirPerms); err != nil {
logrus.WithError(err).Warnf("Failed creating profile directory %v : %v", dir, err)
}

timestamp := strconv.FormatInt(time.Now().UnixMilli(), 10)
traceFile, err := os.Create(filepath.Join(dir, timestamp+"-trace.profile"))
if err != nil {
logrus.WithError(err).Warn("failed to create trace profile file")
return
}
defer traceFile.Close()

cpuFile, err := os.Create(filepath.Join(dir, timestamp+"-cpu.profile"))
if err != nil {
logrus.WithError(err).Warn("failed to create cpu profile file")
return
}
defer cpuFile.Close()

heapFile, err := os.Create(filepath.Join(dir, timestamp+"-heap.profile"))
if err != nil {
logrus.WithError(err).Warn("failed to create heap profile file")
return
}
defer heapFile.Close()

goroutineFile, err := os.Create(filepath.Join(dir, timestamp+"-goroutine.profile"))
if err != nil {
logrus.WithError(err).Warn("failed to create goroutine profile file")
return
}
defer goroutineFile.Close()

blockFile, err := os.Create(filepath.Join(dir, timestamp+"-block.profile"))
if err != nil {
logrus.WithError(err).Warn("failed to create block profile file")
return
}
defer blockFile.Close()

logrus.Debugf("capturing trace profile to %s", traceFile.Name())

if err := runtimetrace.Start(traceFile); err != nil {
logrus.WithError(err).Warn("failed to capture trace profile")
return
}

logrus.Debugf("capturing cpu profile to %s", cpuFile.Name())

if err := pprof.StartCPUProfile(cpuFile); err != nil {
logrus.WithError(err).Warn("failed to capture cpu profile")
return
}

defer func() {
logrus.Debugf("capturing goroutine profile to %s", cpuFile.Name())

if err := pprof.Lookup("goroutine").WriteTo(goroutineFile, 0); err != nil {
logrus.WithError(err).Warn("failed to capture goroutine profile")
}

logrus.Debugf("capturing block profile to %s", cpuFile.Name())

if err := pprof.Lookup("block").WriteTo(blockFile, 0); err != nil {
logrus.WithError(err).Warn("failed to capture block profile")
}

runtime.GC()

logrus.Debugf("capturing heap profile to %s", cpuFile.Name())

if err := pprof.WriteHeapProfile(heapFile); err != nil {
logrus.WithError(err).Warn("failed to capture heap profile")
}

pprof.StopCPUProfile()
runtimetrace.Stop()
}()

<-time.After(30 * time.Second)
}
6 changes: 0 additions & 6 deletions integrations/lib/signals.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ func ServeSignals(app Terminable, shutdownTimeout time.Duration) {
signal.Notify(sigC,
syscall.SIGTERM, // graceful shutdown
syscall.SIGINT, // graceful-then-fast shutdown
syscall.SIGUSR1,
)
defer signal.Stop(sigC)

Expand All @@ -68,10 +67,5 @@ func ServeSignals(app Terminable, shutdownTimeout time.Duration) {
}
go gracefulShutdown()
alreadyInterrupted = true
case syscall.SIGUSR1:
if p, ok := app.(interface{ Profile() }); ok {
go p.Profile()
}
}
}
}

0 comments on commit dede267

Please sign in to comment.