Ejemplo n.º 1
0
        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");
            });
        }
Ejemplo n.º 2
0
        public async Task MetricSourcesAreAttachedAndDetached()
        {
            var metricSource = new TestMetricSource();
            var collector    = new MetricsCollector(
                new MetricsCollectorOptions
            {
                Endpoints = new []
                {
                    new MetricEndpoint("Local", new LocalMetricHandler()),
                },
                Sources          = new[] { metricSource },
                RetryInterval    = TimeSpan.Zero,
                SnapshotInterval = TimeSpan.FromMilliseconds(20),
            }
                );

            collector.Start();

            try
            {
                // make sure initialization happened
                await Task.WhenAny(metricSource.AttachTask, Task.Delay(1000));

                Assert.True(metricSource.AttachTask.IsCompleted, "Metric source was not attached");

                // make sure we got snapshotted
                await Task.WhenAny(metricSource.SnapshotTask, Task.Delay(30000));

                Assert.True(metricSource.SnapshotTask.IsCompleted, "Metric source was not snapshotted");
            }
            finally
            {
                collector.Stop();

                // make sure we got detached
                await Task.WhenAny(metricSource.DetachTask, Task.Delay(1000));

                Assert.True(metricSource.DetachTask.IsCompleted, "Metric source was not detached");
            }
        }
Ejemplo n.º 3
0
        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);
            });
        }
Ejemplo n.º 4
0
 public void StopWithoutStart_Throws()
 {
     var source    = new TestMetricSource();
     var handler   = new TestMetricHandler((handler, type, buffer) => default);