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

Commit

Permalink
Restore linting of the main package
Browse files Browse the repository at this point in the history
Signed-off-by: Yuri Shkuro <[email protected]>
  • Loading branch information
Yuri Shkuro committed Oct 22, 2019
1 parent ec42c2d commit 790ac7d
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PROJECT_ROOT=github.com/uber/jaeger-client-go
PACKAGES := $(shell go list ./... | awk -F/ 'NR>1 {print "./"$$4"/..."}' | grep -v -e ./thrift-gen/... -e ./thrift/... | sort -u)
PACKAGES := . $(shell go list ./... | awk -F/ 'NR>1 {print "./"$$4"/..."}' | grep -v -e ./thrift-gen/... -e ./thrift/... | sort -u)
# all .go files that don't exist in hidden directories
ALL_SRC := $(shell find . -name "*.go" | grep -v -e vendor -e thrift-gen -e ./thrift/ \
-e ".*/\..*" \
Expand Down
25 changes: 18 additions & 7 deletions sampler.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,17 +173,18 @@ func (s *ProbabilisticSampler) String() string {

// -----------------------

// RateLimitingSampler samples at most maxTracesPerSecond. The distribution of sampled traces follows
// burstiness of the service, i.e. a service with uniformly distributed requests will have those
// requests sampled uniformly as well, but if requests are bursty, especially sub-second, then a
// number of sequential requests can be sampled each second.
type RateLimitingSampler struct {
legacySamplerV1Base
maxTracesPerSecond float64
rateLimiter *utils.ReconfigurableRateLimiter
tags []Tag
}

// NewRateLimitingSampler creates a sampler that samples at most maxTracesPerSecond. The distribution of sampled
// traces follows burstiness of the service, i.e. a service with uniformly distributed requests will have those
// requests sampled uniformly as well, but if requests are bursty, especially sub-second, then a number of
// sequential requests can be sampled each second.
// NewRateLimitingSampler creates new RateLimitingSampler.
func NewRateLimitingSampler(maxTracesPerSecond float64) *RateLimitingSampler {
s := new(RateLimitingSampler)
s.delegate = s.IsSampled
Expand Down Expand Up @@ -217,10 +218,12 @@ func (s *RateLimitingSampler) Update(maxTracesPerSecond float64) {
}
}

// Close does nothing.
func (s *RateLimitingSampler) Close() {
// nothing to do
}

// Equal compares with another sampler.
func (s *RateLimitingSampler) Equal(other Sampler) bool {
if o, ok := other.(*RateLimitingSampler); ok {
return s.maxTracesPerSecond == o.maxTracesPerSecond
Expand Down Expand Up @@ -318,6 +321,8 @@ func (s *GuaranteedThroughputProbabilisticSampler) update(lowerBound, samplingRa

// -----------------------

// AdaptiveSampler is a delegating sampler that applies GuaranteedThroughputProbabilisticSampler
// on a per-operation basis.
type AdaptiveSampler struct {
sync.RWMutex

Expand All @@ -327,9 +332,7 @@ type AdaptiveSampler struct {
maxOperations int
}

// NewAdaptiveSampler returns a delegating sampler that applies both ProbabilisticSampler and
// RateLimitingSampler via the GuaranteedThroughputProbabilisticSampler. This sampler keeps track of all
// operations and delegates calls to the respective GuaranteedThroughputProbabilisticSampler.
// NewAdaptiveSampler returns a new AdaptiveSampler.
// TODO (breaking change) remove error from return value
func NewAdaptiveSampler(strategies *sampling.PerOperationSamplingStrategies, maxOperations int) (*AdaptiveSampler, error) {
return newAdaptiveSampler(strategies, maxOperations), nil
Expand All @@ -352,27 +355,33 @@ func newAdaptiveSampler(strategies *sampling.PerOperationSamplingStrategies, max
}
}

// IsSampled is not used and only exists to match Sampler V1 API.
// TODO (breaking change) remove when upgrading everything to SamplerV2
func (s *AdaptiveSampler) IsSampled(id TraceID, operation string) (bool, []Tag) {
return false, nil
}

// OnCreateSpan implements OnCreateSpan of SamplerV2.
func (s *AdaptiveSampler) OnCreateSpan(span *Span) SamplingDecision {
operationName := span.OperationName()
samplerV1 := s.getSamplerForOperation(operationName)
sampled, tags := samplerV1.IsSampled(span.context.TraceID(), operationName)
return SamplingDecision{Sample: sampled, Retryable: true, Tags: tags}
}

// OnSetOperationName implements OnSetOperationName of SamplerV2.
func (s *AdaptiveSampler) OnSetOperationName(span *Span, operationName string) SamplingDecision {
samplerV1 := s.getSamplerForOperation(operationName)
sampled, tags := samplerV1.IsSampled(span.context.TraceID(), operationName)
return SamplingDecision{Sample: sampled, Retryable: false, Tags: tags}
}

// OnSetTag implements OnSetTag of SamplerV2.
func (s *AdaptiveSampler) OnSetTag(span *Span, key string, value interface{}) SamplingDecision {
return SamplingDecision{Sample: false, Retryable: true}
}

// OnFinishSpan implements OnFinishSpan of SamplerV2.
func (s *AdaptiveSampler) OnFinishSpan(span *Span) SamplingDecision {
return SamplingDecision{Sample: false, Retryable: true}
}
Expand Down Expand Up @@ -402,6 +411,7 @@ func (s *AdaptiveSampler) getSamplerForOperation(operation string) Sampler {
return newSampler
}

// Close invokes Close on all underlying samplers.
func (s *AdaptiveSampler) Close() {
s.Lock()
defer s.Unlock()
Expand All @@ -411,6 +421,7 @@ func (s *AdaptiveSampler) Close() {
s.defaultSampler.Close()
}

// Equal is not used.
// TODO (breaking change) remove this in the future
func (s *AdaptiveSampler) Equal(other Sampler) bool {
// NB The Equal() function is overly expensive for AdaptiveSampler since it's composed of multiple
Expand Down
7 changes: 7 additions & 0 deletions sampler_remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,22 @@ func (s *RemotelyControlledSampler) IsSampled(id TraceID, operation string) (boo
return false, nil
}

// OnCreateSpan implements OnCreateSpan of SamplerV2.
func (s *RemotelyControlledSampler) OnCreateSpan(span *Span) SamplingDecision {
return s.sampler.OnCreateSpan(span)
}

// OnSetOperationName implements OnSetOperationName of SamplerV2.
func (s *RemotelyControlledSampler) OnSetOperationName(span *Span, operationName string) SamplingDecision {
return s.sampler.OnSetOperationName(span, operationName)
}

// OnSetTag implements OnSetTag of SamplerV2.
func (s *RemotelyControlledSampler) OnSetTag(span *Span, key string, value interface{}) SamplingDecision {
return s.sampler.OnSetTag(span, key, value)
}

// OnFinishSpan implements OnFinishSpan of SamplerV2.
func (s *RemotelyControlledSampler) OnFinishSpan(span *Span) SamplingDecision {
return s.sampler.OnFinishSpan(span)
}
Expand Down Expand Up @@ -207,6 +211,7 @@ func (s *RemotelyControlledSampler) updateSamplerViaUpdaters(strategy interface{
// ProbabilisticSamplerUpdater is used by RemotelyControlledSampler to parse sampling configuration.
type ProbabilisticSamplerUpdater struct{}

// Update implements Update of SamplerUpdater.
func (u *ProbabilisticSamplerUpdater) Update(sampler SamplerV2, strategy interface{}) (SamplerV2, error) {
type response interface {
GetProbabilisticSampling() *sampling.ProbabilisticSamplingStrategy
Expand All @@ -231,6 +236,7 @@ func (u *ProbabilisticSamplerUpdater) Update(sampler SamplerV2, strategy interfa
// RateLimitingSamplerUpdater is used by RemotelyControlledSampler to parse sampling configuration.
type RateLimitingSamplerUpdater struct{}

// Update implements Update of SamplerUpdater.
func (u *RateLimitingSamplerUpdater) Update(sampler SamplerV2, strategy interface{}) (SamplerV2, error) {
type response interface {
GetRateLimitingSampling() *sampling.RateLimitingSamplingStrategy
Expand All @@ -256,6 +262,7 @@ type AdaptiveSamplerUpdater struct {
MaxOperations int // required
}

// Update implements Update of SamplerUpdater.
func (u *AdaptiveSamplerUpdater) Update(sampler SamplerV2, strategy interface{}) (SamplerV2, error) {
type response interface {
GetOperationSampling() *sampling.PerOperationSamplingStrategies
Expand Down
3 changes: 3 additions & 0 deletions sampler_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,15 @@ func samplerV1toV2(s Sampler) SamplerV2 {
// TODO (breaking change) remove this in the next major release
type SamplerV2Base struct{}

// IsSampled implements IsSampled of Sampler.
func (SamplerV2Base) IsSampled(id TraceID, operation string) (sampled bool, tags []Tag) {
return false, nil
}

// Close implements Close of Sampler.
func (SamplerV2Base) Close() {}

// Equal implements Equal of Sampler.
func (SamplerV2Base) Equal(other Sampler) bool { return false }

// legacySamplerV1Base is used as a base for simple samplers that only implement
Expand Down
2 changes: 2 additions & 0 deletions span_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ func (c SpanContext) IsFirehose() bool {
return c.samplingState.isFirehose()
}

// ExtendedSamplingState returns the custom state object for a given key. If the value for this key does not exist,
// it is initialized via initValue function. This state can be used by samplers (e.g. experimental.PrioritySampler).
func (c SpanContext) ExtendedSamplingState(key interface{}, initValue func() interface{}) interface{} {
return c.samplingState.extendedStateForKey(key, initValue)
}
Expand Down

0 comments on commit 790ac7d

Please sign in to comment.