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); }
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); }
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_VerifyRenaming() { IMetricNameService mNameService = Mock.Create <IMetricNameService>(); Mock.Arrange(() => mNameService.RenameMetric(Arg.IsAny <string>())).Returns <string>(name => "IAmRenamed"); var metric1 = MetricWireModel.BuildMetric(_metricNameService, "name", "myscope", MetricDataWireModel.BuildTimingData(TimeSpan.FromSeconds(3), TimeSpan.FromSeconds(2))); var engine = new MetricStatsCollection(); var scopedStats = new MetricStatsDictionary <string, MetricDataWireModel>(); scopedStats[metric1.MetricName.Name] = metric1.Data; engine.MergeScopedStats(metric1.MetricName.Scope, scopedStats); IEnumerable <MetricWireModel> stats = engine.ConvertToJsonForSending(mNameService); var count = 0; foreach (MetricWireModel current in stats) { count++; Assert.AreEqual("IAmRenamed", 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 MetricStatsDictionary <string, MetricDataWireModel> GetScopedForTesting() { var toReturn = new MetricStatsDictionary <string, MetricDataWireModel>(); foreach (var current in scopedStats) { toReturn[current.Key.ToString()] = current.Value; } return(toReturn); }
public void MergeScopedStats(string scope, IEnumerable <KeyValuePair <string, MetricDataWireModel> > metrics) { MetricStatsDictionary <string, MetricDataWireModel> alreadyScoped; if (_scopedStats.TryGetValue(scope, out alreadyScoped)) { alreadyScoped.Merge(metrics, _mergeFunction); } else { alreadyScoped = new MetricStatsDictionary <string, MetricDataWireModel>(metrics); _scopedStats[scope] = alreadyScoped; } }
public void MergeScopedStats(string scope, string name, MetricDataWireModel metric) { MetricStatsDictionary <string, MetricDataWireModel> alreadyScoped; if (_scopedStats.TryGetValue(scope, out alreadyScoped)) { alreadyScoped.Merge(name, metric, _mergeFunction); } else { alreadyScoped = new MetricStatsDictionary <string, MetricDataWireModel>(); alreadyScoped.Merge(name, metric, _mergeFunction); _scopedStats[scope] = alreadyScoped; } }
public void MergeScopedStats_TwoDifferentSame() { 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 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); engine.MergeScopedStats(metric2.MetricName.Scope, txStats1); engine.MergeScopedStats(metric2.MetricName.Scope, txStats2); 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(2, current.Data.Value1); Assert.AreEqual(1, 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("scope", current.MetricName.Scope); } Assert.AreEqual(2, count); }