Skip to content

Commit

Permalink
enhance: simple head samplers for ratio and rate limit
Browse files Browse the repository at this point in the history
  • Loading branch information
plyr4 committed Aug 21, 2024
1 parent d921b3e commit e590f23
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ services:
VELA_SCHEDULE_ALLOWLIST: '*'
VELA_ENABLE_TRACING: true
VELA_TRACING_SERVICE_NAME: 'vela-server'
VELA_TRACING_SAMPLE_RATIO: 1
VELA_TRACING_SAMPLE_RATELIMIT_PER_SECOND: 1
OTEL_EXPORTER_OTLP_ENDPOINT: http://jaeger:4318
VELA_TRACING_SAMPLER_RATIO: 1
env_file:
- .env
restart: always
Expand Down
12 changes: 9 additions & 3 deletions tracing/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,15 @@ var Flags = []cli.Flag{
Value: "vela-server",
},
&cli.Float64Flag{
EnvVars: []string{"VELA_TRACING_SAMPLER_RATIO", "TRACING_SAMPLER_RATIO"},
Name: "tracing.sampler.ratio",
Usage: "set otel tracing sampler ratio. see: https://opentelemetry.io/docs/concepts/sampling/",
EnvVars: []string{"VELA_TRACING_SAMPLE_RATIO", "OTEL_TRACE_SAMPLE_RATIO"},
Name: "tracing.sample.ratio",
Usage: "set otel tracing head-sampler acceptance ratio. see: https://opentelemetry.io/docs/concepts/sampling/",
Value: 0.5,
},
&cli.Float64Flag{
EnvVars: []string{"VELA_TRACING_SAMPLE_RATELIMIT_PER_SECOND", "OTEL_TRACING_SAMPLE_RATELIMIT_PER_SECOND"},
Name: "tracing.sample.persecond",
Usage: "set otel tracing head-sampler rate-limiting to N per second. see: https://opentelemetry.io/docs/concepts/sampling/",
Value: 1,
},
}
2 changes: 1 addition & 1 deletion tracing/sampler/sampler.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type rateLimitSampler struct {
limiter *rate.Limiter
}

func newRateLimitSampler(perSec float64) *rateLimitSampler {
func NewRateLimitSampler(perSec float64) *rateLimitSampler {

Check failure on line 27 in tracing/sampler/sampler.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] tracing/sampler/sampler.go#L27

unexported-return: exported func NewRateLimitSampler returns unexported type *sampler.rateLimitSampler, which can be annoying to use (revive)
Raw output
tracing/sampler/sampler.go:27:42: unexported-return: exported func NewRateLimitSampler returns unexported type *sampler.rateLimitSampler, which can be annoying to use (revive)
func NewRateLimitSampler(perSec float64) *rateLimitSampler {
                                         ^
return &rateLimitSampler{
maxPerSecond: perSec,
limiter: rate.NewLimiter(rate.Every(time.Duration(1.0/perSec)*time.Second), 1),
Expand Down
11 changes: 7 additions & 4 deletions tracing/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package tracing
import (
"context"

"github.com/go-vela/server/tracing/sampler"

Check failure on line 8 in tracing/tracer.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] tracing/tracer.go#L8

File is not `gci`-ed with --skip-generated -s standard -s default -s blank -s dot -s prefix(github.com/go-vela) --custom-order (gci)
Raw output
tracing/tracer.go:8: File is not `gci`-ed with --skip-generated -s standard -s default -s blank -s dot -s prefix(github.com/go-vela) --custom-order (gci)
	"github.com/go-vela/server/tracing/sampler"
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
"go.opentelemetry.io/otel"
Expand Down Expand Up @@ -34,12 +35,14 @@ func initTracer(c *cli.Context) (*sdktrace.TracerProvider, error) {
return nil, err
}

logrus.Info("intializing tracing using sampler ratio: ", c.Float64("tracing.sampler.ratio"))
logrus.Infof("intializing tracing using samplers: ratio(%f), persecond(%f)", c.Float64("tracing.sampler.ratio"), c.Float64("tracing.sampler.persecond"))

ratioSampler := sdktrace.ParentBased(sdktrace.TraceIDRatioBased(c.Float64("tracing.sampler.ratio")))
rateLimitSampler := sdktrace.ParentBased(sampler.NewRateLimitSampler(c.Float64("tracing.sampler.persecond")))

tp := sdktrace.NewTracerProvider(
// sdktrace.WithSampler(sdktrace.AlwaysSample()),
sdktrace.WithSampler(sdktrace.ParentBased(sdktrace.TraceIDRatioBased(c.Float64("tracing.sampler.ratio")))),
// sdktrace.WithSampler(sdktrace.RateLimiting(1000, 1000)),
sdktrace.WithSampler(ratioSampler),
sdktrace.WithSampler(rateLimitSampler),
sdktrace.WithBatcher(exporter),
sdktrace.WithResource(res),
)
Expand Down

0 comments on commit e590f23

Please sign in to comment.