コード例 #1
0
        public void DefaultSamplingRateIs100Percent()
        {
            var processor = new SamplingTelemetryProcessor(new StubTelemetryProcessor(null));

            Assert.AreEqual(processor.SamplingPercentage, 100.0);
            Assert.IsNull(processor.ProactiveSamplingPercentage);
        }
        public void AdaptiveSamplingSetsExcludedTypesOnInternalSamplingProcessor()
        {
            var tc = new TelemetryConfiguration {
                TelemetryChannel = new StubTelemetryChannel()
            };
            var channelBuilder = new TelemetryProcessorChainBuilder(tc);

            channelBuilder.UseAdaptiveSampling(5, "request;");
            channelBuilder.Build();

            var fieldInfo = typeof(AdaptiveSamplingTelemetryProcessor).GetField("samplingProcessor", BindingFlags.GetField | BindingFlags.Instance | BindingFlags.NonPublic);
            SamplingTelemetryProcessor internalProcessor = (SamplingTelemetryProcessor)fieldInfo.GetValue(tc.TelemetryProcessorChain.FirstTelemetryProcessor);

            Assert.AreEqual("request;", internalProcessor.ExcludedTypes);
        }
        public void SamplingRoutesExcludedTypes()
        {
            var unsampled = new AdaptiveTesterMessageSink();
            var sampled   = new AdaptiveTesterMessageSink();
            SamplingTelemetryProcessor sampler = new SamplingTelemetryProcessor(unsampled, sampled);

            sampler.ExcludedTypes      = "Request";
            sampler.SamplingPercentage = 100.0;

            sampler.Process(new RequestTelemetry());
            sampler.Process(new EventTelemetry());

            Assert.IsNotNull(sampled.events.Dequeue());
            Assert.IsNotNull(unsampled.requests.Dequeue());
        }
コード例 #4
0
        public void EarlyExitWhenProcessingAt100Percent()
        {
            var sentTelemetry = new List <ITelemetry>();
            var processor     = new SamplingTelemetryProcessor(new StubTelemetryProcessor(null)
            {
                OnProcess = t => sentTelemetry.Add(t)
            })
            {
                SamplingPercentage = 100.0
            };

            processor.Process(new RequestTelemetry());

            Assert.IsFalse(((ISupportSampling)sentTelemetry[0]).SamplingPercentage.HasValue);
        }
コード例 #5
0
        public void AllTelemetryIsSentWithDefaultSamplingRate()
        {
            var sentTelemetry = new List <ITelemetry>();
            var processor     = new SamplingTelemetryProcessor(new StubTelemetryProcessor(null)
            {
                OnProcess = t => sentTelemetry.Add(t)
            });

            const int ItemsToGenerate = 100;

            for (int i = 0; i < ItemsToGenerate; i++)
            {
                processor.Process(new RequestTelemetry());
            }

            Assert.AreEqual(ItemsToGenerate, sentTelemetry.Count);
        }
コード例 #6
0
        public void TelemetryItemHasSamplingPercentageSet()
        {
            var sentTelemetry = new List <ITelemetry>();
            var processor     = new SamplingTelemetryProcessor(new StubTelemetryProcessor(null)
            {
                OnProcess = t => sentTelemetry.Add(t)
            });

            processor.SamplingPercentage = 20;

            do
            {
                processor.Process(new RequestTelemetry());
            }while (sentTelemetry.Count == 0);

            Assert.Equal(20, ((ISupportSampling)sentTelemetry[0]).SamplingPercentage);
        }
コード例 #7
0
        public void TelemetryItemSamplingIsSkippedWhenSetByUser()
        {
            var sentTelemetry = new List <ITelemetry>();
            var processor     = new SamplingTelemetryProcessor(new StubTelemetryProcessor(null)
            {
                OnProcess = t => sentTelemetry.Add(t)
            })
            {
                SamplingPercentage = 0
            };

            var requestTelemetry = new RequestTelemetry();

            ((ISupportSampling)requestTelemetry).SamplingPercentage = 100;
            processor.Process(requestTelemetry);

            Assert.AreEqual(1, sentTelemetry.Count);
        }
        public void SamplingWontEarlyExitWhenUnsampledNextPresent()
        {
            var unsampled = new AdaptiveTesterMessageSink();
            var sampled   = new AdaptiveTesterMessageSink();
            SamplingTelemetryProcessor sampler = new SamplingTelemetryProcessor(unsampled, sampled)
            {
                SamplingPercentage = 100.0
            };

            sampler.Process(new RequestTelemetry());
            Assert.IsTrue(sampled.requests.Count == 1);
            var sent = sampled.requests.Dequeue();

            Assert.IsNotNull(sent);
            var sentSample = sent as ISupportSampling;

            Assert.IsNotNull(sentSample);
            Assert.IsTrue(sentSample.SamplingPercentage.HasValue);
        }
        public void SamplingSkipsSampledTelemetryItemProperty()
        {
            var unsampled = new AdaptiveTesterMessageSink();
            var sampled   = new AdaptiveTesterMessageSink();
            SamplingTelemetryProcessor sampler = new SamplingTelemetryProcessor(unsampled, sampled)
            {
                SamplingPercentage = 100.0
            };

            var send        = new RequestTelemetry();
            var sendSampled = (send as ISupportSampling);

            Assert.IsNotNull(sendSampled);
            sendSampled.SamplingPercentage = 25.0;

            sampler.Process(send);

            Assert.IsTrue(unsampled.requests.Count == 1);
            Assert.IsTrue(sampled.requests.Count == 0);
        }
        public void DefaultSamplingRateIs100Percent()
        {
            var processor = new SamplingTelemetryProcessor(new StubTelemetryProcessor(null));

            Assert.Equal(processor.SamplingPercentage, 100.0, 12);
        }