Skip to content
Open
2 changes: 1 addition & 1 deletion build/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ WORKDIR /app
RUN apk add --update --no-cache dumb-init su-exec ca-certificates curl
RUN mkdir -p /app/public

EXPOSE 8081 8082 8083 8084 3000
EXPOSE 8081 8082 8083 8084 3000 8080

RUN chmod +x entrypoint.sh probe.sh
ENTRYPOINT ["/app/entrypoint.sh", "metro"]
20 changes: 19 additions & 1 deletion cmd/service/metro/metro.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Copy link
Copy Markdown

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 @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -119,3 +126,14 @@ func Run(ctx context.Context) {

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

// sets up pprof profile for perfomance monitoring

Copy link
Copy Markdown

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
Copy Markdown

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() {
myMux := http.DefaultServeMux
if err := http.ListenAndServe("localhost:8080", myMux); err != nil {

Copy link
Copy Markdown

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.

logger.Ctx(ctx).Fatalw("Error when starting or running %v pprof http server: %v", componentName, err)
}
}()
}