Skip to content
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

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
19 changes: 18 additions & 1 deletion cmd/service/metro/metro.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import (
configreader "github.com/razorpay/metro/pkg/config"
"github.com/razorpay/metro/pkg/encryption"
"github.com/razorpay/metro/pkg/logger"

"net/http"
_ "net/http/pprof"
Copy link

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)

)

const (
Expand All @@ -38,7 +41,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 {
Expand Down Expand Up @@ -68,6 +71,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)
}
Expand Down Expand Up @@ -114,3 +119,15 @@ func Run(ctx context.Context) {

logger.Ctx(ctx).Infow("stopped metro")
}

// sets up pprof profile for perfomance monitoring
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
perfomance is a misspelling of performance (misspell)

func setPprofProfiles(ctx context.Context, componentName string) {
logger.Ctx(ctx).Infow("initialising pprof profiles")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
initialising is a misspelling of initializing (misspell)

go func() {
if componentName == Web {
http.ListenAndServe("metro-web-pprof.concierge.stage.razorpay.in:8080", nil)
Copy link

Choose a reason for hiding this comment

The 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.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The profiling 'pprof' endpoint is automatically exposed on /debug/pprof. This could leak information about the server. Instead, use import "net/http/pprof". See https://www.farsightsecurity.com/blog/txt-record/go-remote-profiling-20161028/ for more information and mitigation.

🔴 Fix or ignore this finding to merge your pull request.
🙈 From go.lang.security.audit.net.pprof.pprof-debug-exposure.

} else if componentName == Worker {
http.ListenAndServe("metro-worker-pprof.concierge.stage.razorpay.in:8080", nil)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The profiling 'pprof' endpoint is automatically exposed on /debug/pprof. This could leak information about the server. Instead, use import "net/http/pprof". See https://www.farsightsecurity.com/blog/txt-record/go-remote-profiling-20161028/ for more information and mitigation.

🔴 Fix or ignore this finding to merge your pull request.
🙈 From go.lang.security.audit.net.pprof.pprof-debug-exposure.

Copy link

Choose a reason for hiding this comment

The 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.

}
}()
}