From ec87e219ae8828f74448c74a7026016a8b037a19 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Mon, 1 Apr 2024 18:27:01 -0700 Subject: [PATCH] logtail: delete unused code from old way to configure zstd Updates #cleanup Change-Id: I666ecf08ea67e461adf2a3f4daa9d1753b2dc1e4 Signed-off-by: Brad Fitzpatrick --- cmd/tsconnect/wasm/wasm_js.go | 7 +++++-- logtail/logtail.go | 27 +++------------------------ 2 files changed, 8 insertions(+), 26 deletions(-) diff --git a/cmd/tsconnect/wasm/wasm_js.go b/cmd/tsconnect/wasm/wasm_js.go index 5c826d1a3..055cb6f39 100644 --- a/cmd/tsconnect/wasm/wasm_js.go +++ b/cmd/tsconnect/wasm/wasm_js.go @@ -90,8 +90,11 @@ func newIPN(jsConfig js.Value) map[string]any { c := logtail.Config{ Collection: lpc.Collection, PrivateID: lpc.PrivateID, - // NewZstdEncoder is intentionally not passed in, compressed requests - // set HTTP headers that are not supported by the no-cors fetching mode. + + // Compressed requests set HTTP headers that are not supported by the + // no-cors fetching mode: + CompressLogs: false, + HTTPC: &http.Client{Transport: &noCORSTransport{http.DefaultTransport}}, } logtail := logtail.NewLogger(c, log.Printf) diff --git a/logtail/logtail.go b/logtail/logtail.go index ecc3a1c91..191950402 100644 --- a/logtail/logtail.go +++ b/logtail/logtail.go @@ -47,11 +47,6 @@ const ( CollectionNode = "tailnode.log.tailscale.io" ) -type Encoder interface { - EncodeAll(src, dst []byte) []byte - Close() error -} - type Config struct { Collection string // collection name, a domain name PrivateID logid.PrivateID // private ID for the primary log stream @@ -66,9 +61,6 @@ type Config struct { Buffer Buffer // temp storage, if nil a MemoryBuffer CompressLogs bool // whether to compress the log uploads - // Deprecated: Use CompressUploads instead. - NewZstdEncoder func() Encoder // if set, used to compress logs for transmission - // MetricsDelta, if non-nil, is a func that returns an encoding // delta in clientmetrics to upload alongside existing logs. // It can return either an empty string (for nothing) or a string @@ -162,9 +154,6 @@ func NewLogger(cfg Config, logf tslogger.Logf) *Logger { } l.SetSockstatsLabel(sockstats.LabelLogtailLogger) l.compressLogs = cfg.CompressLogs - if cfg.NewZstdEncoder != nil { - l.zstdEncoder = cfg.NewZstdEncoder() - } ctx, cancel := context.WithCancel(context.Background()) l.uploadCancel = cancel @@ -192,7 +181,6 @@ type Logger struct { sentinel chan int32 clock tstime.Clock compressLogs bool - zstdEncoder Encoder uploadCancel func() explainedRaw bool metricsDelta func() string // or nil @@ -273,9 +261,6 @@ func (l *Logger) Shutdown(ctx context.Context) error { io.WriteString(l, "logger closing down\n") <-done - if l.zstdEncoder != nil { - return l.zstdEncoder.Close() - } return nil } @@ -379,15 +364,9 @@ func (l *Logger) uploading(ctx context.Context) { body := l.drainPending() origlen := -1 // sentinel value: uncompressed // Don't attempt to compress tiny bodies; not worth the CPU cycles. - if (l.compressLogs || l.zstdEncoder != nil) && len(body) > 256 { - var zbody []byte - switch { - case l.zstdEncoder != nil: - zbody = l.zstdEncoder.EncodeAll(body, nil) - default: - zbody = zstdframe.AppendEncode(nil, body, - zstdframe.FastestCompression, zstdframe.LowMemory(true)) - } + if l.compressLogs && len(body) > 256 { + zbody := zstdframe.AppendEncode(nil, body, + zstdframe.FastestCompression, zstdframe.LowMemory(true)) // Only send it compressed if the bandwidth savings are sufficient. // Just the extra headers associated with enabling compression