Skip to content
This repository was archived by the owner on Sep 13, 2022. It is now read-only.

Support delayed sampling#380

Merged
yurishkuro merged 28 commits intojaegertracing:masterfrom
yurishkuro:delayed-sampling
Sep 4, 2019
Merged

Support delayed sampling#380
yurishkuro merged 28 commits intojaegertracing:masterfrom
yurishkuro:delayed-sampling

Conversation

@yurishkuro
Copy link
Copy Markdown
Member

@yurishkuro yurishkuro commented Aug 29, 2019

Which problem is this PR solving?

Short description of the changes

  • Sampling finalized mode is no longer early triggered by read operations like injecting context or starting a child span. Instead, sampling may remain unfinalized indefinitely if at least one of the samplers returns retryable=true.
  • Introducing remote flag in SpanContext that is set when the context has been extracted from a carrier/request. When a child span has a remote context as a parent, the child sampling is finalized immediately, thus preserving the existing behavior of respecting the upstream sampling decision.
  • Most samplers are upgraded to V2
    • Remote and PerOperation samplers are completely switched to V2, because they always delegate to the underlying sampler and isSampled() cannot be adequately delegated to V2 API
    • Primitive samplers implement both V1 and V2
    • GuaranteedThroughputSampler is kept at V1 because it delegates to primitive ones using V1 API (there's no benefit for it to use V2)
  • Primitive samplers now return retryable=false from onCreateSpan. If someone wants a deferred sampling behavior, then some samplers should be returning retryable=true.
  • Adding experimental tag-sampler and priority-sampler

Yuri Shkuro added 3 commits August 29, 2019 17:13
Signed-off-by: Yuri Shkuro <[email protected]>
@codecov

This comment has been minimized.

Yuri Shkuro added 4 commits August 30, 2019 14:15
Signed-off-by: Yuri Shkuro <[email protected]>
Signed-off-by: Yuri Shkuro <[email protected]>
Signed-off-by: Yuri Shkuro <[email protected]>
Signed-off-by: Yuri Shkuro <[email protected]>
@yurishkuro yurishkuro changed the title [WIP] Support delayed sampling Support delayed sampling Aug 30, 2019
@yurishkuro yurishkuro changed the title Support delayed sampling [WIP] Support delayed sampling Aug 30, 2019
Comment thread test/span.js
assert.equal(prevTagLength, span._tags.length, 'The sampling.priority tag should only be set once');
});

describe('adaptive sampling tests for span', () => {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

moved to top level test below

Comment thread src/util.js Outdated
_samplingRate: number;

constructor(samplingRate: number) {
super('ProbabilisticSampler');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is calling by name the preferred way of invoking super? It seems pretty fragile

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

it simply passes the "name" that is used in toString and uniqueName() functions.

}

update(samplingRate: number): boolean {
if (this._samplingRate == samplingRate) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is there an equality function which takes in an epsilon for float comparisons?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

not that I know off. I don't think it matters here. If the rate is coming from JSON strategy, then float representation will be the same as long as the string representation is the same.

Comment thread src/span_context.js
_baggage: any;
_debugId: ?string;
_samplingState: SamplingState;
_remote: boolean; // indicates that span context represents a remote parent
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Replace with isRemoteParent?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

In Java Beans naming we don't add is to the field names. And parent would be incorrect here because it's this span context that is "remote".

Comment thread src/tracer.js
Comment thread test/samplers/delayed_sampling.js Outdated
Comment thread test/samplers/delayed_sampling.js Outdated
Comment thread test/samplers/delayed_sampling.js Outdated
}

declare type PrioritySamplerState = {
samplerFired: Array<boolean>,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

How is samplerFired different than retryable?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

samplerFired is set once the given sampler returns retryabe=false. I will add a type comment.

Comment thread test/samplers/delayed_sampling.js Outdated
assert.isFalse(span._spanContext.samplingFinalized, 'finalized');
});

it('should sample and finalize created span with tag', () => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Might be better to nest these under a "matching tag(s)" describe block

Comment thread test/samplers/delayed_sampling.js Outdated
@vprithvi
Copy link
Copy Markdown
Contributor

vprithvi commented Sep 3, 2019

I think the API looks pretty usable

Comment thread test/samplers/delayed_sampling.js Outdated
Yuri Shkuro added 10 commits September 3, 2019 12:18
Signed-off-by: Yuri Shkuro <[email protected]>
Signed-off-by: Yuri Shkuro <[email protected]>
Signed-off-by: Yuri Shkuro <[email protected]>
Signed-off-by: Yuri Shkuro <[email protected]>
Signed-off-by: Yuri Shkuro <[email protected]>
Signed-off-by: Yuri Shkuro <[email protected]>
Signed-off-by: Yuri Shkuro <[email protected]>
Signed-off-by: Yuri Shkuro <[email protected]>
Signed-off-by: Yuri Shkuro <[email protected]>
Comment thread src/samplers/experimental/tag_equals_sampler.js Outdated
Signed-off-by: Yuri Shkuro <[email protected]>
this._sampler = new PrioritySampler([tagSampler, this._sampler]);
return true;
}
return super._updateSampler(strategy);
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@vprithvi this is working, but is hacky, because super._updateSampler works in-place, so I have to do tricks with overriding this._sampler multiple times. Also, the tag & priority samplers are replaced every time, which is not necessarily a problem since they are both stateless and we don't run updates frequently.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

These trade offs seem reasonable for our use case


it('should parse extended strategy response', function(done) {
server.addStrategy('service1', {
strategyType: 'extended',
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@vprithvi thoughts?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not a fan of this in the short term bc it would mean that the backend implementation would need to modify the payload from the thrift sampling object (or modify it after it has been converted to JSON).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The easiest way to avoid it is to nest the "classic" response under a property.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

just made that change

remoteSampler.close();
});

it('should parse extended strategy response', function(done) {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

as a POC this works, but we probably need to add more tests to ensure that the extended remote sampler can switch back and forth between extended and normal adaptive behavior.

@yurishkuro yurishkuro changed the title [WIP] Support delayed sampling Support delayed sampling Sep 4, 2019
Signed-off-by: Yuri Shkuro <[email protected]>
Comment thread src/samplers/experimental/tag_equals_sampler.js
this._sampler = new PrioritySampler([tagSampler, this._sampler]);
return true;
}
return super._updateSampler(strategy);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

These trade offs seem reasonable for our use case


it('should parse extended strategy response', function(done) {
server.addStrategy('service1', {
strategyType: 'extended',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not a fan of this in the short term bc it would mean that the backend implementation would need to modify the payload from the thrift sampling object (or modify it after it has been converted to JSON).

Signed-off-by: Yuri Shkuro <[email protected]>
Signed-off-by: Yuri Shkuro <[email protected]>
@yurishkuro yurishkuro merged commit ca64265 into jaegertracing:master Sep 4, 2019
@yurishkuro yurishkuro deleted the delayed-sampling branch September 4, 2019 20:22
Iuriy-Budnikov pushed a commit to agile-pm/jaeger-client-node that referenced this pull request Sep 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants