-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #97 from gadget-inc/various_fixes
Various fixes
- Loading branch information
Showing
10 changed files
with
79 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ import ( | |
"net" | ||
"os" | ||
"os/signal" | ||
"runtime" | ||
"runtime/pprof" | ||
"syscall" | ||
|
||
|
@@ -34,15 +35,16 @@ func NewServerCommand() *cobra.Command { | |
) | ||
|
||
var ( | ||
level *zapcore.Level | ||
encoding string | ||
tracing bool | ||
profilePath string | ||
port int | ||
dbUri string | ||
certFile string | ||
keyFile string | ||
pasetoFile string | ||
level *zapcore.Level | ||
encoding string | ||
tracing bool | ||
profilePath string | ||
memProfilePath string | ||
port int | ||
dbUri string | ||
certFile string | ||
keyFile string | ||
pasetoFile string | ||
) | ||
|
||
cmd := &cobra.Command{ | ||
|
@@ -128,6 +130,21 @@ func NewServerCommand() *cobra.Command { | |
signal.Notify(osSignals, os.Interrupt, syscall.SIGTERM) | ||
go func() { | ||
<-osSignals | ||
|
||
if memProfilePath != "" { | ||
memProfile, err := os.Create(memProfilePath) | ||
if err != nil { | ||
logger.Error(ctx, "cannot create heap profile file", zap.Error(err), zap.String("path", memProfilePath)) | ||
} | ||
defer memProfile.Close() | ||
runtime.GC() | ||
|
||
err = pprof.WriteHeapProfile(memProfile) | ||
if err != nil { | ||
logger.Error(ctx, "cannot write heap profile", zap.Error(err), zap.String("path", memProfilePath)) | ||
} | ||
} | ||
|
||
s.Grpc.GracefulStop() | ||
}() | ||
|
||
|
@@ -153,7 +170,8 @@ func NewServerCommand() *cobra.Command { | |
flags.AddGoFlag(flag.CommandLine.Lookup("log-level")) | ||
flags.StringVar(&encoding, "log-encoding", "console", "Log encoding (console | json)") | ||
flags.BoolVar(&tracing, "tracing", false, "Whether tracing is enabled") | ||
flags.StringVar(&profilePath, "profile", "", "CPU profile output path (profiling enabled if set)") | ||
flags.StringVar(&profilePath, "profile", "", "CPU profile output path (CPU profiling enabled if set)") | ||
flags.StringVar(&memProfilePath, "memprofile", "", "Memory profile output path") | ||
|
||
flags.IntVar(&port, "port", 5051, "GRPC server port") | ||
flags.StringVar(&dbUri, "dburi", "postgres://[email protected]:5432/dl", "Postgres URI") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters