public void TransmissionProcessorIsAddedDefaultWhenNoOtherTelemetryProcessorsAreConfigured()
 {
     var config = new TelemetryConfiguration();
     var builder = new TelemetryProcessorChainBuilder(config);            
     builder.Build();
     Assert.IsType<TransmissionProcessor>(config.TelemetryProcessorChain.FirstTelemetryProcessor);
 }
 public void UsesTelemetryProcessorGivenInUseToBuild()
 {
     var config = new TelemetryConfiguration();
     var builder = new TelemetryProcessorChainBuilder(config);
     builder.Use((next) => new StubTelemetryProcessor(next));                    
     builder.Build();
     Assert.IsType<StubTelemetryProcessor>(config.TelemetryProcessorChain.FirstTelemetryProcessor);
 }
示例#3
0
        public void ThrowsInvalidOperationExceptionOnReturningNullFromUse()
        {
            var builder = new TelemetryProcessorChainBuilder(new TelemetryConfiguration());

            builder.Use((next) => null);

            Assert.Throws <InvalidOperationException>(() => builder.Build());
        }
        public void ThrowsInvalidOperationExceptionOnReturningNullFromUse()
        {
            var builder = new TelemetryProcessorChainBuilder(new TelemetryConfiguration());
            builder.Use((next) => null);

            Assert.Throws<InvalidOperationException>(() => builder.Build());
            
        }
        public void TransmissionProcessorIsAddedDefaultWhenNoOtherTelemetryProcessorsAreConfigured()
        {
            var config  = new TelemetryConfiguration();
            var builder = new TelemetryProcessorChainBuilder(config);

            builder.Build();
            Assert.IsType <TransmissionProcessor>(config.TelemetryProcessorChain.FirstTelemetryProcessor);
        }
        public void UsesTelemetryProcessorGivenInUseToBuild()
        {
            var config  = new TelemetryConfiguration();
            var builder = new TelemetryProcessorChainBuilder(config);

            builder.Use(next => new StubTelemetryProcessor(next));
            builder.Build();
            Assert.IsType <StubTelemetryProcessor>(config.TelemetryProcessorChain.FirstTelemetryProcessor);
        }
        public void BuildWillInitializeModules()
        {
            var tc1      = new TelemetryConfiguration();
            var builder1 = new TelemetryProcessorChainBuilder(tc1);

            builder1.Use((next) => new MockProcessorModule());
            builder1.Build();

            Assert.AreEqual(2, tc1.TelemetryProcessors.Count); // Transmission is added by default
            Assert.IsTrue(((MockProcessorModule)tc1.TelemetryProcessors[0]).ModuleInitialized, "Module was not initialized.");
        }
        public void NoExceptionOnReturningNullFromUse()
        {
            var configuration = new TelemetryConfiguration();

            var builder = new TelemetryProcessorChainBuilder(configuration);
            builder.Use(next => null);

            builder.Build();

            Assert.Equal(1, configuration.TelemetryProcessors.Count); // Transmission is added by default
        }
        public void BuildOrdersTelemetryChannelsInOrderOfUseCalls()
        {
           var config = new TelemetryConfiguration() {TelemetryChannel = new StubTelemetryChannel()};
           StringBuilder outputCollector = new StringBuilder();
           var builder = new TelemetryProcessorChainBuilder(config);
           builder.Use((next) => new StubTelemetryProcessor(next) { OnProcess = (item) => { outputCollector.Append("processor1"); } });
           builder.Use((next) => new StubTelemetryProcessor(next) { OnProcess = (item) => { outputCollector.Append("processor2"); } });
           builder.Build();
           config.TelemetryProcessorChain.Process(new StubTelemetry());            

           Assert.Equal("processor1processor2", outputCollector.ToString());
        }
        public void NoExceptionOnReturningNullFromUse()
        {
            var configuration = new TelemetryConfiguration();

            var builder = new TelemetryProcessorChainBuilder(configuration);

            builder.Use(next => null);

            builder.Build();

            Assert.Equal(1, configuration.TelemetryProcessors.Count); // Transmission is added by default
        }
        public void NullProcessorsAreSkipped()
        {
            var configuration = new TelemetryConfiguration();

            var builder = new TelemetryProcessorChainBuilder(configuration);
            builder.Use(next => new StubTelemetryProcessor(next));
            builder.Use(next => null);
            builder.Use(next => new StubTelemetryProcessor(next));

            builder.Build();

            Assert.Equal(3, configuration.TelemetryProcessors.Count); // Transmission is added by default
            Assert.Same(((StubTelemetryProcessor)configuration.TelemetryProcessors[0]).next, ((StubTelemetryProcessor)configuration.TelemetryProcessors[1]));
        }
        public void BuildUsesTelemetryProcesorFactoryOnEachCall()
        {
            var tc1 = new TelemetryConfiguration();
            var tc2 = new TelemetryConfiguration();
            var builder1 = new TelemetryProcessorChainBuilder(tc1);
            builder1.Use((next) => new StubTelemetryProcessor(next));
            builder1.Build();

            var builder2 = new TelemetryProcessorChainBuilder(tc2);
            builder2.Use((next) => new StubTelemetryProcessor(next));
            builder2.Build();
            
            Assert.NotSame(tc1.TelemetryProcessors, tc2.TelemetryProcessors);
        }
        public void NullProcessorsAreSkipped()
        {
            var configuration = new TelemetryConfiguration();

            var builder = new TelemetryProcessorChainBuilder(configuration);

            builder.Use(next => new StubTelemetryProcessor(next));
            builder.Use(next => null);
            builder.Use(next => new StubTelemetryProcessor(next));

            builder.Build();

            Assert.Equal(3, configuration.TelemetryProcessors.Count); // Transmission is added by default
            Assert.Same(((StubTelemetryProcessor)configuration.TelemetryProcessors[0]).next, ((StubTelemetryProcessor)configuration.TelemetryProcessors[1]));
        }
        public void BuildUsesTelemetryProcesorFactoryOnEachCall()
        {
            var tc1      = new TelemetryConfiguration();
            var tc2      = new TelemetryConfiguration();
            var builder1 = new TelemetryProcessorChainBuilder(tc1);

            builder1.Use((next) => new StubTelemetryProcessor(next));
            builder1.Build();

            var builder2 = new TelemetryProcessorChainBuilder(tc2);

            builder2.Use((next) => new StubTelemetryProcessor(next));
            builder2.Build();

            Assert.NotSame(tc1.TelemetryProcessors, tc2.TelemetryProcessors);
        }
