public void MergeStatsEngine_Mix()
        {
            var metric5 = MetricWireModel.BuildMetric(_metricNameService, "DotNet/name", null, MetricDataWireModel.BuildTimingData(TimeSpan.FromSeconds(4), TimeSpan.FromSeconds(4)));
            var metric6 = MetricWireModel.BuildMetric(_metricNameService, "DotNet/another", null, MetricDataWireModel.BuildTimingData(TimeSpan.FromSeconds(8), TimeSpan.FromSeconds(6)));

            var engine1 = new MetricStatsCollection();
            MetricStatsDictionary <string, MetricDataWireModel> scoped1 = new MetricStatsDictionary <string, MetricDataWireModel>();

            scoped1.Merge("DotNet/name1", MetricDataWireModel.BuildTimingData(TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(1)), MetricDataWireModel.BuildAggregateData);
            scoped1.Merge("DotNet/name2", MetricDataWireModel.BuildTimingData(TimeSpan.FromSeconds(3), TimeSpan.FromSeconds(2)), MetricDataWireModel.BuildAggregateData);
            engine1.MergeUnscopedStats(metric5);
            engine1.MergeScopedStats("engine1scope", scoped1);

            var engine2 = new MetricStatsCollection();
            MetricStatsDictionary <string, MetricDataWireModel> scoped2 = new MetricStatsDictionary <string, MetricDataWireModel>();

            scoped2.Merge("DotNet/name3", MetricDataWireModel.BuildTimingData(TimeSpan.FromSeconds(4), TimeSpan.FromSeconds(1)), MetricDataWireModel.BuildAggregateData);
            scoped2.Merge("DotNet/name4", MetricDataWireModel.BuildTimingData(TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(2)), MetricDataWireModel.BuildAggregateData);
            engine1.MergeUnscopedStats(metric6);
            engine1.MergeScopedStats("engine2scope", scoped1);

            var engine3 = new MetricStatsCollection();

            engine3.Merge(engine1);
            engine3.Merge(engine2);

            IEnumerable <MetricWireModel> stats = engine3.ConvertToJsonForSending(_metricNameService);
            var count = 0;

            foreach (MetricWireModel current in stats)
            {
                count++;
            }
            Assert.AreEqual(6, count);
        }
示例#2
0
        public void MergeScopedStats_Three()
        {
            var txName  = new TransactionMetricName("WebTransaction", "Test", false);
            var txStats = new TransactionMetricStatsCollection(txName);

            txStats.MergeScopedStats(MetricName.Create("DotNet/name"), MetricDataWireModel.BuildTimingData(TimeSpan.FromSeconds(3), TimeSpan.FromSeconds(2)));
            txStats.MergeScopedStats(MetricName.Create("DotNet/name"), MetricDataWireModel.BuildTimingData(TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(4)));
            txStats.MergeScopedStats(MetricName.Create("DotNet/other"), MetricDataWireModel.BuildTimingData(TimeSpan.FromSeconds(4), TimeSpan.FromSeconds(3)));

            Assert.AreEqual("WebTransaction/Test", txStats.GetTransactionName().PrefixedName);

            MetricStatsDictionary <string, MetricDataWireModel> unscoped = txStats.GetUnscopedForTesting();
            MetricStatsDictionary <string, MetricDataWireModel> scoped   = txStats.GetScopedForTesting();

            Assert.AreEqual(0, unscoped.Count);
            Assert.AreEqual(2, scoped.Count);
            var data = scoped["DotNet/name"];

            Assert.NotNull(data);
            Assert.AreEqual(2, data.Value0);
            Assert.AreEqual(8, data.Value1);
            Assert.AreEqual(6, data.Value2);
            Assert.AreEqual(3, data.Value3);
            Assert.AreEqual(5, data.Value4);

            data = scoped["DotNet/other"];
            Assert.NotNull(data);
            Assert.AreEqual(1, data.Value0);
            Assert.AreEqual(4, data.Value1);
            Assert.AreEqual(3, data.Value2);
            Assert.AreEqual(4, data.Value3);
            Assert.AreEqual(4, data.Value4);
        }
