You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tailscale/cmd
Joe Tsai 7a77a2edf1
logtail: optimize JSON processing (#11671)
Changes made:

* Avoid "encoding/json" for JSON processing, and instead use
"github.com/go-json-experiment/json/jsontext".
Use jsontext.Value.IsValid for validation, which is much faster.
Use jsontext.AppendQuote instead of our own JSON escaping.

* In drainPending, use a different maxLen depending on lowMem.
In lowMem mode, it is better to perform multiple uploads
than it is to construct a large body that OOMs the process.

* In drainPending, if an error is encountered draining,
construct an error message in the logtail JSON format
rather than something that is invalid JSON.

* In appendTextOrJSONLocked, use jsontext.Decoder to check
whether the input is a valid JSON object. This is faster than
the previous approach of unmarshaling into map[string]any and
then re-marshaling that data structure.
This is especially beneficial for network flow logging,
which produces relatively large JSON objects.

* In appendTextOrJSONLocked, enforce maxSize on the input.
If too large, then we may end up in a situation where the logs
can never be uploaded because it exceeds the maximum body size
that the Tailscale logs service accepts.

* Use "tailscale.com/util/truncate" to properly truncate a string
on valid UTF-8 boundaries.

* In general, remove unnecessary spaces in JSON output.

Performance:

    name       old time/op    new time/op    delta
    WriteText     776ns ± 2%     596ns ± 1%   -23.24%  (p=0.000 n=10+10)
    WriteJSON     110µs ± 0%       9µs ± 0%   -91.77%  (p=0.000 n=8+8)

    name       old alloc/op   new alloc/op   delta
    WriteText      448B ± 0%        0B       -100.00%  (p=0.000 n=10+10)
    WriteJSON    37.9kB ± 0%     0.0kB ± 0%   -99.87%  (p=0.000 n=10+10)

    name       old allocs/op  new allocs/op  delta
    WriteText      1.00 ± 0%      0.00       -100.00%  (p=0.000 n=10+10)
    WriteJSON     1.08k ± 0%     0.00k ± 0%   -99.91%  (p=0.000 n=10+10)

For text payloads, this is 1.30x faster.
For JSON payloads, this is 12.2x faster.

Updates #cleanup
Updates tailscale/corp#18514

Signed-off-by: Joe Tsai <joetsai@digital-static.net>
2 months ago
..
addlicense all: update tools that manage copyright headers 1 year ago
build-webclient client/web: precompress assets 6 months ago
cloner cmd/cloner: fix typo in test type's name 8 months ago
connector-gen cmd/connector-gen: add helper tool for wide app connector configurations 6 months ago
containerboot cmd/{containerboot,k8s-operator/deploy/manifests}: optionally allow proxying cluster traffic to a cluster target via ingress proxy (#11036) 4 months ago
derper tsweb: switch to fastuuid for request ID generation 2 months ago
derpprobe cmd/{derper,derpprobe}: add --version flag 2 months ago
dist cmd/dist: update logs for synology builds 4 months ago
get-authkey util/cmpx: delete now that we're using Go 1.22 4 months ago
gitops-pusher cmd/gitops-pusher: only use OAuth creds if non-empty string 4 months ago
hello cmd/hello: link to the Hello KB article (#11022) 4 months ago
k8s-operator Revert "cmd/{k8s-nameserver,k8s-operator},k8s-operator: add a kube nameserver, make operator deploy it (#11017)" (#11669) 2 months ago
mkmanifest cmd/mkmanifest, cmd/tailscale, cmd/tailscaled: remove Windows arm32 resources from OSS 1 year ago
mkpkg go.mod: upgrade nfpm to v2 (#8786) 10 months ago
mkversion version/mkversion: open-source version generation logic 1 year ago
nardump all: update copyright and license headers 1 year ago
netlogfmt util/cmpx: remove code that's in the stdlib now 6 months ago
nginx-auth tailcfg,all: add and use Node.IsTagged() 1 year ago
pgproxy various: add golangci-lint, fix issues (#7905) 1 year ago
printdep cmd/printdep: print correct toolchain URL 1 year ago
proxy-to-grafana tailcfg,all: add and use Node.IsTagged() 1 year ago
sniproxy go.mod, all: move away from inet.af domain seized by Taliban 4 months ago
speedtest all: update copyright and license headers 1 year ago
ssh-auth-none-demo all: replace deprecated ioutil references 9 months ago
stunc all: update copyright and license headers 1 year ago
stund tsweb: switch to fastuuid for request ID generation 2 months ago
sync-containers all: adjust some build tags for plan9 9 months ago
tailscale cmd/tailscale/cli: prefix all --help usages with "tailscale ...", some tidying 2 months ago
tailscaled logtail: optimize JSON processing (#11671) 2 months ago
testcontrol all: update copyright and license headers 1 year ago
testwrapper cmd/testwrapper: apply results of all unit tests to coverage for all packages 3 months ago
tsconnect logtail: delete unused code from old way to configure zstd 2 months ago
tsidp cmd/tsidp: add start of OIDC Tailscale IdP 7 months ago
tsshd all: update copyright and license headers 1 year ago
viewer cmd/viewer: import views when generating byteSliceField 3 months ago