This repository has been archived by the owner on May 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 289
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support delayed sampling decisions (#447)
* Support delayed sampling decision Signed-off-by: Yuri Shkuro <ys@uber.com> * go fmt Signed-off-by: Yuri Shkuro <ys@uber.com> * Add sampling on finishing span; fix metrics Signed-off-by: Yuri Shkuro <ys@uber.com> * Remove unused field Signed-off-by: Yuri Shkuro <ys@uber.com> * Fix comment Signed-off-by: Yuri Shkuro <ys@uber.com> * Fix comment Signed-off-by: Yuri Shkuro <ys@uber.com> * Remove empty branch Signed-off-by: Yuri Shkuro <ys@uber.com>
- Loading branch information
1 parent
ff64c7c
commit c9bbde9
Showing
11 changed files
with
255 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// Copyright (c) 2019 Uber Technologies, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package jaeger | ||
|
||
type SamplingDecision struct { | ||
sample bool | ||
retryable bool | ||
tags []Tag | ||
} | ||
|
||
type SamplerV2 interface { | ||
OnCreateSpan(span *Span) SamplingDecision | ||
OnSetOperationName(span *Span, operationName string) SamplingDecision | ||
OnSetTag(span *Span, key string, value interface{}) SamplingDecision | ||
OnFinishSpan(span *Span) SamplingDecision | ||
|
||
// Close does a clean shutdown of the sampler, stopping any background | ||
// go-routines it may have started. | ||
Close() | ||
} | ||
|
||
// samplerV1toV2 wraps legacy V1 sampler into an adapter that make it look like V2. | ||
func samplerV1toV2(s Sampler) SamplerV2 { | ||
if s2, ok := s.(SamplerV2); ok { | ||
return s2 | ||
} | ||
type legacySamplerV1toV2Adapter struct { | ||
legacySamplerV1Base | ||
} | ||
return &legacySamplerV1toV2Adapter{ | ||
legacySamplerV1Base: legacySamplerV1Base{ | ||
delegate: s.IsSampled, | ||
}, | ||
} | ||
} | ||
|
||
// legacySamplerV1Base is used as a base for simple samplers that only implement | ||
// the legacy isSampled() function that is not sensitive to its arguments. | ||
type legacySamplerV1Base struct { | ||
delegate func(id TraceID, operation string) (sampled bool, tags []Tag) | ||
} | ||
|
||
func (s *legacySamplerV1Base) OnCreateSpan(span *Span) SamplingDecision { | ||
isSampled, tags := s.delegate(span.context.traceID, span.operationName) | ||
return SamplingDecision{sample: isSampled, retryable: false, tags: tags} | ||
} | ||
|
||
func (s *legacySamplerV1Base) OnSetOperationName(span *Span, operationName string) SamplingDecision { | ||
isSampled, tags := s.delegate(span.context.traceID, span.operationName) | ||
return SamplingDecision{sample: isSampled, retryable: false, tags: tags} | ||
} | ||
|
||
func (s *legacySamplerV1Base) OnSetTag(span *Span, key string, value interface{}) SamplingDecision { | ||
return SamplingDecision{sample: false, retryable: true} | ||
} | ||
|
||
func (s *legacySamplerV1Base) OnFinishSpan(span *Span) SamplingDecision { | ||
return SamplingDecision{sample: false, retryable: true} | ||
} | ||
|
||
func (s *legacySamplerV1Base) Close() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright (c) 2019 The Jaeger Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package jaeger | ||
|
||
var _ SamplerV2 = new(ConstSampler) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.