Skip to content

Commit

Permalink
fix service name
Browse files Browse the repository at this point in the history
  • Loading branch information
felixge committed Dec 11, 2023
1 parent 885eaa1 commit 836bbaf
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 20 deletions.
6 changes: 4 additions & 2 deletions internal/apps/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type Config struct {
DisableExecutionTracing bool
}

func (c Config) RunHTTP(handler http.Handler) {
func (c Config) RunHTTP(handler func() http.Handler) {
// Parse common test app flags
var (
httpF = flag.String("http", "localhost:8080", "HTTP addr to listen on.")
Expand Down Expand Up @@ -70,7 +70,9 @@ func (c Config) RunHTTP(handler http.Handler) {
}
defer l.Close()
log.Printf("Listening on: http://%s", *httpF)
server := http.Server{Handler: handler}
// handler is a func, because if we create a traced handler before starting
// the tracer, the service name will default to http.router.
server := http.Server{Handler: handler()}
go server.Serve(l)

// Wait until SIGINT is received, then shut down
Expand Down
25 changes: 13 additions & 12 deletions internal/apps/memory-leak/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,21 @@ func init() {
}

func main() {
// Setup http routes
mux := httptrace.NewServeMux()
// Endpoint and handler names are chosen so we don't give away what they do.
// The profiling product should make it easy to figure out what the problem
// is.
mux.HandleFunc("/lorem", LoremHandler) // Don't leak anything
mux.HandleFunc("/ipsum", IpsumHandler) // Leak a goroutine stack via a goroutine.
mux.HandleFunc("/dolor", DolorHandler) // Leak a heap pointer via a global variable.
mux.HandleFunc("/sit", SitHandler) // Leak a goroutine stack and a heap pointer via a goroutine.
// TODO: file leak, cgo heap leak, cgo thread leak, etc.

// Start app
app := apps.Config{}
app.RunHTTP(mux)
app.RunHTTP(func() http.Handler {
// Setup http routes
mux := httptrace.NewServeMux()
// Endpoint and handler names are chosen so we don't give away what they
// do. The profiling product should make it easy to figure out what the
// problem is.
mux.HandleFunc("/lorem", LoremHandler) // Don't leak anything
mux.HandleFunc("/ipsum", IpsumHandler) // Leak a goroutine stack via a goroutine.
mux.HandleFunc("/dolor", DolorHandler) // Leak a heap pointer via a global variable.
mux.HandleFunc("/sit", SitHandler) // Leak a goroutine stack and a heap pointer via a goroutine.
// TODO: file leak, cgo heap leak, cgo thread leak, etc.
return mux
})
}

func LoremHandler(w http.ResponseWriter, _ *http.Request) {
Expand Down
13 changes: 7 additions & 6 deletions internal/apps/unit-of-work/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ func main() {
// Enable unit of work
os.Setenv("DD_PROFILING_ENDPOINT_COUNT_ENABLED", "true")

// Setup http routes
mux := httptrace.NewServeMux()
mux.HandleFunc("/foo", FooHandler)
mux.HandleFunc("/bar", BarHandler)

// Start app
app := apps.Config{}
app.RunHTTP(mux)
app.RunHTTP(func() http.Handler {
// Setup http routes
mux := httptrace.NewServeMux()
mux.HandleFunc("/foo", FooHandler)
mux.HandleFunc("/bar", BarHandler)
return mux
})
}

// FooHandler does twice the amount of cpu work per request as BarHandler.
Expand Down

0 comments on commit 836bbaf

Please sign in to comment.