示例#3
0
        public void Setup()
        {
            Mock.Arrange(() => _metricNameService.RenameMetric(Arg.IsAny <string>())).Returns <string>(name => name);
            _connectionHandler = new ConnectionHandler(new JsonSerializer(), Mock.Create <ICollectorWireFactory>(), Mock.Create <IProcessStatic>(), Mock.Create <IDnsStatic>(),
                                                       Mock.Create <ILabelsService>(), Mock.Create <Environment>(), Mock.Create <ISystemInfo>(), Mock.Create <IAgentHealthReporter>(), Mock.Create <IEnvironment>());

            var validScopedMetric = MetricWireModel.BuildMetric(_metricNameService, "DotNet/name", "WebTransaction/DotNet/name",
                                                                MetricDataWireModel.BuildTimingData(TimeSpan.FromSeconds(3.0), TimeSpan.FromSeconds(2.0)));

            var validUnscopedMetric = MetricWireModel.BuildMetric(_metricNameService, "Custom/name", string.Empty,
                                                                  MetricDataWireModel.BuildTimingData(TimeSpan.FromSeconds(4.0), TimeSpan.FromSeconds(3.0)));

            var validMetricWireModels = new List <MetricWireModel> {
                validScopedMetric, validUnscopedMetric
            };

            _wellformedMetricData = new MetricWireModelCollection("440491846668652", 1450462672.0, 1450462710.0, validMetricWireModels);
        }
示例#4
0
        public void Metrics_are_retained_after_harvest_if_response_equals_retain()
        {
            // Arrange
            IEnumerable <MetricWireModel> unsentMetrics = null;

            Mock.Arrange(() => _dataTransportService.Send(Arg.IsAny <IEnumerable <MetricWireModel> >()))
            .Returns <IEnumerable <MetricWireModel> >((metrics) =>
            {
                unsentMetrics = metrics;
                return(DataTransportResponseStatus.Retain);
            });

            _metricAggregator.Collect(BuildMetric(_metricNameService, "DotNet/metric1", null, MetricDataWireModel.BuildTimingData(TimeSpan.FromSeconds(3), TimeSpan.FromSeconds(1))));
            _harvestAction();
            _metricAggregator.Collect(BuildMetric(_metricNameService, "DotNet/metric2", null, MetricDataWireModel.BuildTimingData(TimeSpan.FromSeconds(3), TimeSpan.FromSeconds(1))));
            _harvestAction();

            // Assert
            Assert.AreEqual(3, unsentMetrics.Count()); // include "DotNet/metric1", "DotNet/metric2" and "Supportability/MetricHarvest/transmit" metrics
            Assert.IsTrue(unsentMetrics.Any(_ => _.MetricName.Name == "DotNet/metric1" && _.Data.Value0 == 1));
            Assert.IsTrue(unsentMetrics.Any(_ => _.MetricName.Name == "DotNet/metric2" && _.Data.Value0 == 1));
            Assert.IsTrue(unsentMetrics.Any(_ => _.MetricName.Name == "Supportability/MetricHarvest/transmit" && _.Data.Value0 == 2));
        }
