Skip to content

Commit

Permalink
Add http_info_endpoint to enable and disable info endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-heinzmann-logmein committed Sep 15, 2022
1 parent 7cd3eba commit 538cf94
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
8 changes: 6 additions & 2 deletions cmd/mtail/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ 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.")
httpDebugEndpoints = flag.Bool("http_debugging_endpoint", true, "Enable debugging endpoints (/debug/*).")
httpInfoEndpoints = flag.Bool("http_info_endpoint", true, "Enable info endpoints (/progz,/varz).")

// Tracing.
jaegerEndpoint = flag.String("jaeger_endpoint", "", "If set, collector endpoint URL of jaeger thrift service")
Expand Down Expand Up @@ -209,7 +210,10 @@ func main() {
opts = append(opts, mtail.DumpBytecode)
}
if *httpDebugEndpoints {
opts = append(opts, mtail.HttpDebugEndpoints)
opts = append(opts, mtail.HTTPDebugEndpoints)
}
if *httpInfoEndpoints {
opts = append(opts, mtail.HTTPInfoEndpoints)
}
if *syslogUseCurrentYear {
opts = append(opts, mtail.SyslogUseCurrentYear)
Expand Down
11 changes: 7 additions & 4 deletions internal/mtail/mtail.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type Server struct {
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
httpInfoEndpoints bool // if set, mtail will enable info endpoints for progz and varz
}

// initRuntime constructs a new runtime and performs the initial load of program files in the program directory.
Expand Down Expand Up @@ -98,20 +99,22 @@ func (m *Server) initHTTPServer() error {

mux := http.NewServeMux()
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)
}
if m.httpInfoEndpoints {
mux.Handle("/", m)
mux.HandleFunc("/favicon.ico", FaviconHandler)
mux.HandleFunc("/varz", http.HandlerFunc(m.e.HandleVarz))
mux.Handle("/progz", http.HandlerFunc(m.r.ProgzHandler))
}
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("/progz", http.HandlerFunc(m.r.ProgzHandler))
zpages.Handle(mux, "/")

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

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

// HttpInfoEndpoints enables info http endpoints
var HTTPInfoEndpoints = &niladicOption{
func(m *Server) error {
m.httpInfoEndpoints = 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 538cf94

Please sign in to comment.