log: use logtail to log and upload sockstat logs

Switch to using logtail for logging sockstat logs. Always log locally
(on supported platforms), but disable automatic uploading.  Change
existing c2n sockstats request to trigger upload to log server and
return log ID.

Signed-off-by: Will Norris <will@tailscale.com>
This commit is contained in:
Will Norris
2023-03-22 13:51:29 -07:00
committed by Will Norris
parent 731688e5cc
commit f13b8bf0cf
3 changed files with 64 additions and 34 deletions

View File

@@ -84,8 +84,13 @@ func (b *LocalBackend) handleC2N(w http.ResponseWriter, r *http.Request) {
}
writeJSON(res)
case "/sockstats":
if r.Method != "POST" {
http.Error(w, "bad method", http.StatusMethodNotAllowed)
return
}
w.Header().Set("Content-Type", "text/plain")
b.sockstatLogger.WriteLogs(w)
b.sockstatLogger.Flush()
fmt.Fprintln(w, b.sockstatLogger.LogID())
default:
http.Error(w, "unknown c2n path", http.StatusBadRequest)
}

View File

@@ -310,7 +310,7 @@ func NewLocalBackend(logf logger.Logf, logid string, store ipn.StateStore, diale
// for now, only log sockstats on unstable builds
if version.IsUnstableBuild() {
b.sockstatLogger, err = sockstatlog.NewLogger(logpolicy.LogsDir(logf), logf)
b.sockstatLogger, err = sockstatlog.NewLogger(logpolicy.LogsDir(logf), logf, logid)
if err != nil {
log.Printf("error setting up sockstat logger: %v", err)
}