Skip to content

lib/gobuild: count S3 uploads and cache hits correctly - #27

Open
shoemoney wants to merge 1 commit into
tailscale:mainfrom
shoemoney:fix/s3-put-metrics
Open

shoemoney wants to merge 1 commit into
tailscale:mainfrom
shoemoney:fix/s3-put-metrics

Conversation

@shoemoney

@shoemoney shoemoney commented Nov 28, 2026 •

Copy link
Copy Markdown

PutCond returns true after an upload, but maybePutObject counts it as a cache hit. Reverse the check so uploads increment put_s3_object and objects already in S3 increment put_s3_found.

Fixes #25. Related: #26, which was closed without merging. This patch is based on current main.

The regression test calls S3Cache.Put with a local cache and an in-memory S3 transport. It checks an upload, a remote hit after local eviction, both action writes, and the reported metrics. Both metric cases fail before the fix and pass afterward.

Passed with Go 1.26.6:

  • GOTOOLCHAIN=go1.26.6 go test -vet=all -race -cpu=1,2 ./...
  • GOTOOLCHAIN=go1.26.6 go run honnef.co/go/tools/cmd/staticcheck@latest ./...

gofmt -l -s and git diff --check are clean. The focused test also passes with the race detector on Go 1.27.4; the full suite passes with GOEXPERIMENT=nojsonv2.

With default Go 1.27.4 settings, the full suite and staticcheck fail to build the pinned github.com/go-json-experiment/json, which still refers to json.SkipFunc and json.DiscardUnknownMembers. The same build failure occurs on unmodified upstream main and affects the current stable Go CI setup. No dependency changes are included here.

@shoemoney
shoemoney marked this pull request as ready for review November 28, 2026 04:38
maybePutObject added to put_s3_found when it had just written the
object, so put_s3_object and put_s3_found were swapped. Count a hit
only when the object was already present and matching.

Fixes tailscale#25

Signed-off-by: Jeremy Schoemaker <jeremy@shoemoney.com>
@shoemoney shoemoney changed the title gobuild: count S3 uploads and cache hits correctly lib/gobuild: count S3 uploads and cache hits correctly Nov 28, 2026
@creachadair

Copy link
Copy Markdown
Member

Thank you @shoemoney, the fix looks good to me. However, we do not need such an elaborate test for this, the metrics are not part of the primary API for this package, so let's just drop that part. Thanks also for the reminder about updating the dependencies, I will take care of that separately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

put_s3_object and put_s3_found metrics are swapped

2 participants