-
Notifications
You must be signed in to change notification settings - Fork 328
Lazily enable zpages at runtime #774
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,16 +31,31 @@ | |
package zpages // import "go.opencensus.io/zpages" | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"sync" | ||
|
||
"go.opencensus.io/internal" | ||
) | ||
|
||
// Handler is an http.Handler that serves the zpages. | ||
// Handler is deprecated: Use NewHandler. | ||
var Handler http.Handler | ||
|
||
var enableOnce sync.Once | ||
|
||
func init() { | ||
Handler = NewHandler("") | ||
} | ||
|
||
// NewHandler returns a handler that serves the z-pages. | ||
func NewHandler(prefix string) http.Handler { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We shouldn't have the prefix here. It is coupling the responsibilities of a mux and a handler into a handler. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I this this is preferable to using StripPrefix. It is much more readable, does not allocate a new request object, and does not try to fake the URL (like StripPrefix does). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rakyll If this were changed to http.ServerMux I think that would work for what I referenced in #783. The http.Handler strips the |
||
enableOnce.Do(func() { | ||
internal.LocalSpanStoreEnabled = true | ||
registerRPCViews() | ||
}) | ||
zpagesMux := http.NewServeMux() | ||
zpagesMux.HandleFunc("/rpcz", rpczHandler) | ||
zpagesMux.HandleFunc("/tracez", tracezHandler) | ||
zpagesMux.Handle("/public/", http.FileServer(fs)) | ||
Handler = zpagesMux | ||
zpagesMux.HandleFunc(fmt.Sprintf("%s/rpcz", prefix), rpczHandler) | ||
zpagesMux.HandleFunc(fmt.Sprintf("%s/tracez", prefix), tracezHandler) | ||
zpagesMux.Handle(fmt.Sprintf("%s/public/", prefix), http.FileServer(fs)) | ||
return zpagesMux | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the line.