public void TestBasicFunctionality() { MetricAggregator aggregator = new MetricAggregator(new AggregationTemplate("test_metric", "key1", new Averager())); // metrics with 1 tag, key1, that has key values of val[1-10]. The key values don't matter for this test and are ignored by the aggregator. Only the metric value is averaged. IEnumerable <Metric> metrics = Enumerable.Range(1, 10).Select(i => new Metric(this.now, "test_metric", i, new Dictionary <string, string> { { "key1", $"val{i}" } })); Metric[] result = aggregator.AggregateMetrics(metrics).ToArray(); Assert.Equal(5.5, result.Single().Value); // should be sum of 1-10 }
public void TestKeepsNonAggregateTagsSeperate() { MetricAggregator aggregator = new MetricAggregator(new AggregationTemplate("test_metric", "key1", new Summer())); // metrics with 2 tags, key1, that has key values of val[1-10], and key2, which has key values val[0-1]. The values are summed by shared key2, and key1's value is ignored. IEnumerable <Metric> metrics = Enumerable.Range(1, 10).Select(i => new Metric(this.now, "test_metric", i, new Dictionary <string, string> { { "key1", $"val{i}" }, { "key2", $"val{i % 2}" } })); Metric[] results = aggregator.AggregateMetrics(metrics).ToArray(); Assert.Equal(2, results.Length); Assert.Equal(2 + 4 + 6 + 8 + 10, results.Where(m => m.Tags.Contains(new KeyValuePair <string, string>("key2", "val0"))).Single().Value); Assert.Equal(1 + 3 + 5 + 7 + 9, results.Where(m => m.Tags.Contains(new KeyValuePair <string, string>("key2", "val1"))).Single().Value); }
public void TestMultipleMetricsDifferentAggregator() { MetricAggregator aggregator = new MetricAggregator( new AggregationTemplate("test_metric0", "key1", new Summer()), new AggregationTemplate("test_metric1", "key1", new Multiplier())); // 2 metrics with 1 tag, key1, that has key values of val[1-10]. The key values don't matter for this test and are ignored by the aggregator. Only the metric values are used. Even values are test_metric0 and will be summed, odd values are test_metric1 and will be multiplied. IEnumerable <Metric> metrics = Enumerable.Range(1, 10).Select(i => new Metric(this.now, $"test_metric{i % 2}", i, new Dictionary <string, string> { { "key1", $"val{i}" } })); Metric[] results = aggregator.AggregateMetrics(metrics).ToArray(); Assert.Equal(2, results.Length); Assert.Equal(2 + 4 + 6 + 8 + 10, results.Where(m => m.Name == "test_metric0").Single().Value); Assert.Equal(1 * 3 * 5 * 7 * 9, results.Where(m => m.Name == "test_metric1").Single().Value); }