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