-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
servenv: Move away from using default HTTP muxer
Up until now we've been using the implicit default HTTP mux. The problem of using this mux is that it works implicitly also for profiling endpoints. So the moment that `net/http/pprof` is imported, those endpoints get added. We want to be able to make enabling the profiling endpoints optional, but there's no way to do that with the default mux except by recompiling and removing the import. By moving everything away from the default mux to an explicit mux for the servenv, we can make this configurable in the near future. It still gets added to the default mux, but we don't use that anymore so it doesn't get exposed. The changes here now explicitly add the profiling endpoints so that we can make that optional in a follow up. Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
- Loading branch information
Showing
35 changed files
with
125 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package servenv | ||
|
||
import ( | ||
"errors" | ||
"net" | ||
"net/http" | ||
"net/http/httptest" | ||
"net/http/pprof" | ||
) | ||
|
||
var mux = http.NewServeMux() | ||
|
||
func HTTPHandle(pattern string, handler http.Handler) { | ||
mux.Handle(pattern, handler) | ||
} | ||
|
||
func HTTPHandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request)) { | ||
mux.HandleFunc(pattern, handler) | ||
} | ||
|
||
func HTTPServe(l net.Listener) error { | ||
err := http.Serve(l, mux) | ||
if errors.Is(err, http.ErrServerClosed) || errors.Is(err, net.ErrClosed) { | ||
return nil | ||
} | ||
return err | ||
} | ||
|
||
func HTTPTestServer() *httptest.Server { | ||
return httptest.NewServer(mux) | ||
} | ||
|
||
func HTTPRegisterProfile() { | ||
HTTPHandleFunc("/debug/pprof/", pprof.Index) | ||
HTTPHandleFunc("/debug/pprof/cmdline", pprof.Cmdline) | ||
HTTPHandleFunc("/debug/pprof/profile", pprof.Profile) | ||
HTTPHandleFunc("/debug/pprof/symbol", pprof.Symbol) | ||
HTTPHandleFunc("/debug/pprof/trace", pprof.Trace) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.