pkg/server/status: link to GCL logs on GCE

Fixes issue #592

Change-Id: Ife405816ee42902258c93eac917a6ff5bada4138
This commit is contained in:
mpl 2015-11-19 16:49:46 +01:00
parent 64a8d7d26b
commit 8a10bb52e0
2 changed files with 32 additions and 15 deletions

View File

@ -237,8 +237,8 @@ func (sh *StatusHandler) serveStatusHTML(rw http.ResponseWriter, req *http.Reque
f("<h2>Logs</h2><ul>")
f(" <li><a href='/debug/config'>/debug/config</a> - server config</li>\n")
if env.OnGCE() {
f(" <li><a href='/debug/logs'>/debug/logs</a> - server logs</li>\n")
f(" <li><a href='/debug/logs?TODO'>/debug/logs?XXX</a> - camlistored logs</li>\n")
f(" <li><a href='/debug/logs/camlistored'>camlistored logs on Google Cloud Logging</a></li>\n")
f(" <li><a href='/debug/logs/system'>system logs from Google Compute Engine</a></li>\n")
}
f("</ul>")

View File

@ -46,6 +46,8 @@ import (
"camlistore.org/pkg/server"
"camlistore.org/pkg/server/app"
"camlistore.org/pkg/types/serverconfig"
"google.golang.org/cloud/compute/metadata"
)
const camliPrefix = "/camli/"
@ -597,7 +599,7 @@ func (config *Config) InstallHandlers(hi HandlerInstaller, baseURL string, reind
hi.Handle("/debug/pprof/", profileHandler{})
}
hi.Handle("/debug/config", auth.RequireAuth(configHandler{config}, auth.OpAll))
hi.Handle("/debug/logs", auth.RequireAuth(http.HandlerFunc(logsHandler), auth.OpAll))
hi.Handle("/debug/logs/", auth.RequireAuth(http.HandlerFunc(logsHandler), auth.OpAll))
return multiCloser(hl.closers), nil
}
@ -697,6 +699,18 @@ func (profileHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
}
func logsHandler(w http.ResponseWriter, r *http.Request) {
suffix := strings.TrimPrefix(r.URL.Path, "/debug/logs/")
switch suffix {
case "camlistored":
projID, err := metadata.ProjectID()
if err != nil {
httputil.ServeError(w, r, fmt.Errorf("Error getting project ID: %v", err))
return
}
http.Redirect(w, r,
"https://console.developers.google.com/logs?project="+projID+"&service=custom.googleapis.com&logName=camlistored-stderr",
http.StatusFound)
case "system":
c := &http.Client{
Transport: &http.Transport{
Dial: func(network, addr string) (net.Conn, error) {
@ -711,4 +725,7 @@ func logsHandler(w http.ResponseWriter, r *http.Request) {
}
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
io.Copy(w, res.Body)
default:
http.Error(w, "no such logs", 404)
}
}