public void GetReadings_EnumeratesAllTaggedMetrics() { var source = new TestMetricSource(); var counter = source.AddCounter("counter", "unit", "desc", new MetricTag <string>("tag")); counter.Increment("test"); counter.Increment("test_2"); counter.Increment("test_2"); counter.Increment("test_3"); counter.Increment("test_3"); counter.Increment("test_3"); // HACK: need to order by the reported value to ensure we get consistent order var readings = source.GetReadings(DateTime.UtcNow).OrderBy(x => x.Value); Assert.Collection( readings, reading => { Assert.Equal("counter", reading.Name); Assert.Equal(1, reading.Value); Assert.True(reading.Tags.TryGetValue("tag", out var value) && value == "test"); }, reading => { Assert.Equal("counter", reading.Name); Assert.Equal(2, reading.Value); Assert.True(reading.Tags.TryGetValue("tag", out var value) && value == "test_2"); }, reading => { Assert.Equal("counter", reading.Name); Assert.Equal(3, reading.Value); Assert.True(reading.Tags.TryGetValue("tag", out var value) && value == "test_3"); }); }
public void GetReadings_EnumeratesAllUntaggedMetrics() { var source = new TestMetricSource(); var counter = source.AddCounter("counter", "unit", "desc"); var gauge = source.AddSamplingGauge("gauge", "unit", "desc"); counter.Increment(); counter.Increment(); gauge.Record(42.123d); var readings = source.GetReadings(DateTime.UtcNow); Assert.Collection( readings, reading => { Assert.Equal("counter", reading.Name); Assert.Equal(2, reading.Value); }, reading => { Assert.Equal("gauge", reading.Name); Assert.Equal(42.123d, reading.Value); }); }