Skip to content

Commit

Permalink
Disables rendering dead links
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-heinzmann-logmein committed Sep 15, 2022
1 parent 538cf94 commit 519a5a9
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 14 deletions.
42 changes: 32 additions & 10 deletions internal/mtail/httpstatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,21 @@ import (
)

const statusTemplate = `
<!DOCTYPE html>
<html>
<head>
<title>mtail on {{.BindAddress}}</title>
</head>
<body>
<h1>mtail on {{.BindAddress}}</h1>
<p>Build: {{.BuildInfo}}</p>
<p>Metrics: <a href="/json">json</a>, <a href="/graphite">graphite</a>, <a href="/metrics">prometheus</a>, <a href="/varz">varz</a></p>
<p>Debug: <a href="/debug/pprof">debug/pprof</a>, <a href="/debug/vars">debug/vars</a>, <a href="/tracez">tracez</a>, <a href="/progz">progz</a></p>
<p>Metrics: <a href="/json">json</a>, <a href="/graphite">graphite</a>, <a href="/metrics">prometheus</a></p>
<p>Info: {{ if .HTTPInfoEndpoints }}<a href="/varz">varz</a>, <a href="/progz">progz</a> <a href="/tracez">tracez</a></p>{{ else }} disabled {{ end }}</p>
<p>Debug: {{ if .HTTPDebugEndpoints }}<a href="/debug/pprof">debug/pprof</a>, <a href="/debug/vars">debug/vars</a>{{ else }} disabled {{ end }}</p>
`
const statusTemplateEnd = `
</body>
</html>
`

// ServeHTTP satisfies the http.Handler interface, and is used to serve the
Expand All @@ -31,25 +37,41 @@ func (m *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}

te, err := template.New("statusend").Parse(statusTemplateEnd)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

data := struct {
BindAddress string
BuildInfo string
BindAddress string
BuildInfo string
HTTPDebugEndpoints bool
HTTPInfoEndpoints bool
}{
m.listener.Addr().String(),
m.buildInfo.String(),
m.httpDebugEndpoints,
m.httpInfoEndpoints,
}
w.Header().Add("Content-type", "text/html")
w.WriteHeader(http.StatusOK)
if err = t.Execute(w, data); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
err = m.r.WriteStatusHTML(w)
if err != nil {
glog.Warningf("Error while writing loader status: %s", err)
if m.httpInfoEndpoints {
err = m.r.WriteStatusHTML(w)
if err != nil {
glog.Warningf("Error while writing loader status: %s", err)
}
err = m.t.WriteStatusHTML(w)
if err != nil {
glog.Warningf("Error while writing tailer status: %s", err)
}
}
err = m.t.WriteStatusHTML(w)
if err != nil {
glog.Warningf("Error while writing tailer status: %s", err)

if err = te.Execute(w, data); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/mtail/mtail.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ func (m *Server) initHTTPServer() error {
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("/", m)
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))
Expand Down
2 changes: 1 addition & 1 deletion internal/runtime/httpstatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

const loaderTemplate = `
<h2 id="loader">Program Loader</h2>
<table border=1>
<table border="1">
<tr>
<th>program name</th>
<th>errors</th>
Expand Down
3 changes: 1 addition & 2 deletions internal/tailer/httpstatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const tailerTemplate = `
{{end}}
</ul>
<h3>Log files watched</h3>
<table border=1>
<table border="1">
<tr>
<th>pathname</th>
<th>errors</th>
Expand All @@ -38,7 +38,6 @@ const tailerTemplate = `
</tr>
{{end}}
</table>
</ul>
`

// WriteStatusHTML emits the Tailer's state in HTML format to the io.Writer w.
Expand Down

0 comments on commit 519a5a9

Please sign in to comment.