Skip to content

Commit

Permalink
Add http_debugging_endpoint flag to allow disabeling http debug endpo…
Browse files Browse the repository at this point in the history
…int (fixes #305)
  • Loading branch information
robert-heinzmann-logmein committed Sep 15, 2022
1 parent 4add76d commit 7cd3eba
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
4 changes: 4 additions & 0 deletions cmd/mtail/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ var (
// Debugging flags.
blockProfileRate = flag.Int("block_profile_rate", 0, "Nanoseconds of block time before goroutine blocking events reported. 0 turns off. See https://golang.org/pkg/runtime/#SetBlockProfileRate")
mutexProfileFraction = flag.Int("mutex_profile_fraction", 0, "Fraction of mutex contention events reported. 0 turns off. See http://golang.org/pkg/runtime/#SetMutexProfileFraction")
httpDebugEndpoints = flag.Bool("http_debugging_endpoint", true, "Enable debugging endpoints.")

// Tracing.
jaegerEndpoint = flag.String("jaeger_endpoint", "", "If set, collector endpoint URL of jaeger thrift service")
Expand Down Expand Up @@ -207,6 +208,9 @@ func main() {
if *dumpBytecode {
opts = append(opts, mtail.DumpBytecode)
}
if *httpDebugEndpoints {
opts = append(opts, mtail.HttpDebugEndpoints)
}
if *syslogUseCurrentYear {
opts = append(opts, mtail.SyslogUseCurrentYear)
}
Expand Down
29 changes: 16 additions & 13 deletions internal/mtail/mtail.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ type Server struct {

buildInfo BuildInfo // go build information

programPath string // path to programs to load
oneShot bool // if set, mtail reads log files from the beginning, once, then exits
compileOnly bool // if set, mtail compiles programs then exits
programPath string // path to programs to load
oneShot bool // if set, mtail reads log files from the beginning, once, then exits
compileOnly bool // if set, mtail compiles programs then exit
httpDebugEndpoints bool // if set, mtail will enable debug endpoints
}

// initRuntime constructs a new runtime and performs the initial load of program files in the program directory.
Expand Down Expand Up @@ -96,19 +97,21 @@ func (m *Server) initHTTPServer() error {
}

mux := http.NewServeMux()
mux.HandleFunc("/favicon.ico", FaviconHandler)
mux.Handle("/", m)
mux.Handle("/progz", http.HandlerFunc(m.r.ProgzHandler))
mux.HandleFunc("/json", http.HandlerFunc(m.e.HandleJSON))
if m.httpDebugEndpoints {
mux.HandleFunc("/favicon.ico", FaviconHandler)
mux.Handle("/", m)
mux.Handle("/debug/vars", expvar.Handler())
mux.HandleFunc("/debug/pprof/", pprof.Index)
mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
mux.HandleFunc("/debug/pprof/profile", pprof.Profile)
mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
mux.HandleFunc("/debug/pprof/trace", pprof.Trace)
}
mux.Handle("/metrics", promhttp.HandlerFor(m.reg, promhttp.HandlerOpts{}))
mux.HandleFunc("/json", http.HandlerFunc(m.e.HandleJSON))
mux.HandleFunc("/graphite", http.HandlerFunc(m.e.HandleGraphite))
mux.HandleFunc("/varz", http.HandlerFunc(m.e.HandleVarz))
mux.Handle("/debug/vars", expvar.Handler())
mux.HandleFunc("/debug/pprof/", pprof.Index)
mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
mux.HandleFunc("/debug/pprof/profile", pprof.Profile)
mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
mux.HandleFunc("/debug/pprof/trace", pprof.Trace)
mux.Handle("/progz", http.HandlerFunc(m.r.ProgzHandler))
zpages.Handle(mux, "/")

srv := &http.Server{
Expand Down
8 changes: 8 additions & 0 deletions internal/mtail/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,14 @@ var DumpBytecode = &niladicOption{
},
}

// Debug enables debug http endpoints
var HttpDebugEndpoints = &niladicOption{
func(m *Server) error {
m.httpDebugEndpoints = true
return nil
},
}

// SyslogUseCurrentYear instructs the Server to use the current year for year-less log timestamp during parsing.
var SyslogUseCurrentYear = &niladicOption{
func(m *Server) error {
Expand Down

0 comments on commit 7cd3eba

Please sign in to comment.