diff --git a/.github/workflows/job_coverage.yml b/.github/workflows/job_coverage.yml index 8e054233..3238e771 100644 --- a/.github/workflows/job_coverage.yml +++ b/.github/workflows/job_coverage.yml @@ -3,14 +3,16 @@ name: coverage on: push: branches: [ main, v3, v4 ] + paths-ignore: + - '.github/**' + - '.gitea/**' pull_request: branches: [ main, v3, v4 ] - # Allows you to run this workflow manually from the Actions tab - workflow_dispatch: jobs: build: + if: github.server_url != 'https://github.com' runs-on: ubuntu-latest steps: - name: checkout code @@ -22,7 +24,7 @@ jobs: uses: actions/setup-go@v5 with: cache-dependency-path: "**/*.sum" - go-version: 'stable' + go-version: 'stable' - name: test coverage run: | diff --git a/.github/workflows/job_lint.yml b/.github/workflows/job_lint.yml index c1c8e476..1c104db4 100644 --- a/.github/workflows/job_lint.yml +++ b/.github/workflows/job_lint.yml @@ -3,27 +3,27 @@ name: lint on: pull_request: types: [opened, reopened, synchronize] - branches: - - master - - v3 - - v4 + branches: [ master, v3, v4 ] + paths-ignore: + - '.github/**' + - '.gitea/**' jobs: lint: runs-on: ubuntu-latest steps: - - name: checkout code - uses: actions/checkout@v4 - with: - filter: 'blob:none' - - name: setup go - uses: actions/setup-go@v5 - with: - cache-dependency-path: "**/*.sum" - go-version: 'stable' - - name: setup deps - run: go get -v ./... - - name: run lint - uses: golangci/golangci-lint-action@v6 - with: - version: 'latest' + - name: checkout code + uses: actions/checkout@v4 + with: + filter: 'blob:none' + - name: setup go + uses: actions/setup-go@v5 + with: + cache-dependency-path: "**/*.sum" + go-version: 'stable' + - name: setup deps + run: go get -v ./... + - name: run lint + uses: golangci/golangci-lint-action@v6 + with: + version: 'latest' diff --git a/.github/workflows/job_test.yml b/.github/workflows/job_test.yml index f68cbca4..59a95aee 100644 --- a/.github/workflows/job_test.yml +++ b/.github/workflows/job_test.yml @@ -3,15 +3,12 @@ name: test on: pull_request: types: [opened, reopened, synchronize] - branches: - - master - - v3 - - v4 + branches: [ master, v3, v4 ] push: - branches: - - master - - v3 - - v4 + branches: [ master, v3, v4 ] + paths-ignore: + - '.github/**' + - '.gitea/**' jobs: test: diff --git a/.github/workflows/job_tests.yml b/.github/workflows/job_tests.yml index 4072ee6f..9af22912 100644 --- a/.github/workflows/job_tests.yml +++ b/.github/workflows/job_tests.yml @@ -3,51 +3,48 @@ name: test on: pull_request: types: [opened, reopened, synchronize] - branches: - - master - - v3 - - v4 + branches: [ master, v3, v4 ] push: - branches: - - master - - v3 - - v4 + branches: [ master, v3, v4 ] + paths-ignore: + - '.github/**' + - '.gitea/**' jobs: test: runs-on: ubuntu-latest steps: - - name: checkout code - uses: actions/checkout@v4 - with: - filter: 'blob:none' - - name: checkout tests - uses: actions/checkout@v4 - with: - ref: master - filter: 'blob:none' - repository: unistack-org/micro-tests - path: micro-tests - - name: setup go - uses: actions/setup-go@v5 - with: - cache-dependency-path: "**/*.sum" - go-version: 'stable' - - name: setup go work - env: - GOWORK: ${{ github.workspace }}/go.work - run: | - go work init - go work use . - go work use micro-tests - - name: setup deps - env: - GOWORK: ${{ github.workspace }}/go.work - run: go get -v ./... - - name: run tests - env: - INTEGRATION_TESTS: yes - GOWORK: ${{ github.workspace }}/go.work - run: | - cd micro-tests - go test -mod readonly -v ./... || true + - name: checkout code + uses: actions/checkout@v4 + with: + filter: 'blob:none' + - name: checkout tests + uses: actions/checkout@v4 + with: + ref: master + filter: 'blob:none' + repository: unistack-org/micro-tests + path: micro-tests + - name: setup go + uses: actions/setup-go@v5 + with: + cache-dependency-path: "**/*.sum" + go-version: 'stable' + - name: setup go work + env: + GOWORK: ${{ github.workspace }}/go.work + run: | + go work init + go work use . + go work use micro-tests + - name: setup deps + env: + GOWORK: ${{ github.workspace }}/go.work + run: go get -v ./... + - name: run tests + env: + INTEGRATION_TESTS: yes + GOWORK: ${{ github.workspace }}/go.work + run: | + cd micro-tests + go test -mod readonly -v ./... || true diff --git a/tracer/memory/memory.go b/tracer/memory/memory.go index 64f44ee9..2b85f9fa 100644 --- a/tracer/memory/memory.go +++ b/tracer/memory/memory.go @@ -46,6 +46,10 @@ func (s memoryStringer) String() string { return s.s } +func (t *Tracer) Enabled() bool { + return t.opts.Enabled +} + func (t *Tracer) Flush(_ context.Context) error { return nil } diff --git a/tracer/noop.go b/tracer/noop.go index 7da4bed9..d382c0b2 100644 --- a/tracer/noop.go +++ b/tracer/noop.go @@ -18,6 +18,10 @@ func (t *noopTracer) Spans() []Span { return t.spans } +func (t *noopTracer) Enabled() bool { + return t.opts.Enabled +} + func (t *noopTracer) Start(ctx context.Context, name string, opts ...SpanOption) (context.Context, Span) { options := NewSpanOptions(opts...) span := &noopSpan{ diff --git a/tracer/options.go b/tracer/options.go index 1c67e1e8..2e3b5e00 100644 --- a/tracer/options.go +++ b/tracer/options.go @@ -142,6 +142,8 @@ type Options struct { Name string // ContextAttrFuncs contains funcs that provides tracing ContextAttrFuncs []ContextAttrFunc + // Enabled specify trace status + Enabled bool } // Option func signature @@ -181,6 +183,7 @@ func NewOptions(opts ...Option) Options { Logger: logger.DefaultLogger, Context: context.Background(), ContextAttrFuncs: DefaultContextAttrFuncs, + Enabled: true, } for _, o := range opts { o(&options) @@ -194,3 +197,10 @@ func Name(n string) Option { o.Name = n } } + +// Disabled disable tracer +func Disabled(b bool) Option { + return func(o *Options) { + o.Enabled = !b + } +} diff --git a/tracer/tracer.go b/tracer/tracer.go index 2cf05647..14f1e216 100644 --- a/tracer/tracer.go +++ b/tracer/tracer.go @@ -51,6 +51,8 @@ type Tracer interface { // Extract(ctx context.Context) // Flush flushes spans Flush(ctx context.Context) error + // Enabled returns tracer status + Enabled() bool } type Span interface { diff --git a/util/buffer/seeker_buffer.go b/util/buffer/seeker_buffer.go index 0ecfc71e..5d48c826 100644 --- a/util/buffer/seeker_buffer.go +++ b/util/buffer/seeker_buffer.go @@ -67,6 +67,12 @@ func (b *SeekerBuffer) Close() error { return nil } +// Reset clears all the data out of the buffer and sets the read position to 0. +func (b *SeekerBuffer) Reset() { + b.data = nil + b.pos = 0 +} + // Len returns the length of data remaining to be read. func (b *SeekerBuffer) Len() int { return len(b.data[b.pos:])