Skip to content

sampling weight & tracestate propagation - #1384

Merged
SylvainJuge merged 23 commits into
elastic:masterfrom
SylvainJuge:add-sampling-weight
Oct 7, 2020
Merged

SylvainJuge merged 23 commits into
elastic:masterfrom
SylvainJuge:add-sampling-weight

Conversation

@SylvainJuge

@SylvainJuge SylvainJuge commented Sep 4, 2020 •

Copy link
Copy Markdown
Member

What does this PR do?

Fixes #1293
Fixes #1385

Implementation notes / questions

  • not sure if Sampler#getSampleRate() is relevant as there might be non-probabilistic samplers which can't provide any meaningful value. For root transactions, we could simply get the value from configuration instead.
  • sample rate rounding is applied to 1) configuration and 2) when parsing tracestate header
  • as an optimization, we might avoid tracestate parsing and transmit as-is if it does not contains es= string,

Checklist

  • This is an enhancement of existing features, or a new feature in existing plugins
    • I have updated CHANGELOG.asciidoc
    • I have added tests that prove my fix is effective or that my feature works
    • Added an API method or config option? Document in which version this will be introduced
    • I have made corresponding changes to the documentation

@SylvainJuge
SylvainJuge marked this pull request as ready for review September 4, 2020 09:10
@ghost

ghost commented Sep 4, 2020 •

Copy link
Copy Markdown

💚 Build Succeeded

Pipeline View Test View Changes Artifacts preview

Expand to view the summary

Build stats

  • Build Cause: [Pull request #1384 updated]

  • Start Time: 2020-10-07T08:35:12.355+0000

  • Duration: 44 min 52 sec

Test stats 🧪

Test Results
Failed 0
Passed 1610
Skipped 12
Total 1622

@SylvainJuge SylvainJuge self-assigned this Sep 4, 2020

@eyalkoren eyalkoren left a comment

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.

Regarding your comment- "as an optimization, we might avoid tracestate parsing and transmit as-is if it does not contains es= string", I think it is more than a nice-to-have, we need to optimize already now.

Let's try to break it:

  • starting a child transaction
    • if parent passed a tracestate
      • if the tracestate header contains es= - only parse from its start position to the next ,. No need to split and iterate over all of it.
      • else (tracestate header does not contain es=) - we are required to split for vendor entries because the spec does not allow more than 32 entries. However, in most cases there will be less than 32, so it should be enough to append our own to the end of it.
    • else (parent did not pass a tracestate header) - create a single-entry tracestate with our value.
  • starting a root transaction - create a single-entry tracestate with our value.

This is already a big optimisation, as it means we will only have to split the header if our agent is intermixed with other vendors, which is probably not the common case.

Furthermore, whenever we add our tracestate entry, since the sample rate comes from the configuration, we can easily create a readymade tracestate entry and register a listener on the transaction_sample_rate config option to replace it when it is changed.

@SylvainJuge

Copy link
Copy Markdown
Member Author

We now have

  • taking the header has-is if we just need to read the value
  • write and append the header to existing values
  • for a given TraceState instance, we cache the last computed header value, thus if sample rate does not change, we don't allocate to compute header.

higherBound = (long) (Long.MAX_VALUE * samplingRate);
lowerBound = -higherBound;
this.sampleRate = samplingRate;
traceStateHeader = TraceState.buildHeaderString(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.

I don't think we need this dependency in TraceState - enough to be able to get sampleRateAsString here and use the the StringBuilder in TraceState to append to the header when required. This means both no allocation and no dependency.
Sorry for nagging, but conceptually - a sampler shouldn't be aware of tracestate

@eyalkoren eyalkoren left a comment

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.

Let's not keep this hanging just because of #1384 (comment) - I'd like to avoid this dependency, but if it complicates stuff, don't bother.
I think if TextTracestateAppender#join() would accept List<CharSequence> instead of List<String> that would make things simpler as you can combine Strings and StringBuilders in the tracestate list.

@eyalkoren eyalkoren left a comment

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.

👍 Thanks for your patience 😊

@codecov-io

Copy link
Copy Markdown

Codecov Report

Merging #1384 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #1384   +/-   ##
=========================================
  Coverage     60.85%   60.85%           
  Complexity     3087     3087           
=========================================
  Files           388      388           
  Lines         17952    17952           
  Branches       2507     2507           
=========================================
  Hits          10925    10925           
  Misses         6313     6313           
  Partials        714      714           

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 b157471...e088b99. Read the comment docs.

@SylvainJuge
SylvainJuge merged commit 2259495 into elastic:master Oct 7, 2020
@SylvainJuge
SylvainJuge deleted the add-sampling-weight branch October 7, 2020 10:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement sample_rate precision spec Adding sampling weight to transactions and spans

3 participants