feat: Ignore agent pprof port in listening ports (#6515)

* feat: Ignore agent pprof port in listening ports
This commit is contained in:
Steven Masley
2023-03-09 10:53:00 -06:00
committed by GitHub
parent 3de29307b5
commit 2abae42cec
5 changed files with 126 additions and 5 deletions
+13 -5
View File
@@ -11,7 +11,7 @@ import (
"github.com/coder/coder/codersdk"
)
func (*agent) apiHandler() http.Handler {
func (a *agent) apiHandler() http.Handler {
r := chi.NewRouter()
r.Get("/", func(rw http.ResponseWriter, r *http.Request) {
httpapi.Write(r.Context(), rw, http.StatusOK, codersdk.Response{
@@ -19,16 +19,24 @@ func (*agent) apiHandler() http.Handler {
})
})
lp := &listeningPortsHandler{}
// Make a copy to ensure the map is not modified after the handler is
// created.
cpy := make(map[int]string)
for k, b := range a.ignorePorts {
cpy[k] = b
}
lp := &listeningPortsHandler{ignorePorts: cpy}
r.Get("/api/v0/listening-ports", lp.handler)
return r
}
type listeningPortsHandler struct {
mut sync.Mutex
ports []codersdk.WorkspaceAgentListeningPort
mtime time.Time
mut sync.Mutex
ports []codersdk.WorkspaceAgentListeningPort
mtime time.Time
ignorePorts map[int]string
}
// handler returns a list of listening ports. This is tested by coderd's