-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* wip: add sampling. current limits include... * hardcoded sampling rate of 50% * sampling decision should only be performed at root or honour parent span decision * allow more than probabilistic strategy for sampling * pretty sure i've not understood the model, code tidying to come * extract probabilistic sampling into a class * change sample_rate to double * use bernoulli distribution to decide whether to sample * make sampling decision for root span * inspired by the jaeger module we check whether any of the references are ChildOf to identify a parent span. * tracer- check whether referenced context is set, fix impl of sampling * set sampling_set_flag also * propagation of sampling status * propagation works but seems to be non-deterministic when incoming context is incomplete (i.e. just sampling header but no trace id) * call Sampler::ShouldSample to determine whether to sample * currently hardcoded to prob sample with fixed rate but will be replaced next * refactor: simplify sampling decision call * write tests and fix implementation * add support for old OtTracer constructor: defaults to always sampling * use static thread_local random generator * move random include to file that uses it * Span: only report when sampled * tracer: check whether parent span context is valid to determine sampling * parent context may be not-null but empty- not sufficient to just check if there's a parent span, must also check whether it's valid. * probabilistic sampler bounds p(sampled) between 0 and 1 * simplify constructor of OtTracer when setting default sampler * default initialize sampled_ to true for Span * clang formatted * store test log artifacts * TEMP: specify build dir to capture test artifact output - normally this looks like it would be configured with the circleci config but this should work without repo write access * initialize flags when constructing context from span. only need sampled_flag set * ProbabilisticSampler: make constructor explicit * use std::make_shared to return OtTracer from makeZipkinOtTracer
- Loading branch information
Showing
15 changed files
with
141 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,3 +32,5 @@ | |
*.app | ||
|
||
bazel-* | ||
|
||
.build/ |
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
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,10 @@ | ||
#include "sampling.h" | ||
#include <random> | ||
|
||
namespace zipkin { | ||
bool ProbabilisticSampler::ShouldSample() { | ||
static thread_local std::mt19937 rng(std::random_device{}()); | ||
std::bernoulli_distribution dist(sample_rate_); | ||
return dist(rng); | ||
} | ||
} // namespace zipkin |
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,23 @@ | ||
#pragma once | ||
#include <algorithm> | ||
#include <memory> | ||
|
||
namespace zipkin { | ||
class Sampler { | ||
public: | ||
virtual ~Sampler() = default; | ||
virtual bool ShouldSample() = 0; | ||
}; | ||
|
||
class ProbabilisticSampler : public Sampler { | ||
public: | ||
explicit ProbabilisticSampler(double sample_rate) | ||
: sample_rate_(std::max(0.0, std::min(sample_rate, 1.0))){}; | ||
bool ShouldSample() override; | ||
|
||
private: | ||
double sample_rate_; | ||
}; | ||
|
||
typedef std::unique_ptr<Sampler> SamplerPtr; | ||
} // namespace zipkin |
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