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

Support delayed sampling #380

Merged
merged 28 commits into from
Sep 4, 2019

Conversation

yurishkuro
Copy link
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 <ys@uber.com>
Signed-off-by: Yuri Shkuro <ys@uber.com>
Signed-off-by: Yuri Shkuro <ys@uber.com>
@codecov

This comment has been minimized.

Yuri Shkuro added 4 commits August 30, 2019 14:15
Signed-off-by: Yuri Shkuro <ys@uber.com>
Signed-off-by: Yuri Shkuro <ys@uber.com>
Signed-off-by: Yuri Shkuro <ys@uber.com>
Signed-off-by: Yuri Shkuro <ys@uber.com>
@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
Yuri Shkuro added 6 commits August 30, 2019 17:39
Signed-off-by: Yuri Shkuro <ys@uber.com>
Signed-off-by: Yuri Shkuro <ys@uber.com>
Signed-off-by: Yuri Shkuro <ys@uber.com>
Signed-off-by: Yuri Shkuro <ys@uber.com>
Signed-off-by: Yuri Shkuro <ys@uber.com>
Signed-off-by: Yuri Shkuro <ys@uber.com>
@@ -244,166 +252,180 @@ describe('span should', () => {
assert.equal(prevTagLength, span._tags.length, 'The sampling.priority tag should only be set once');
});

describe('adaptive sampling tests for span', () => {
Copy link
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

src/util.js Outdated Show resolved Hide resolved
_samplingRate: number;

constructor(samplingRate: number) {
super('ProbabilisticSampler');
Copy link
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
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.

@@ -26,6 +28,14 @@ export default class ProbabilisticSampler implements LegacySamplerV1 {
this._samplingRate = samplingRate;
}

update(samplingRate: number): boolean {
if (this._samplingRate == samplingRate) {
Copy link
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
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.

@@ -26,6 +26,7 @@ export default class SpanContext {
_baggage: any;
_debugId: ?string;
_samplingState: SamplingState;
_remote: boolean; // indicates that span context represents a remote parent
Copy link
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
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".

src/tracer.js Show resolved Hide resolved
test/samplers/delayed_sampling.js Outdated Show resolved Hide resolved
test/samplers/delayed_sampling.js Outdated Show resolved Hide resolved
}

declare type PrioritySamplerState = {
samplerFired: Array<boolean>,
Copy link
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
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.

assert.isFalse(span._spanContext.samplingFinalized, 'finalized');
});

it('should sample and finalize created span with tag', () => {
Copy link
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

test/samplers/delayed_sampling.js Outdated Show resolved Hide resolved
@vprithvi
Copy link
Contributor

vprithvi commented Sep 3, 2019

I think the API looks pretty usable

Yuri Shkuro added 9 commits September 3, 2019 12:18
Signed-off-by: Yuri Shkuro <ys@uber.com>
Signed-off-by: Yuri Shkuro <ys@uber.com>
Signed-off-by: Yuri Shkuro <ys@uber.com>
Signed-off-by: Yuri Shkuro <ys@uber.com>
Signed-off-by: Yuri Shkuro <ys@uber.com>
Signed-off-by: Yuri Shkuro <ys@uber.com>
Signed-off-by: Yuri Shkuro <ys@uber.com>
Signed-off-by: Yuri Shkuro <ys@uber.com>
Signed-off-by: Yuri Shkuro <ys@uber.com>
Yuri Shkuro added 2 commits September 3, 2019 19:20
Signed-off-by: Yuri Shkuro <ys@uber.com>
Signed-off-by: Yuri Shkuro <ys@uber.com>
Signed-off-by: Yuri Shkuro <ys@uber.com>
this._sampler = new PrioritySampler([tagSampler, this._sampler]);
return true;
}
return super._updateSampler(strategy);
Copy link
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
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
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
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
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
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
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 <ys@uber.com>
this._sampler = new PrioritySampler([tagSampler, this._sampler]);
return true;
}
return super._updateSampler(strategy);
Copy link
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
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 <ys@uber.com>
Signed-off-by: Yuri Shkuro <ys@uber.com>
@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