mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-29 04:55:31 +00:00
ipn/local: log OS-specific diagnostic information as JSON (#11700)
There is an undocumented 16KiB limit for text log messages. However, the limit for JSON messages is 256KiB. Even worse, logging JSON as text results in significant overhead since each double quote needs to be escaped. Instead, use logger.Logf.JSON to explicitly log the info as JSON. We also modify osdiag to return the information as structured data rather than implicitly have the package log on our behalf. This gives more control to the caller on how to log. Updates #7802 Signed-off-by: Joe Tsai <joetsai@digital-static.net>
This commit is contained in:
parent
06502b9048
commit
63b3c82587
@ -131,7 +131,7 @@ func isWindowsService() bool {
|
|||||||
// Windows started.
|
// Windows started.
|
||||||
func runWindowsService(pol *logpolicy.Policy) error {
|
func runWindowsService(pol *logpolicy.Policy) error {
|
||||||
go func() {
|
go func() {
|
||||||
osdiag.LogSupportInfo(logger.WithPrefix(log.Printf, "Support Info: "), osdiag.LogSupportInfoReasonStartup)
|
logger.Logf(log.Printf).JSON(1, "SupportInfo", osdiag.SupportInfo(osdiag.LogSupportInfoReasonStartup))
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if logSCMInteractions, _ := syspolicy.GetBoolean(syspolicy.LogSCMInteractions, false); logSCMInteractions {
|
if logSCMInteractions, _ := syspolicy.GetBoolean(syspolicy.LogSCMInteractions, false); logSCMInteractions {
|
||||||
|
@ -380,7 +380,7 @@ func (h *Handler) serveBugReport(w http.ResponseWriter, r *http.Request) {
|
|||||||
envknob.LogCurrent(logger.WithPrefix(h.logf, "user bugreport: "))
|
envknob.LogCurrent(logger.WithPrefix(h.logf, "user bugreport: "))
|
||||||
|
|
||||||
// OS-specific details
|
// OS-specific details
|
||||||
osdiag.LogSupportInfo(logger.WithPrefix(h.logf, "user bugreport OS: "), osdiag.LogSupportInfoReasonBugReport)
|
h.logf.JSON(1, "UserBugReportOS", osdiag.SupportInfo(osdiag.LogSupportInfoReasonBugReport))
|
||||||
|
|
||||||
if defBool(r.URL.Query().Get("diagnose"), false) {
|
if defBool(r.URL.Query().Get("diagnose"), false) {
|
||||||
h.b.Doctor(r.Context(), logger.WithPrefix(h.logf, "diag: "))
|
h.b.Doctor(r.Context(), logger.WithPrefix(h.logf, "diag: "))
|
||||||
|
@ -4,8 +4,6 @@
|
|||||||
// Package osdiag provides loggers for OS-specific diagnostic information.
|
// Package osdiag provides loggers for OS-specific diagnostic information.
|
||||||
package osdiag
|
package osdiag
|
||||||
|
|
||||||
import "tailscale.com/types/logger"
|
|
||||||
|
|
||||||
// LogSupportInfoReason is an enumeration indicating the reason for logging
|
// LogSupportInfoReason is an enumeration indicating the reason for logging
|
||||||
// support info.
|
// support info.
|
||||||
type LogSupportInfoReason int
|
type LogSupportInfoReason int
|
||||||
@ -15,9 +13,8 @@
|
|||||||
LogSupportInfoReasonBugReport // a bugreport is in the process of being gathered.
|
LogSupportInfoReasonBugReport // a bugreport is in the process of being gathered.
|
||||||
)
|
)
|
||||||
|
|
||||||
// LogSupportInfo obtains OS-specific diagnostic information useful for
|
// SupportInfo obtains OS-specific diagnostic information for troubleshooting
|
||||||
// troubleshooting and support, and writes it to logf. The reason argument is
|
// and support. The reason governs the verbosity of the output.
|
||||||
// useful for governing the verbosity of this function's output.
|
func SupportInfo(reason LogSupportInfoReason) map[string]any {
|
||||||
func LogSupportInfo(logf logger.Logf, reason LogSupportInfoReason) {
|
return supportInfo(reason)
|
||||||
logSupportInfo(logf, reason)
|
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
|
|
||||||
package osdiag
|
package osdiag
|
||||||
|
|
||||||
import "tailscale.com/types/logger"
|
func supportInfo(LogSupportInfoReason) map[string]any {
|
||||||
|
return nil
|
||||||
func logSupportInfo(logger.Logf, LogSupportInfoReason) {
|
|
||||||
}
|
}
|
||||||
|
@ -5,10 +5,8 @@
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"encoding/json"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"unicode/utf16"
|
"unicode/utf16"
|
||||||
@ -18,7 +16,6 @@
|
|||||||
"github.com/dblohm7/wingoes/pe"
|
"github.com/dblohm7/wingoes/pe"
|
||||||
"golang.org/x/sys/windows"
|
"golang.org/x/sys/windows"
|
||||||
"golang.org/x/sys/windows/registry"
|
"golang.org/x/sys/windows/registry"
|
||||||
"tailscale.com/types/logger"
|
|
||||||
"tailscale.com/util/osdiag/internal/wsc"
|
"tailscale.com/util/osdiag/internal/wsc"
|
||||||
"tailscale.com/util/winutil"
|
"tailscale.com/util/winutil"
|
||||||
"tailscale.com/util/winutil/authenticode"
|
"tailscale.com/util/winutil/authenticode"
|
||||||
@ -34,15 +31,6 @@
|
|||||||
initialValueBufLen = 80 // large enough to contain a stringified GUID encoded as UTF-16
|
initialValueBufLen = 80 // large enough to contain a stringified GUID encoded as UTF-16
|
||||||
)
|
)
|
||||||
|
|
||||||
func logSupportInfo(logf logger.Logf, reason LogSupportInfoReason) {
|
|
||||||
var b strings.Builder
|
|
||||||
if err := getSupportInfo(&b, reason); err != nil {
|
|
||||||
logf("error encoding support info: %v", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
logf("%s", b.String())
|
|
||||||
}
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
supportInfoKeyModules = "modules"
|
supportInfoKeyModules = "modules"
|
||||||
supportInfoKeyPageFile = "pageFile"
|
supportInfoKeyPageFile = "pageFile"
|
||||||
@ -51,7 +39,7 @@ func logSupportInfo(logf logger.Logf, reason LogSupportInfoReason) {
|
|||||||
supportInfoKeyWinsockLSP = "winsockLSP"
|
supportInfoKeyWinsockLSP = "winsockLSP"
|
||||||
)
|
)
|
||||||
|
|
||||||
func getSupportInfo(w io.Writer, reason LogSupportInfoReason) error {
|
func supportInfo(reason LogSupportInfoReason) map[string]any {
|
||||||
output := make(map[string]any)
|
output := make(map[string]any)
|
||||||
|
|
||||||
regInfo, err := getRegistrySupportInfo(registry.LOCAL_MACHINE, []string{winutil.RegPolicyBase, winutil.RegBase})
|
regInfo, err := getRegistrySupportInfo(registry.LOCAL_MACHINE, []string{winutil.RegPolicyBase, winutil.RegBase})
|
||||||
@ -86,8 +74,7 @@ func getSupportInfo(w io.Writer, reason LogSupportInfoReason) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enc := json.NewEncoder(w)
|
return output
|
||||||
return enc.Encode(output)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type getRegistrySupportInfoBufs struct {
|
type getRegistrySupportInfoBufs struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user