Skip to content
This repository has been archived by the owner on Jun 14, 2023. It is now read-only.

Add tracer sampler #73

Merged
merged 13 commits into from
Sep 13, 2020
Merged

Add tracer sampler #73

merged 13 commits into from
Sep 13, 2020

Conversation

xbkaishui
Copy link
Contributor

Fix #70 , support client side trace sampling service.

@rainbend rainbend added this to the 1.0.0 milestone Sep 2, 2020
@wu-sheng wu-sheng requested a review from rainbend September 2, 2020 15:38
@wu-sheng wu-sheng added the enhancement New feature or request label Sep 2, 2020
sampler.go Outdated
type RandomSampler struct {
samplingRate float64
rand *rand.Rand
Threshold int
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why T in upper case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just for test, random sampler is not easy to test the correctness

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed Threshold to threshold, sorry I am newer to golang

sampler.go Outdated

func NewRandomSampler(samplingRate float64) *RandomSampler {
if samplingRate < 0.0 || samplingRate > 1.0 {
return nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is not a good practice, the user would expect nil when use sampling unless you have an err status.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about <=0 and >=1.0 use NewConstSampler?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, move the logic to WithSampler

@xbkaishui xbkaishui requested a review from wu-sheng September 3, 2020 04:06
segment.go Outdated
@@ -237,7 +237,11 @@ func newSegmentRoot(segmentSpan *segmentSpanImpl) *rootSegmentSpan {
break
}
}
s.tracer.reporter.Send(append(s.segment, s))
//check need send segment with sample service
sampled := s.tracer.sampler.IsSampled(s.TraceID, s.FirstSpan.GetOperationName())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Should be sampled when the first Span is created, and NoopSpan is returned when ignored.
  2. Sampling should be forced when downstream services are sampled.

Hi @xbkaishui, that's my suggestion, what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @arugal, thanks for your cr, I have a couple of questions about what your mention
for the first one, how to decide which one is the first span ?
for the second one, how to check when downstream services are sampled, if it is have sw8, I should consider it is force sampled?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how to decide which one is the first span ?

go2sky/trace.go

Lines 116 to 119 in fdae247

parentSpan, ok := ctx.Value(ctxKeyInstance).(segmentSpan)
if !ok {
parentSpan = nil
}

When parentSpan is nil.

how to check when downstream services are sampled, if it is have sw8, I should consider it is force sampled?

Yes, when sw8 header exist.

I think that the code should be added to trace#CreateLocalSpan or trace#createNoop.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @arugal Thanks for you help, changed as your suggestion. please help review again

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. CreateEntrySpan and CreateExitSpan should judge the CreateLocalSpan returns NoopSpan or not. Specifically CreateExitSpan, if NoopSpan returns span type is wrong error.

  2. traceID is not required for IsSampled, please recheck.

move sample logic to CreateEntrySpan
@xbkaishui
Copy link
Contributor Author

@arugal, I have changed the logic , please help to check if it is acceptable, thanks

@xbkaishui xbkaishui requested a review from rainbend September 4, 2020 16:13
@codecov-commenter
Copy link

Codecov Report

Merging #73 into master will decrease coverage by 0.46%.
The diff coverage is 63.41%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #73      +/-   ##
==========================================
- Coverage   69.59%   69.12%   -0.47%     
==========================================
  Files          12       13       +1     
  Lines         638      677      +39     
==========================================
+ Hits          444      468      +24     
- Misses        158      171      +13     
- Partials       36       38       +2     
Impacted Files Coverage Δ
trace_opts.go 37.50% <0.00%> (-62.50%) ⬇️
trace.go 80.18% <58.33%> (-3.15%) ⬇️
sampler.go 100.00% <100.00%> (ø)
span_opts.go 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fdae247...e28762a. Read the comment docs.

@xbkaishui
Copy link
Contributor Author

@arugal , changed as your request, please help to check again. Thanks

Copy link
Member

@rainbend rainbend left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the late reply. I may not have described it clearly before.

trace.go Outdated Show resolved Hide resolved
Copy link
Member

@rainbend rainbend left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you for contribution :)

@rainbend rainbend merged commit 5ff73ea into SkyAPM:master Sep 13, 2020
@JuankleChan
Copy link

can this commit merger into v0.3 & v0.4 branch ?

@rainbend
Copy link
Member

can this commit merger into v0.3 & v0.4 branch ?

v0.3.0 and v0.4.0 is tag.

@JuankleChan
Copy link

can this commit merger into v0.3 & v0.4 branch ?

v0.3.0 and v0.4.0 is tag.

what shoud i do if i want tracer sampler but the oap version must be v6.4.0? is it possible to new a branch for adapting the old grcp protocol?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

how to set client sample rate
5 participants