Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: peterbourgon/trc
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.0.2
Choose a base ref
...
head repository: peterbourgon/trc
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.0.3
Choose a head ref
  • 6 commits
  • 70 files changed
  • 2 contributors

Commits on Jun 12, 2023

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    96da685 View commit details

Commits on Jun 16, 2023

  1. Copy the full SHA
    9ada6f5 View commit details
  2. Don't allow Free to recycle unfinished traces (#6)

    * Don't allow Free to recycle unfinished traces
    
    * Fix typo
    
    * Comment cleanup
    peterbourgon authored Jun 16, 2023
    Copy the full SHA
    03f6fff View commit details
  3. Remove dead code

    peterbourgon committed Jun 16, 2023
    Copy the full SHA
    904fc71 View commit details

Commits on Sep 17, 2023

  1. v0.0.2 — huge refactor (#7)

    * Initial commit of potential refactor
    
    * Fix
    
    * WIP
    
    * WIP
    
    * WIP
    
    * WIP
    
    * Select -> Search
    
    * Fix SearchStats IsZero
    
    * Fix StreamTrace Duration
    
    * Broker benchmark
    
    * Broker benchmark
    
    * Broker benchmark
    
    * Fix example
    
    * DropRate
    
    * trcstream
    
    * WIP
    
    * WIP
    
    * Large change
    
    * Huge WIP
    
    * cmd/trc plus more stuff
    
    * WIP
    
    * rm trcstream
    
    * cmd/trc WIP
    
    * WIP
    
    * WIP
    
    * Timeline WIP (trash)
    
    * Tweaks
    
    * WIP fixes
    
    * WIP
    
    * Checkin 1
    
    * trcweb fixups
    
    * Super WIP
    
    * Super WIP
    
    * Super WIP
    
    * Super WIP
    
    * Big WIP
    
    * WIP
    
    * No more broker async
    
    * go mod tidy
    
    * WIP
    
    * tidy
    
    * Final revive fixups
    
    * Final test fixes
    
    * Don't exclude internal from revive
    
    * Windows test hack fix?
    
    * Static trace sort
    peterbourgon authored Sep 17, 2023
    Copy the full SHA
    039ae3a View commit details
  2. hack updates

    peterbourgon committed Sep 17, 2023
    Copy the full SHA
    fd19c3a View commit details
Showing with 4,687 additions and 2,759 deletions.
  1. +38 −17 .github/workflows/test.yaml
  2. +2 −0 .revive.toml
  3. +1 −2 README.md
  4. +2 −4 _examples/trc-basic/go.mod
  5. +3 −6 _examples/trc-basic/go.sum
  6. +4 −1 _examples/trc-basic/main.go
  7. +2 −4 _examples/trc-complex/go.mod
  8. +3 −6 _examples/trc-complex/go.sum
  9. +10 −10 _examples/trc-complex/kv.go
  10. +40 −47 _examples/trc-complex/main.go
  11. +75 −6 benchmark_test.go
  12. +132 −0 broker.go
  13. +53 −0 broker_test.go
  14. +178 −0 cmd/trc/main.go
  15. +97 −0 cmd/trc/search.go
  16. +208 −0 cmd/trc/stream.go
  17. +63 −0 cmd/trc/trc.go
  18. +25 −0 cmd/trc/util.go
  19. +216 −0 collector.go
  20. +131 −0 collector_test.go
  21. +159 −0 decorators.go
  22. +4 −4 doc.go
  23. +23 −27 eztrc/easy.go
  24. +190 −0 filter.go
  25. +4 −3 go.mod
  26. +10 −2 go.sum
  27. +13 −0 hack/lint-parallel-tests
  28. +15 −0 hack/run-action-tests
  29. +15 −0 hack/update-action-tests
  30. +16 −14 helpers.go
  31. +4 −0 helpers_test.go
  32. +20 −9 internal/trcdebug/counters.go
  33. +6 −0 internal/trcringbuf/ringbuffer_test.go
  34. +20 −0 internal/trcutil/atomic.go
  35. +2 −0 internal/trcutil/doc.go
  36. +13 −0 internal/trcutil/errors.go
  37. +97 −0 internal/trcutil/humanize.go
  38. +39 −0 internal_test.go
  39. +316 −0 search_stats.go
  40. +77 −0 search_stats_test.go
  41. +227 −0 search_types.go
  42. +2 −0 stack_test.go
  43. +21 −21 trace.go
  44. +145 −87 trace_core.go
  45. +160 −0 trace_static.go
  46. +31 −0 trace_static_test.go
  47. +6 −10 trace_test.go
  48. +0 −536 trchttp/assets/traces.html
  49. +0 −152 trchttp/client.go
  50. +0 −6 trchttp/doc.go
  51. +0 −78 trchttp/e2e_test.go
  52. +0 −408 trchttp/render.go
  53. +0 −179 trchttp/server.go
  54. +0 −182 trcstore/collector.go
  55. +0 −82 trcstore/collector_test.go
  56. +0 −4 trcstore/doc.go
  57. +0 −374 trcstore/search.go
  58. +0 −48 trcstore/search_test.go
  59. +0 −314 trcstore/stats.go
  60. +0 −54 trcstore/stats_test.go
  61. +0 −33 trcstore/util_test.go
  62. +9 −0 trcweb/assets/embed.go
  63. +63 −26 trchttp/assets/style.css → trcweb/assets/traces.css
  64. +573 −0 trcweb/assets/traces.html
  65. +2 −0 trcweb/doc.go
  66. +82 −0 trcweb/e2e_test.go
  67. +14 −3 {trchttp → trcweb}/middleware.go
  68. +372 −0 trcweb/render.go
  69. +524 −0 trcweb/trace_server.go
  70. +130 −0 trcweb/util.go
55 changes: 38 additions & 17 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -4,10 +4,21 @@ on:
types: [opened, synchronize]
push:
branches: [main]
schedule:
- cron: "0 12 1 * *" # first day of the month at 12:00

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
platform: [ubuntu-latest, macos-latest, windows-latest]

runs-on: ${{ matrix.platform }}

defaults:
run:
shell: bash

steps:
- name: Install Go
uses: actions/setup-go@v3
@@ -20,40 +31,50 @@ jobs:
ref: ${{ github.event.pull_request.head.sha }}

- name: Prepare cache
id: cache
run: |
echo "GOCACHE=$(go env GOCACHE)" >> $GITHUB_ENV
echo "GOMODCACHE=$(go env GOMODCACHE)" >> $GITHUB_ENV
echo "GOVERSION=$(go env GOVERSION)" >> $GITHUB_ENV
mkdir -p $(go env GOCACHE)
mkdir -p $(go env GOMODCACHE)
echo "GOCACHE=$(go env GOCACHE)" >> $GITHUB_OUTPUT
echo "GOMODCACHE=$(go env GOMODCACHE)" >> $GITHUB_OUTPUT
echo "GOVERSION=$(go env GOVERSION)" >> $GITHUB_OUTPUT
mkdir -p $(go env GOCACHE) || true
mkdir -p $(go env GOMODCACHE) || true
- name: Cache
uses: actions/cache@v3
with:
path: |
${{ env.GOCACHE }}
${{ env.GOMODCACHE }}
key: test.1-${{ runner.os }}-${{ env.GOVERSION }}-${{ hashFiles('**/go.mod') }}
${{ steps.cache.outputs.GOCACHE }}
${{ steps.cache.outputs.GOMODCACHE }}
key: test.1-${{ runner.os }}-${{ steps.cache.outputs.GOVERSION }}-${{ hashFiles('**/go.mod') }}
restore-keys: |
test.1-${{ runner.os }}-${{ env.GOVERSION }}-
test.1-${{ runner.os }}-${{ steps.cache.outputs.GOVERSION }}-${{ hashFiles('**/go.mod') }}
test.1-${{ runner.os }}-${{ steps.cache.outputs.GOVERSION }}-
test.1-${{ runner.os }}-
- name: Install tools
run: |
go install honnef.co/go/tools/cmd/staticcheck@latest
go install mvdan.cc/gofumpt@latest
go install github.com/mgechev/revive@latest
- name: gofmt
- name: Run gofmt
if: matrix.platform != 'windows-latest' # :<
run: diff <(gofmt -d . 2>/dev/null) <(printf '')

- name: go vet
run: go vet --printfuncs=Tracef,Errorf,LazyTracef,LazyErrorf ./...
- name: Run go vet
run: go vet ./...

- name: staticcheck
- name: Run staticcheck
run: staticcheck ./...

- name: gofumpt
run: diff <(gofumpt -d -e -l . 2>/dev/null) <(printf '')
- name: Run gofumpt
run: gofumpt -d -e -l .

- name: Run revive
run: revive --set_exit_status --config="./.revive.toml" --exclude="./_examples/..." ./...

- name: Run lint-parallel-tests
run: hack/lint-parallel-tests

- name: go test
- name: Run go test
run: go test -v -race ./...
2 changes: 2 additions & 0 deletions .revive.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[rule.unused-parameter]
disabled = true
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -37,8 +37,7 @@ Traces can be viewed, queried, etc. through a web UI.

<kbd><img src="/ui.png"/></kbd>

See the [examples dir](https://github.com/peterbourgon/trc/tree/main/_examples)
for more complete example applications.
See the examples directory for more complete example applications.

The current API is experimental and unstable. Breaking changes are guaranteed.
Use at your own risk.
6 changes: 2 additions & 4 deletions _examples/trc-basic/go.mod
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
module trc-basic

go 1.20
go 1.21

require github.com/peterbourgon/trc v0.0.0-00010101000000-000000000000

require (
github.com/go-stack/stack v1.8.1 // indirect
github.com/bernerdschaefer/eventsource v0.0.0-20130606115634-220e99a79763 // indirect
github.com/oklog/ulid/v2 v2.1.0 // indirect
github.com/peterbourgon/unixtransport v0.0.1 // indirect
golang.org/x/exp v0.0.0-20230425010034-47ecfdc1ba53 // indirect
)

replace github.com/peterbourgon/trc => ../..
9 changes: 3 additions & 6 deletions _examples/trc-basic/go.sum
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
github.com/go-stack/stack v1.8.1 h1:ntEHSVwIt7PNXNpgPmVfMrNhLtgjlmnZha2kOpuRiDw=
github.com/go-stack/stack v1.8.1/go.mod h1:dcoOX6HbPZSZptuspn9bctJ+N/CnF5gGygcUP3XYfe4=
github.com/bernerdschaefer/eventsource v0.0.0-20130606115634-220e99a79763 h1:Xhc57KuvOszD8WMiNzIeTfmpfUJ9lodF/j/cTN0v0Is=
github.com/bernerdschaefer/eventsource v0.0.0-20130606115634-220e99a79763/go.mod h1:Son4chyIHRln8G19kywUdR55p9OsyCC0zi9CY9Me92k=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/oklog/ulid/v2 v2.1.0 h1:+9lhoxAP56we25tyYETBBY1YLA2SaoLvUFgrP2miPJU=
github.com/oklog/ulid/v2 v2.1.0/go.mod h1:rcEKHmBBKfef9DhnvX7y1HZBYxjXb0cP5ExxNsTT1QQ=
github.com/pborman/getopt v0.0.0-20170112200414-7148bc3a4c30/go.mod h1:85jBQOZwpVEaDAr341tbn15RS4fCAsIst0qp7i8ex1o=
github.com/peterbourgon/unixtransport v0.0.1 h1:M3bP6so2XBtW+jOSI611/Lt/XuCT77s58NC36ASXYtE=
github.com/peterbourgon/unixtransport v0.0.1/go.mod h1:287HHyPa+1Uv2IEIXsf77UIJHQHAbcb8rFXroYVpjpI=
golang.org/x/exp v0.0.0-20230425010034-47ecfdc1ba53 h1:5llv2sWeaMSnA3w2kS57ouQQ4pudlXrR0dCgw51QK9o=
golang.org/x/exp v0.0.0-20230425010034-47ecfdc1ba53/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w=
5 changes: 4 additions & 1 deletion _examples/trc-basic/main.go
Original file line number Diff line number Diff line change
@@ -8,9 +8,11 @@ import (
"net/http"
"net/http/httptest"
_ "net/http/pprof"
"os"
"strings"
"time"

"github.com/peterbourgon/trc"
"github.com/peterbourgon/trc/eztrc"
)

@@ -38,7 +40,8 @@ func main() {
}

// Here's how you would change the number of traces per category.
eztrc.Collector().Resize(context.Background(), 100)
eztrc.Collector().SetCategorySize(100)
eztrc.Collector().SetDecorators(trc.LogDecorator(os.Stderr))

// Create a single serve mux for both API endpoints.
mux := http.NewServeMux()
6 changes: 2 additions & 4 deletions _examples/trc-complex/go.mod
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
module trc-complex

go 1.20
go 1.21

require (
github.com/felixge/fgprof v0.9.3
github.com/peterbourgon/trc v0.0.0-00010101000000-000000000000
)

require (
github.com/go-stack/stack v1.8.1 // indirect
github.com/bernerdschaefer/eventsource v0.0.0-20130606115634-220e99a79763 // indirect
github.com/google/pprof v0.0.0-20211214055906-6f57359322fd // indirect
github.com/oklog/ulid/v2 v2.1.0 // indirect
github.com/peterbourgon/unixtransport v0.0.1 // indirect
golang.org/x/exp v0.0.0-20230425010034-47ecfdc1ba53 // indirect
)

replace github.com/peterbourgon/trc => ../..
9 changes: 3 additions & 6 deletions _examples/trc-complex/go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
github.com/bernerdschaefer/eventsource v0.0.0-20130606115634-220e99a79763 h1:Xhc57KuvOszD8WMiNzIeTfmpfUJ9lodF/j/cTN0v0Is=
github.com/bernerdschaefer/eventsource v0.0.0-20130606115634-220e99a79763/go.mod h1:Son4chyIHRln8G19kywUdR55p9OsyCC0zi9CY9Me92k=
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
@@ -6,26 +8,21 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/felixge/fgprof v0.9.3 h1:VvyZxILNuCiUCSXtPtYmmtGvb65nqXh2QFWc0Wpf2/g=
github.com/felixge/fgprof v0.9.3/go.mod h1:RdbpDgzqYVh/T9fPELJyV7EYJuHB55UTEULNun8eiPw=
github.com/go-stack/stack v1.8.1 h1:ntEHSVwIt7PNXNpgPmVfMrNhLtgjlmnZha2kOpuRiDw=
github.com/go-stack/stack v1.8.1/go.mod h1:dcoOX6HbPZSZptuspn9bctJ+N/CnF5gGygcUP3XYfe4=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/pprof v0.0.0-20211214055906-6f57359322fd h1:1FjCyPC+syAzJ5/2S8fqdZK1R22vvA0J7JZKcuOIQ7Y=
github.com/google/pprof v0.0.0-20211214055906-6f57359322fd/go.mod h1:KgnwoLYCZ8IQu3XUZ8Nc/bM9CCZFOyjUNOSygVozoDg=
github.com/ianlancetaylor/demangle v0.0.0-20210905161508-09a460cdf81d/go.mod h1:aYm2/VgdVmcIU8iMfdMvDMsRAQjcfZSKFby6HOFvi/w=
github.com/oklog/ulid/v2 v2.1.0 h1:+9lhoxAP56we25tyYETBBY1YLA2SaoLvUFgrP2miPJU=
github.com/oklog/ulid/v2 v2.1.0/go.mod h1:rcEKHmBBKfef9DhnvX7y1HZBYxjXb0cP5ExxNsTT1QQ=
github.com/pborman/getopt v0.0.0-20170112200414-7148bc3a4c30/go.mod h1:85jBQOZwpVEaDAr341tbn15RS4fCAsIst0qp7i8ex1o=
github.com/peterbourgon/unixtransport v0.0.1 h1:M3bP6so2XBtW+jOSI611/Lt/XuCT77s58NC36ASXYtE=
github.com/peterbourgon/unixtransport v0.0.1/go.mod h1:287HHyPa+1Uv2IEIXsf77UIJHQHAbcb8rFXroYVpjpI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
golang.org/x/exp v0.0.0-20230425010034-47ecfdc1ba53 h1:5llv2sWeaMSnA3w2kS57ouQQ4pudlXrR0dCgw51QK9o=
golang.org/x/exp v0.0.0-20230425010034-47ecfdc1ba53/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w=
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
20 changes: 10 additions & 10 deletions _examples/trc-complex/kv.go
Original file line number Diff line number Diff line change
@@ -44,7 +44,7 @@ func (a *KV) ServeHTTP(w http.ResponseWriter, r *http.Request) {
case r.Method == "DELETE":
a.handleDel(w, r)
default:
eztrc.Errorf(r.Context(), "method %s not allowed", r.Method)
eztrc.LazyErrorf(r.Context(), "method %s not allowed", r.Method)
http.Error(w, "method must be GET, PUT, or DELETE", http.StatusMethodNotAllowed)
}
}
@@ -59,7 +59,7 @@ func (a *KV) handleSet(w http.ResponseWriter, r *http.Request) {
return
}

tr.Tracef("key %q", key)
tr.LazyTracef("key %q", key)

valbuf, err := io.ReadAll(r.Body)
if err != nil {
@@ -74,7 +74,7 @@ func (a *KV) handleSet(w http.ResponseWriter, r *http.Request) {
return
}

tr.Tracef("val %q", val)
tr.LazyTracef("val %q", val)

a.s.Set(ctx, key, val)
}
@@ -85,21 +85,21 @@ func (a *KV) handleGet(w http.ResponseWriter, r *http.Request) {

key := getKey(r.URL.Path)
if key == "" {
tr.Errorf("key not provided")
tr.LazyErrorf("key not provided")
http.Error(w, "key required", http.StatusBadRequest)
return
}

tr.Tracef("key %q", key)
tr.LazyTracef("key %q", key)

val, ok := a.s.Get(ctx, key)
if !ok {
tr.Errorf("key not found")
tr.LazyErrorf("key not found")
http.Error(w, "not found", http.StatusNoContent)
return
}

tr.Tracef("val %q", val)
tr.LazyTracef("val %q", val)

fmt.Fprintln(w, val)
}
@@ -110,17 +110,17 @@ func (a *KV) handleDel(w http.ResponseWriter, r *http.Request) {

key := getKey(r.URL.Path)
if key == "" {
tr.Errorf("key not provided")
tr.LazyErrorf("key not provided")
http.Error(w, "key required", http.StatusBadRequest)
return
}

tr.Tracef("key %q", key)
tr.LazyTracef("key %q", key)

ok := a.s.Del(ctx, key)

if !ok {
tr.Errorf("key not found")
tr.LazyErrorf("key not found")
http.Error(w, "not found", http.StatusNoContent)
return
}
Loading