示例#15
0
        protected static void BuildTelemetryProcessorChain(XElement definition, TelemetryProcessorChainBuilder builder)
        {
            if (definition != null)
            {
                IEnumerable <XElement> elems = definition.Elements(XmlNamespace + AddElementName);
                foreach (XElement addElement in elems)
                {
                    builder = builder.Use(current =>
                    {
                        var constructorArgs = new object[] { current };
                        return((ITelemetryProcessor)LoadInstance(addElement, typeof(ITelemetryProcessor), null, constructorArgs, null));
                    });
                }
            }

            builder.Build();
        }
        public void BuildOrdersTelemetryChannelsInOrderOfUseCalls()
        {
            var           config          = new TelemetryConfiguration(string.Empty, new StubTelemetryChannel());
            StringBuilder outputCollector = new StringBuilder();
            var           builder         = new TelemetryProcessorChainBuilder(config);

            builder.Use((next) => new StubTelemetryProcessor(next)
            {
                OnProcess = (item) => { outputCollector.Append("processor1"); }
            });
            builder.Use((next) => new StubTelemetryProcessor(next)
            {
                OnProcess = (item) => { outputCollector.Append("processor2"); }
            });
            builder.Build();
            config.TelemetryProcessorChain.Process(new StubTelemetry());

            Assert.Equal("processor1processor2", outputCollector.ToString());
        }
        public void AllTelemetryCapturedWhenProductionRateIsLow()
        {
            var sentTelemetry = new List<ITelemetry>();
            int itemsProduced = 0;

            using (var tc = new TelemetryConfiguration() { TelemetryChannel = new StubTelemetryChannel() })
            {
                var chainBuilder = new TelemetryProcessorChainBuilder(tc);

                // set up addaptive sampling that evaluates and changes sampling % frequently
                chainBuilder
                    .UseAdaptiveSampling(
                        new SamplingPercentageEstimatorSettings()
                        {
                            EvaluationInterval = TimeSpan.FromSeconds(1),
                            SamplingPercentageDecreaseTimeout = TimeSpan.FromSeconds(2),
                            SamplingPercentageIncreaseTimeout = TimeSpan.FromSeconds(2),
                        },
                        this.TraceSamplingPercentageEvaluation)
                    .Use((next) => new StubTelemetryProcessor(next) { OnProcess = (t) => sentTelemetry.Add(t) });

                chainBuilder.Build();

                const int productionFrequencyMs = 1000;

                using (var productionTimer = new Timer(
                            (state) => { tc.TelemetryProcessorChain.Process(new RequestTelemetry()); itemsProduced++; },
                            null,
                            productionFrequencyMs,
                            productionFrequencyMs))
                {
                    Thread.Sleep(25000);
                }
            }

            Assert.Equal(itemsProduced, sentTelemetry.Count);
        }
        public void SamplingPercentageAdjustsAccordingToConstantHighProductionRate()
        {
            var sentTelemetry = new List<ITelemetry>();
            int itemsProduced = 0;

            using (var tc = new TelemetryConfiguration() { TelemetryChannel = new StubTelemetryChannel() })
            {
                var chainBuilder = new TelemetryProcessorChainBuilder(tc);

                // set up addaptive sampling that evaluates and changes sampling % frequently
                chainBuilder
                    .UseAdaptiveSampling(
                        new SamplingPercentageEstimatorSettings()
                        {
                            EvaluationInterval = TimeSpan.FromSeconds(1),
                            SamplingPercentageDecreaseTimeout = TimeSpan.FromSeconds(2),
                            SamplingPercentageIncreaseTimeout = TimeSpan.FromSeconds(2),
                        },
                        this.TraceSamplingPercentageEvaluation)
                    .Use((next) => new StubTelemetryProcessor(next) { OnProcess = (t) => sentTelemetry.Add(t) });

                chainBuilder.Build();

                const int productionFrequencyMs = 100;

                using (var productionTimer = new Timer(
                            (state) =>
                            {
                                for (int i = 0; i < 2; i++)
                                {
                                    tc.TelemetryProcessorChain.Process(new RequestTelemetry());
                                    itemsProduced++;
                                }
                            },
                            null,
                            0,
                            productionFrequencyMs))
                {
                    Thread.Sleep(25000);
                }
            }

            // number of items produced should be close to target of 5/second
            int targetItemCount = 25 * 5;

            // tolrance +-
            int tolerance = targetItemCount / 2;

            Trace.WriteLine(string.Format("'Ideal' telemetry item count: {0}", targetItemCount));
            Trace.WriteLine(string.Format(
                "Expected range: from {0} to {1}",
                targetItemCount - tolerance,
                targetItemCount + tolerance));
            Trace.WriteLine(string.Format(
                "Actual telemetry item count: {0} ({1:##.##}% of ideal)", 
                sentTelemetry.Count,
                100.0 * sentTelemetry.Count / targetItemCount));

            Assert.True(sentTelemetry.Count > targetItemCount - tolerance);
            Assert.True(sentTelemetry.Count < targetItemCount + tolerance);
        }
        private static TelemetryProcessorChain CreateTelemetryProcessorChainWithSampling(IList<ITelemetry> sentTelemetry, double samplingPercentage)
        {
            var tc = new TelemetryConfiguration() {TelemetryChannel = new StubTelemetryChannel()};
            var channelBuilder = new TelemetryProcessorChainBuilder(tc);            
            channelBuilder.UseSampling(samplingPercentage);
            channelBuilder.Use((next) => new StubTelemetryProcessor(next) { OnProcess = (t) => sentTelemetry.Add(t) });
            
            channelBuilder.Build();

            return tc.TelemetryProcessorChain;
        }