Exemple #1
0
        public void AdaptiveSampler_CheckingMovingAverageBounds()
        {
            AdaptiveSampler sampler = new AdaptiveSampler(20, 0.5);

            Assert.Equal(1.0, sampler.CheckMovingAverageBounds(1.43));
            Assert.Equal(0.0, sampler.CheckMovingAverageBounds(-0.3));
        }
Exemple #2
0
        public void AdaptiveSampler_CheckNumItemsSampled()
        {
            SamplingParameters parameters = new SamplingParameters(this.parent, this.traceId, "test", this.activityKindServer, null, null);
            AdaptiveSampler    sampler    = new AdaptiveSampler(5, 0.5);

            int numSampled = 0;

            // run for 200 seconds to let adaptive sampling adjust
            for (int i = 0; i < 200; i++)
            {
                // sends 10 events in 1 second
                int events = 10;
                for (int j = 0; j < events; j++)
                {
                    SamplingResult result = sampler.ShouldSample(parameters);
                    if (result.IsSampled)
                    {
                        numSampled += 1;
                    }

                    Thread.Sleep(1000 / events);
                }
            }

            int expectedSampled = 10;

            Assert.Equal(expectedSampled, numSampled / 200);
        }
Exemple #3
0
        public void AdaptiveSampler_CheckMaxTelemetry_OutOfBound()
        {
            AdaptiveSampler sampler = new AdaptiveSampler(-5, 0.5);

            sampler.CheckMaxTelemetryItemsPerSecond(-5);
            Assert.Equal(0, sampler.GetMaxTelemetryItemsPerSecond());
        }
Exemple #4
0
        public void AdaptiveSampler_CheckNewProbability_IncreaseMaxAllowed()
        {
            double             oldProbability    = 0.5;
            int                maxSamplesAllowed = 40;
            SamplingParameters parameters        = new SamplingParameters(this.parent, this.traceId, "test", this.activityKindServer, null, null);
            AdaptiveSampler    sampler           = new AdaptiveSampler(maxSamplesAllowed, oldProbability);

            // run for 200 seconds to let adaptive sampling adjust
            for (int i = 0; i < 200; i++)
            {
                // send 20 events each second
                int events = 20;
                for (int j = 0; j < events; j++)
                {
                    sampler.ShouldSample(parameters);
                    Thread.Sleep(1000 / events);
                }
            }

            // since events < maxSamplesAllowed, we expect to see all sampled (probability around 1)
            double expectedProbability = 1.0;

            // Assert.True(sampler.ProbSampler.GetProbability() - 0.1< expectedProbability && expectedProbability < sampler.ProbSampler.GetProbability() + 0.2);
            // Assert.Equal(1.0, sampler.ProbSampler.GetProbability());
            Assert.True(expectedProbability - 0.1 <= sampler.ProbSampler.GetProbability() && sampler.ProbSampler.GetProbability() <= expectedProbability + 0.1);
        }
Exemple #5
0
        public void AdaptiveSampler_Initialization()
        {
            AdaptiveSampler sampler = new AdaptiveSampler(5, 0.5);

            Assert.NotNull(sampler);
            Assert.Equal(5, sampler.GetMaxTelemetryItemsPerSecond());
            Assert.Equal(0.5, sampler.ProbSampler.GetProbability());
            sampler.ProbSampler.SetProbability(0.2);
            Assert.Equal(0.2, sampler.ProbSampler.GetProbability());
        }
Exemple #6
0
        public void BeforeEachTest()
        {
            _compositeTestAgent = new CompositeTestAgent();

            _adaptiveSampler = new AdaptiveSampler(AdaptiveSampler.DefaultTargetSamplesPerInterval, DefaultSamplingTargetIntervalInSecondsForTesting, DefaultSeedForTesting);

            //This will simulate that the agent has connected and force a sampling interval to start
            _compositeTestAgent.ServerConfiguration.SamplingTarget = AdaptiveSampler.DefaultTargetSamplesPerInterval;
            _compositeTestAgent.ServerConfiguration.SamplingTargetPeriodInSeconds = DefaultSamplingTargetIntervalInSecondsForTesting;
            _compositeTestAgent.PushConfiguration();
        }
Exemple #7
0
        public void AdaptiveSampler_CheckNewProbability_Adjusted()
        {
            double             oldProbability    = 0.5;
            int                maxSamplesAllowed = 10; // should stay at 0.5
            SamplingParameters parameters        = new SamplingParameters(this.parent, this.traceId, "test", this.activityKindServer, null, null);
            AdaptiveSampler    sampler           = new AdaptiveSampler(maxSamplesAllowed, oldProbability);

            // run for 200 seconds to let adaptive sampling adjust
            for (int i = 0; i < 200; i++)
            {
                // send 20 events each second
                int events = 20;
                for (int j = 0; j < events; j++)
                {
                    sampler.ShouldSample(parameters);
                    Thread.Sleep(1000 / events);
                }
            }

            // probability should be around (10/20) 0.5
            double expectedProbability = 0.5;

            Assert.True(expectedProbability - 0.1 <= sampler.ProbSampler.GetProbability() && sampler.ProbSampler.GetProbability() <= expectedProbability + 0.2);

            // max increases, so probability should increase to around 1
            sampler.CheckMaxTelemetryItemsPerSecond(40);

            // run for 200 seconds to let adaptive sampling adjust
            for (int i = 0; i < 200; i++)
            {
                // send 20 events each second
                int events = 20;
                for (int j = 0; j < events; j++)
                {
                    sampler.ShouldSample(parameters);
                    Thread.Sleep(1000 / events);
                }
            }

            expectedProbability = 1;
            Assert.Equal(expectedProbability, sampler.ProbSampler.GetProbability());
            Assert.True(expectedProbability - 0.1 <= sampler.ProbSampler.GetProbability() && sampler.ProbSampler.GetProbability() <= expectedProbability + 0.2);
        }
Exemple #8
0
        public void AdaptiveSampler_CheckNewProbability_StaySame()
        {
            double             oldProbability    = 0.5;
            int                maxSamplesAllowed = 10; // should stay at 0.5
            SamplingParameters parameters        = new SamplingParameters(this.parent, this.traceId, "test", this.activityKindServer, null, null);
            AdaptiveSampler    sampler           = new AdaptiveSampler(maxSamplesAllowed, oldProbability);

            // run for 200 seconds to let adaptive sampling adjust
            for (int i = 0; i < 200; i++)
            {
                // send 20 events each second
                int events = 20;
                for (int j = 0; j < events; j++)
                {
                    sampler.ShouldSample(parameters);
                    Thread.Sleep(1000 / events);
                }
            }

            // since events > maxSamplesAllowed, we expect to less sampled (20/10 = 0.5)
            double expectedProbability = 0.5;

            Assert.True(expectedProbability - 0.2 <= sampler.ProbSampler.GetProbability() && sampler.ProbSampler.GetProbability() <= expectedProbability + 0.2);
        }
Exemple #9
0
 public void AfterEachTest()
 {
     _compositeTestAgent.Dispose();
     _adaptiveSampler = null;
 }
 public void Setup()
 {
     _adaptiveSampler = new AdaptiveSampler(Target, Interval, new Random(DefaultSeedForTesting));
 }