From 8a10bb52e0e7a7aa9ccc19406f98046aa11fb467 Mon Sep 17 00:00:00 2001 From: mpl Date: Thu, 19 Nov 2015 16:49:46 +0100 Subject: [PATCH] pkg/server/status: link to GCL logs on GCE Fixes issue #592 Change-Id: Ife405816ee42902258c93eac917a6ff5bada4138 --- pkg/server/status.go | 4 ++-- pkg/serverinit/serverinit.go | 43 +++++++++++++++++++++++++----------- 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/pkg/server/status.go b/pkg/server/status.go index 978089c2b..206ab2801 100644 --- a/pkg/server/status.go +++ b/pkg/server/status.go @@ -237,8 +237,8 @@ func (sh *StatusHandler) serveStatusHTML(rw http.ResponseWriter, req *http.Reque f("

Logs

") diff --git a/pkg/serverinit/serverinit.go b/pkg/serverinit/serverinit.go index 6c1379b4d..f63e770ad 100644 --- a/pkg/serverinit/serverinit.go +++ b/pkg/serverinit/serverinit.go @@ -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,18 +699,33 @@ func (profileHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) { } func logsHandler(w http.ResponseWriter, r *http.Request) { - c := &http.Client{ - Transport: &http.Transport{ - Dial: func(network, addr string) (net.Conn, error) { - return net.Dial("unix", "/run/camjournald.sock") + 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) { + return net.Dial("unix", "/run/camjournald.sock") + }, }, - }, + } + res, err := c.Get("http://journal/entries") + if err != nil { + http.Error(w, err.Error(), 500) + return + } + w.Header().Set("Content-Type", "text/plain; charset=utf-8") + io.Copy(w, res.Body) + default: + http.Error(w, "no such logs", 404) } - res, err := c.Get("http://journal/entries") - if err != nil { - http.Error(w, err.Error(), 500) - return - } - w.Header().Set("Content-Type", "text/plain; charset=utf-8") - io.Copy(w, res.Body) }