Skip to content
This repository has been archived by the owner on Jul 4, 2024. It is now read-only.

Commit

Permalink
Add sampling time flag.
Browse files Browse the repository at this point in the history
  • Loading branch information
eleven26 committed Mar 10, 2023
1 parent 335f7d9 commit 0e29201
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 5 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: goreleaser

on:
push:
tags:
- '*'

permissions:
contents: write

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
-
name: Fetch all tags
run: git fetch --force --tags
-
name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.19
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
distribution: goreleaser
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
28 changes: 28 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# This is an example .goreleaser.yml file with some sensible defaults.
# Make sure to check the documentation at https://goreleaser.com
# git tag v0.0.2 => git push origin v0.0.2 => github ci release
project_name: zipkin_sampler
before:
hooks:
- go mod tidy
builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin
archives:
- replacements:
386: i386
amd64: x86_64
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ incpatch .Version }}"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
2 changes: 1 addition & 1 deletion http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func BenchmarkServeHTTP(b *testing.B) {
w.WriteHeader(http.StatusAccepted)
}))

go serveHTTP("9433", server.URL)
go serveHTTP("9433", server.URL, 5000)
}

b.ReportAllocs()
Expand Down
10 changes: 6 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,32 @@ func main() {
Run: func(cmd *cobra.Command, args []string) {
port, _ := cmd.Flags().GetString("port")
endpoint, _ := cmd.Flags().GetString("endpoint")
t, _ := cmd.Flags().GetInt("time")

fmt.Println("listen on port:", port)
fmt.Println("zipkin endpoint:", endpoint)

serveHTTP(port, endpoint)
serveHTTP(port, endpoint, t)
},
Args: cobra.ExactArgs(0),
}

cmd.Flags().StringP("port", "p", "9422", "zipkin sampler port.")
cmd.Flags().StringP("endpoint", "e", "http://192.168.2.168:9411/api/v2/spans", "zipkin collector endpoint.")
cmd.Flags().IntP("time", "t", 5000, "sampling time.")

//_ = cmd.MarkFlagRequired("endpoint")
_ = cmd.MarkFlagRequired("endpoint")

err := cmd.Execute()
if err != nil {
log.Fatal(err)
}
}

func serveHTTP(port, endpoint string) {
func serveHTTP(port, endpoint string, t int) {
reporter := sampler.NewReporter(
endpoint, // zipkin server
sampler.NewTimeBaseSampler(time.Second*5), // 采集超过5秒的trace
sampler.NewTimeBaseSampler(time.Millisecond*time.Duration(t)), // 采集超过指定时间的trace
)
collector := sampler.NewCollector(
time.Minute*10, // 超过 30分钟,没有等到 root trace 就丢弃
Expand Down

0 comments on commit 0e29201

Please sign in to comment.