示例#5
0
        public void Harvest_AggregatesMetricsBeforeSending()
        {
            var sentMetrics = Enumerable.Empty <MetricWireModel>();

            Mock.Arrange(() => _dataTransportService.Send(Arg.IsAny <IEnumerable <MetricWireModel> >()))
            .DoInstead <IEnumerable <MetricWireModel> >(metrics => sentMetrics = metrics);

            _metricAggregator.Collect(MetricWireModel.BuildMetric(_metricNameService, "DotNet/metric1", null, MetricDataWireModel.BuildTimingData(TimeSpan.FromSeconds(3), TimeSpan.FromSeconds(1))));
            _metricAggregator.Collect(MetricWireModel.BuildMetric(_metricNameService, "DotNet/metric1", null, MetricDataWireModel.BuildTimingData(TimeSpan.FromSeconds(7), TimeSpan.FromSeconds(5))));
            _metricAggregator.Collect(MetricWireModel.BuildMetric(_metricNameService, "DotNet/metric2", "scope2", MetricDataWireModel.BuildTimingData(TimeSpan.FromSeconds(7), TimeSpan.FromSeconds(5))));

            _harvestAction();

            Assert.NotNull(sentMetrics);
            Assert.AreEqual(3, sentMetrics.Count());
            MetricWireModel sentMetric1 = null;
            MetricWireModel sentMetric2 = null;
            MetricWireModel sentMetric3 = null;

            foreach (MetricWireModel metric in sentMetrics)
            {
                if ("DotNet/metric1".Equals(metric.MetricName.Name))
                {
                    sentMetric1 = metric;
                }
                else if ("DotNet/metric2".Equals(metric.MetricName.Name))
                {
                    sentMetric2 = metric;
                }
                else if ("Supportability/MetricHarvest/transmit".Equals(metric.MetricName.Name))
                {
                    sentMetric3 = metric;
                }
                else
                {
                    Assert.Fail("Unexpected metric name " + metric.MetricName.Name);
                }
            }

            NrAssert.Multiple(
                () => Assert.AreEqual("DotNet/metric1", sentMetric1.MetricName.Name),
                () => Assert.AreEqual(null, sentMetric1.MetricName.Scope),
                () => Assert.AreEqual(2, sentMetric1.Data.Value0),
                () => Assert.AreEqual(10, sentMetric1.Data.Value1),
                () => Assert.AreEqual(6, sentMetric1.Data.Value2),
                () => Assert.AreEqual(3, sentMetric1.Data.Value3),
                () => Assert.AreEqual(7, sentMetric1.Data.Value4),
                () => Assert.AreEqual(58, sentMetric1.Data.Value5),

                () => Assert.AreEqual("DotNet/metric2", sentMetric2.MetricName.Name),
                () => Assert.AreEqual("scope2", sentMetric2.MetricName.Scope),
                () => Assert.AreEqual(1, sentMetric2.Data.Value0),
                () => Assert.AreEqual(7, sentMetric2.Data.Value1),
                () => Assert.AreEqual(5, sentMetric2.Data.Value2),
                () => Assert.AreEqual(7, sentMetric2.Data.Value3),
                () => Assert.AreEqual(7, sentMetric2.Data.Value4),
                () => Assert.AreEqual(49, sentMetric2.Data.Value5),

                () => Assert.AreEqual(MetricNames.SupportabilityMetricHarvestTransmit, sentMetric3.MetricName.Name),
                () => Assert.AreEqual(null, sentMetric3.MetricName.Scope),
                () => Assert.AreEqual(1, sentMetric3.Data.Value0),
                () => Assert.AreEqual(0, sentMetric3.Data.Value1),
                () => Assert.AreEqual(0, sentMetric3.Data.Value2),
                () => Assert.AreEqual(0, sentMetric3.Data.Value3),
                () => Assert.AreEqual(0, sentMetric3.Data.Value4),
                () => Assert.AreEqual(0, sentMetric3.Data.Value5)
                );
        }
        public void MergeUnscopedStats_PreDoneMetrics()
        {
            IMetricNameService mNameService = Mock.Create <IMetricNameService>();

            Mock.Arrange(() => mNameService.RenameMetric(Arg.IsAny <string>())).Returns <string>(name => "IAmRenamed");
            var metric1 = MetricWireModel.BuildMetric(_metricNameService, "name", null, MetricDataWireModel.BuildTimingData(TimeSpan.FromSeconds(3), TimeSpan.FromSeconds(2)));
            var engine  = new MetricStatsCollection();

            engine.MergeUnscopedStats(metric1);
            IEnumerable <MetricWireModel> stats = engine.ConvertToJsonForSending(mNameService);
            var count = 0;

            foreach (MetricWireModel current in stats)
            {
                count++;
                Assert.AreEqual("name", current.MetricName.Name);
                Assert.AreEqual(null, current.MetricName.Scope);
                Assert.AreEqual(1, current.Data.Value0);
                Assert.AreEqual(3, current.Data.Value1);
                Assert.AreEqual(2, current.Data.Value2);
            }
            Assert.AreEqual(1, count);
        }
        public void MergeScopedStats_DifferentScopes()
        {
            var metric1 = MetricWireModel.BuildMetric(_metricNameService, "DotNet/name", "scope", MetricDataWireModel.BuildTimingData(TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(1)));
            var metric2 = MetricWireModel.BuildMetric(_metricNameService, "DotNet/another", "scope", MetricDataWireModel.BuildTimingData(TimeSpan.FromSeconds(3), TimeSpan.FromSeconds(2)));
            var metric3 = MetricWireModel.BuildMetric(_metricNameService, "DotNet/name", "myotherscope", MetricDataWireModel.BuildTimingData(TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(4)));
            var metric4 = MetricWireModel.BuildMetric(_metricNameService, "DotNet/another", "myotherscope", MetricDataWireModel.BuildTimingData(TimeSpan.FromSeconds(7), TimeSpan.FromSeconds(6)));


            var engine = new MetricStatsCollection();
            MetricStatsDictionary <string, MetricDataWireModel> txStats1 = new MetricStatsDictionary <string, MetricDataWireModel>();

            txStats1.Merge(metric1.MetricName.Name, metric1.Data, MetricDataWireModel.BuildAggregateData);
            MetricStatsDictionary <string, MetricDataWireModel> txStats2 = new MetricStatsDictionary <string, MetricDataWireModel>();

            txStats2.Merge(metric2.MetricName.Name, metric2.Data, MetricDataWireModel.BuildAggregateData);
            MetricStatsDictionary <string, MetricDataWireModel> txStats3 = new MetricStatsDictionary <string, MetricDataWireModel>();

            txStats3.Merge(metric3.MetricName.Name, metric3.Data, MetricDataWireModel.BuildAggregateData);
            MetricStatsDictionary <string, MetricDataWireModel> txStats4 = new MetricStatsDictionary <string, MetricDataWireModel>();

            txStats4.Merge(metric4.MetricName.Name, metric4.Data, MetricDataWireModel.BuildAggregateData);

            engine.MergeScopedStats(metric2.MetricName.Scope, txStats1);
            engine.MergeScopedStats(metric2.MetricName.Scope, txStats2);
            engine.MergeScopedStats(metric3.MetricName.Scope, txStats3);
            engine.MergeScopedStats(metric4.MetricName.Scope, txStats4);

            IEnumerable <MetricWireModel> stats = engine.ConvertToJsonForSending(_metricNameService);
            var count = 0;

            foreach (MetricWireModel current in stats)
            {
                count++;
                if (current.MetricName.Name.Equals("DotNet/name"))
                {
                    if (current.MetricName.Scope.Equals("scope"))
                    {
                        Assert.AreEqual(1, current.Data.Value0);
                        Assert.AreEqual(2, current.Data.Value1);
                        Assert.AreEqual(1, current.Data.Value2);
                    }
                    else
                    {
                        Assert.AreEqual("myotherscope", current.MetricName.Scope);
                        Assert.AreEqual(1, current.Data.Value0);
                        Assert.AreEqual(5, current.Data.Value1);
                        Assert.AreEqual(4, current.Data.Value2);
                    }
                }
                else if (current.MetricName.Name.Equals("DotNet/another"))
                {
                    if (current.MetricName.Scope.Equals("scope"))
                    {
                        Assert.AreEqual(1, current.Data.Value0);
                        Assert.AreEqual(3, current.Data.Value1);
                        Assert.AreEqual(2, current.Data.Value2);
                    }
                    else
                    {
                        Assert.AreEqual("myotherscope", current.MetricName.Scope);
                        Assert.AreEqual(1, current.Data.Value0);
                        Assert.AreEqual(7, current.Data.Value1);
                        Assert.AreEqual(6, current.Data.Value2);
                    }
                }
                else
                {
                    Assert.Fail("Unexpected metric: " + current.MetricName.Name);
                }
            }
            Assert.AreEqual(4, count);
        }
        public void MergeScopedStats_TwoStatsSeparateEngines()
        {
            var metric1 = MetricWireModel.BuildMetric(_metricNameService, "name", "scope", MetricDataWireModel.BuildTimingData(TimeSpan.FromSeconds(3), TimeSpan.FromSeconds(2)));
            var engine  = new MetricStatsCollection();
            MetricStatsDictionary <string, MetricDataWireModel> txStats1 = new MetricStatsDictionary <string, MetricDataWireModel>();

            txStats1.Merge(metric1.MetricName.Name, metric1.Data, MetricDataWireModel.BuildAggregateData);
            MetricStatsDictionary <string, MetricDataWireModel> txStats2 = new MetricStatsDictionary <string, MetricDataWireModel>();

            txStats2.Merge(metric1.MetricName.Name, metric1.Data, MetricDataWireModel.BuildAggregateData);
            engine.MergeScopedStats(metric1.MetricName.Scope, txStats1);
            engine.MergeScopedStats(metric1.MetricName.Scope, txStats2);

            IEnumerable <MetricWireModel> stats = engine.ConvertToJsonForSending(_metricNameService);
            var count = 0;

            foreach (MetricWireModel current in stats)
            {
                count++;
                Assert.AreEqual("name", current.MetricName.Name);
                Assert.AreEqual("scope", current.MetricName.Scope);
                Assert.AreEqual(2, current.Data.Value0);
                Assert.AreEqual(6, current.Data.Value1);
                Assert.AreEqual(4, current.Data.Value2);
            }
            Assert.AreEqual(1, count);
        }
        public void MergeScopedStats_TwoDifferentSame_StringData()
        {
            var metric1 = MetricWireModel.BuildMetric(_metricNameService, "DotNet/name", "myscope", MetricDataWireModel.BuildTimingData(TimeSpan.FromSeconds(7), TimeSpan.FromSeconds(5)));
            var metric2 = MetricWireModel.BuildMetric(_metricNameService, "DotNet/another", "myscope", MetricDataWireModel.BuildTimingData(TimeSpan.FromSeconds(3), TimeSpan.FromSeconds(2)));

            var engine = new MetricStatsCollection();

            engine.MergeScopedStats(metric1.MetricName.Scope, metric1.MetricName.Name, metric1.Data);
            engine.MergeScopedStats(metric2.MetricName.Scope, metric2.MetricName.Name, metric2.Data);

            IEnumerable <MetricWireModel> stats = engine.ConvertToJsonForSending(_metricNameService);
            var count = 0;

            foreach (MetricWireModel current in stats)
            {
                count++;
                if (current.MetricName.Name.Equals("DotNet/name"))
                {
                    Assert.AreEqual(1, current.Data.Value0);
                    Assert.AreEqual(7, current.Data.Value1);
                    Assert.AreEqual(5, current.Data.Value2);
                }
                else if (current.MetricName.Name.Equals("DotNet/another"))
                {
                    Assert.AreEqual(1, current.Data.Value0);
                    Assert.AreEqual(3, current.Data.Value1);
                    Assert.AreEqual(2, current.Data.Value2);
                }
                else
                {
                    Assert.Fail("Unexpected metric: " + current.MetricName.Name);
                }
                Assert.AreEqual(metric1.MetricName.Scope, current.MetricName.Scope);
            }
            Assert.AreEqual(2, count);
        }
        public void MergeScopedStats_OneStat_StringData()
        {
            var metric1 = MetricWireModel.BuildMetric(_metricNameService, "DotNet/name", "myScope", MetricDataWireModel.BuildTimingData(TimeSpan.FromSeconds(3), TimeSpan.FromSeconds(2)));
            var engine  = new MetricStatsCollection();

            engine.MergeScopedStats(metric1.MetricName.Scope, metric1.MetricName.Name, metric1.Data);
            IEnumerable <MetricWireModel> stats = engine.ConvertToJsonForSending(_metricNameService);
            var count = 0;

            foreach (MetricWireModel current in stats)
            {
                count++;
                Assert.AreEqual("DotNet/name", current.MetricName.Name);
                Assert.AreEqual("myScope", current.MetricName.Scope);
                Assert.AreEqual(1, current.Data.Value0);
                Assert.AreEqual(3, current.Data.Value1);
                Assert.AreEqual(2, current.Data.Value2);
            }
            Assert.AreEqual(1, count);
        }
        public void MergeUnscopedNotCreated_TwoStatsSame()
        {
            var metric1 = MetricWireModel.BuildMetric(_metricNameService, "name", null, MetricDataWireModel.BuildTimingData(TimeSpan.FromSeconds(3), TimeSpan.FromSeconds(2)));
            var engine  = new MetricStatsCollection();

            engine.MergeUnscopedStats(metric1.MetricName.Name, metric1.Data);
            engine.MergeUnscopedStats(metric1.MetricName.Name, metric1.Data);
            IEnumerable <MetricWireModel> stats = engine.ConvertToJsonForSending(_metricNameService);
            var count = 0;

            foreach (MetricWireModel current in stats)
            {
                count++;
                Assert.AreEqual("name", current.MetricName.Name);
                Assert.AreEqual(null, current.MetricName.Scope);
                Assert.AreEqual(2, current.Data.Value0);
                Assert.AreEqual(6, current.Data.Value1);
                Assert.AreEqual(4, current.Data.Value2);
            }
            Assert.AreEqual(1, count);

            var metric2 = MetricWireModel.BuildMetric(_metricNameService, "name", null, MetricDataWireModel.BuildTimingData(TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(4)));

            engine.MergeUnscopedStats(metric2.MetricName.Name, metric2.Data);
            engine.MergeUnscopedStats(metric2.MetricName.Name, metric2.Data);
            stats = engine.ConvertToJsonForSending(_metricNameService);

            count = 0;

            foreach (MetricWireModel current in stats)
            {
                count++;
                Assert.AreEqual("name", current.MetricName.Name);
                Assert.AreEqual(null, current.MetricName.Scope);
                Assert.AreEqual(4, current.Data.Value0);
                Assert.AreEqual(16, current.Data.Value1);
                Assert.AreEqual(12, current.Data.Value2);
            }
            Assert.AreEqual(1, count);
        }