Skip to content

Commit

Permalink
Make Treatment Service max goroutines configurable and add profiling …
Browse files Browse the repository at this point in the history
…handler (#15)

* Add profiler to Treatment Service handler

* Make max goroutines configurable

Co-authored-by: Krithika Sundararajan <krithika.sundararajan@go-jek.com>
  • Loading branch information
krithika369 and Krithika Sundararajan authored Jul 6, 2022
1 parent 158271c commit 95d5624
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions treatment-service/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ type SwaggerConfig struct {
// DeploymentConfig captures the config related to the deployment of Treatment Service
type DeploymentConfig struct {
EnvironmentType string `default:"local"`
MaxGoRoutines int `default:"100"`
}

type MetricSinkKind = string
Expand Down
3 changes: 2 additions & 1 deletion treatment-service/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func TestDefaultConfigs(t *testing.T) {
},
DeploymentConfig: DeploymentConfig{
EnvironmentType: "local",
MaxGoRoutines: 100,
},
AssignedTreatmentLogger: AssignedTreatmentLoggerConfig{
Kind: "",
Expand Down Expand Up @@ -80,7 +81,7 @@ func TestLoadMultipleConfigs(t *testing.T) {
URL: "localhost:3000/v1",
AuthorizationEnabled: true,
},
DeploymentConfig: DeploymentConfig{EnvironmentType: "dev"},
DeploymentConfig: DeploymentConfig{EnvironmentType: "dev", MaxGoRoutines: 200},
AssignedTreatmentLogger: AssignedTreatmentLoggerConfig{
Kind: "bq",
QueueLength: 1073741824,
Expand Down
9 changes: 6 additions & 3 deletions treatment-service/controller/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package controller

import (
"net/http"
_ "net/http/pprof"

"github.com/heptiolabs/healthcheck"

Expand All @@ -17,11 +18,13 @@ type InternalController struct {

func NewInternalController(ctx *appcontext.AppContext, cfg *config.Config) *InternalController {
healthCheckHandler := healthcheck.NewHandler()
healthCheckHandler.AddLivenessCheck("goroutine-threshold", healthcheck.GoroutineCountCheck(100))
healthCheckHandler.AddLivenessCheck("goroutine-threshold", healthcheck.GoroutineCountCheck(cfg.DeploymentConfig.MaxGoRoutines))

mux := http.NewServeMux()
mux.Handle("/health/", http.StripPrefix("/health", healthCheckHandler))
mux.Handle("/debug", NewDebugHandler(ctx, cfg))
mux.Handle("/debug/dump", NewCacheDumpHandler(ctx, cfg))
// For profiling. net/http/pprof will register itself to http.DefaultServeMux.
mux.Handle("/debug/pprof/", http.DefaultServeMux)
return &InternalController{Handler: mux, AppContext: ctx, Config: cfg}
}

Expand All @@ -30,7 +33,7 @@ type debugHandler struct {
Config *config.Config
}

func NewDebugHandler(ctx *appcontext.AppContext, cfg *config.Config) http.Handler {
func NewCacheDumpHandler(ctx *appcontext.AppContext, cfg *config.Config) http.Handler {
return &debugHandler{AppContext: ctx, Config: cfg}
}

Expand Down
1 change: 1 addition & 0 deletions treatment-service/testdata/config2.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
DeploymentConfig:
EnvironmentType: dev
MaxGoRoutines: 200

SentryConfig:
Enabled: true
Expand Down

0 comments on commit 95d5624

Please sign in to comment.