-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added pprof profiling to monitor heap memory #318
base: master
Are you sure you want to change the base?
Changes from all commits
2732aff
890412a
ff61064
3cdd82f
0f10480
faecdaf
ec318d7
58bdf45
b3385f6
b7efb6a
9571cc1
9a7a49e
41dddd8
f510472
e1b36af
59a641b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,11 @@ import ( | |
configreader "github.com/razorpay/metro/pkg/config" | ||
"github.com/razorpay/metro/pkg/encryption" | ||
"github.com/razorpay/metro/pkg/logger" | ||
|
||
"net/http" | ||
|
||
// blank import added for testing. | ||
_ "net/http/pprof" | ||
) | ||
|
||
const ( | ||
|
@@ -39,7 +44,7 @@ func isValidComponent(component string) bool { | |
} | ||
|
||
// Init initializes all modules (logger, tracing, config, metro component) | ||
func Init(_ context.Context, env string, componentName string) { | ||
func Init(ctx context.Context, env string, componentName string) { | ||
// componentName validation | ||
ok := isValidComponent(componentName) | ||
if !ok { | ||
|
@@ -69,6 +74,8 @@ func Init(_ context.Context, env string, componentName string) { | |
|
||
err = boot.InitMonitoring(env, appConfig.App, appConfig.Sentry, appConfig.Tracing) | ||
|
||
setPprofProfiles(ctx, componentName) | ||
|
||
if err != nil { | ||
log.Fatalf("error in setting up monitoring : %v", err) | ||
} | ||
|
@@ -119,3 +126,14 @@ func Run(ctx context.Context) { | |
|
||
logger.Ctx(ctx).Infow("stopped metro") | ||
} | ||
|
||
// sets up pprof profile for perfomance monitoring | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [golangci] reported by reviewdog 🐶 |
||
func setPprofProfiles(ctx context.Context, componentName string) { | ||
logger.Ctx(ctx).Infow("initialising pprof profiles") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [golangci] reported by reviewdog 🐶 |
||
go func() { | ||
myMux := http.DefaultServeMux | ||
if err := http.ListenAndServe("localhost:8080", myMux); err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Found an HTTP server without TLS. Use 'http.ListenAndServeTLS' instead. See https://golang.org/pkg/net/http/#ListenAndServeTLS for more information. 🔴 Fix or ignore this finding to merge your pull request.🙈 From go.lang.security.audit.net.use-tls.use-tls. |
||
logger.Ctx(ctx).Fatalw("Error when starting or running %v pprof http server: %v", componentName, err) | ||
} | ||
}() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [golangci] reported by reviewdog 🐶
G108: Profiling endpoint is automatically exposed on /debug/pprof (gosec)