public void ZeroProbabilityNeverSamplesAnyTrace()
        {
            var sampler = new ProbabilisticSampler(0);

            Assert.False(sampler.Sample("op1", 0));
            Assert.False(sampler.Sample("op2", 1));
            Assert.False(sampler.Sample("op2.1", 8383));
            Assert.False(sampler.Sample("op3", 89480932480));
        }
        public void OneProbabilitySamplesAllTraces()
        {
            var sampler = new ProbabilisticSampler(0.999);

            Assert.True(sampler.Sample("op1", 0));
            Assert.True(sampler.Sample("op2", 1));
            Assert.True(sampler.Sample("op2.1", 8383));
            Assert.True(sampler.Sample("op3", 89480932480));
            Assert.True(sampler.Sample("op4", long.MaxValue));
        }
示例#3
0
        public void TestSamplingBoundariesPositive()
        {
            double samplingRate = 0.5;

            long     halfwayBoundary = 0x3fffffffffffffffL;
            ISampler sampler         = new ProbabilisticSampler(samplingRate);

            Assert.True(sampler.Sample("", new TraceId(halfwayBoundary)).IsSampled);

            Assert.False(sampler.Sample("", new TraceId(halfwayBoundary + 2)).IsSampled);
        }
示例#4
0
        public void TestSamplingBoundariesNegative()
        {
            double samplingRate = 0.5;

            long     halfwayBoundary = -0x4000000000000000L;
            ISampler sampler         = new ProbabilisticSampler(samplingRate);

            Assert.True(sampler.Sample("", new TraceId(halfwayBoundary)).IsSampled);

            Assert.False(sampler.Sample("", new TraceId(halfwayBoundary - 1)).IsSampled);
        }
示例#5
0
        public void TestTags()
        {
            ProbabilisticSampler sampler = new ProbabilisticSampler(0.1);
            var tags = sampler.Sample("vadacurry", new TraceId(20L)).Tags;

            Assert.Equal("probabilistic", tags["sampler.type"]);
            Assert.Equal(0.1, tags["sampler.param"]);
        }
        public void SamplerSetsTheCorrectTags()
        {
            var sampler = new ProbabilisticSampler(0.43);
            var sample  = sampler.Sample("an op", ulong.MinValue);

            Assert.Equal("probabilistic", sample.Tags["sampler"]);
            Assert.Equal(0.43.ToString(), sample.Tags["sampler-arg"]);
        }
        public void SamplerOnlySamplesLowerProbabilityBound(double probability)
        {
            var sampler = new ProbabilisticSampler(probability);
            var sampled = sampler.Sample("abc", 1);

            Assert.True(sampled);
            var random = ulong.MaxValue * probability / 2 + 5;

            Assert.True(sampler.Sample("something", (ulong)random));

            var upperBound = (ulong)Math.Ceiling(ulong.MaxValue * probability);

            Assert.False(sampler.Sample("upper", upperBound));

            Assert.False(sampler.Sample("upper + 1", upperBound + 1));
            Assert.False(sampler.Sample("upper + something", upperBound + 9894));
        }
示例#8
0
        public PerOperationSamplerTests()
        {
            _loggerFactory = new NullLoggerFactory();
            _defaultProbabilisticSampler = Substitute.ForPartsOf <ProbabilisticSampler>(0);

            _undertest = new PerOperationSampler(MaxOperations, _operationToSamplers, _defaultProbabilisticSampler,
                                                 DefaultLowerBoundTracesPerSecond, _loggerFactory);

            _defaultProbabilisticSampler.Sample(operation, TraceId)
            .Returns(new SamplingStatus(true, EmptyTags));

            _defaultProbabilisticSampler.SamplingRate.Returns(DefaultSamplingProbability);
        }