Esempio n. 1
0
        public void MetricNameIsAccentSensitive()
        {
            using (var manager = new MetricManager())
            {
                Metric metric = manager.CreateMetric("My metric");
                Metric other  = manager.CreateMetric("My métric");

                Assert.False(metric.Equals(other));
            }
        }
        public void MetricsAreEqualIfDimensionsSetToNothingImplicitlyAndExplicitly()
        {
            using (var manager = new MetricManager())
            {
                Metric metric = manager.CreateMetric("My metric", null);
                Metric other  = manager.CreateMetric("My metric");

                Assert.IsTrue(metric.Equals(other));
            }
        }
Esempio n. 3
0
        public void MetricsAreEqualForTheSameMetricNameWithoutDimensions()
        {
            using (var manager = new MetricManager())
            {
                Metric metric = manager.CreateMetric("My metric");
                Metric other  = manager.CreateMetric("My metric");

                Assert.True(metric.Equals(other));
            }
        }
Esempio n. 4
0
        public void MetricsAreEqualIfDimensionsSetToNothingImplicitlyAndExplicitlyAsEmptySet()
        {
            using (var manager = new MetricManager())
            {
                Metric metric = manager.CreateMetric("My metric", new Dictionary <string, string>());
                Metric other  = manager.CreateMetric("My metric");

                Assert.True(metric.Equals(other));
            }
        }
Esempio n. 5
0
        public void MetricInvokesMetricProcessorsForEachValueTracked()
        {
            // Arrange
            var sentTelemetry = new List <ITelemetry>();
            var sentSamples   = new List <MetricSample>();

            var client = this.InitializeTelemetryClient(sentTelemetry, sentSamples);

            var dimensions = new Dictionary <string, string> {
                { "Dim1", "Value1" },
                { "Dim2", "Value2" }
            };

            using (MetricManager manager = new MetricManager(client))
            {
                Metric metric = manager.CreateMetric("Test Metric", dimensions);

                // Act
                metric.Track(42);
            }

            // Assert
            var sample = (MetricSample)sentSamples.Single();

            Assert.Equal("Test Metric", sample.Name);

            Assert.Equal(42, sample.Value);

            Assert.Equal("Value1", sample.Dimensions["Dim1"]);
            Assert.Equal("Value2", sample.Dimensions["Dim2"]);
        }
        public void CanCreateMetricWithASetOfDimensions()
        {
            // Arrange
            var sentTelemetry = new List <ITelemetry>();

            var client = this.InitializeTelemetryClient(sentTelemetry);

            var dimensions = new Dictionary <string, string> {
                { "Dim1", "Value1" },
                { "Dim2", "Value2" }
            };

            using (MetricManager manager = new MetricManager(client))
            {
                // Act
                Metric metric = manager.CreateMetric("Test Metric", dimensions);
                metric.Track(42);
            }

            // Assert
            var aggregatedMetric = (MetricTelemetry)sentTelemetry.Single();

            Assert.Equal("Test Metric", aggregatedMetric.Name);

            Assert.Equal(1, aggregatedMetric.Count);
            Assert.Equal(42, aggregatedMetric.Sum);

            // note: interval duration property is auto-generated
            Assert.Equal(3, aggregatedMetric.Properties.Count);

            Assert.Equal("Value1", aggregatedMetric.Properties["Dim1"]);
            Assert.Equal("Value2", aggregatedMetric.Properties["Dim2"]);
        }
Esempio n. 7
0
        public void CanCreateMetricHavingNoDimensions()
        {
            // Arrange
            var sentTelemetry = new List <ITelemetry>();

            var client = this.InitializeTelemetryClient(sentTelemetry);

            using (MetricManager manager = new MetricManager(client))
            {
                // Act
                Metric metric = manager.CreateMetric("Test Metric");
                metric.Track(42);
            }

            // Assert (single metric aggregation exists in the output)
            var aggregatedMetric = (MetricTelemetry)sentTelemetry.Single();

            Assert.AreEqual("Test Metric", aggregatedMetric.Name);

            Assert.AreEqual(1, aggregatedMetric.Count);
            Assert.AreEqual(42, aggregatedMetric.Sum);

            // note: interval duration property is auto-generated
            Assert.AreEqual(1, aggregatedMetric.Properties.Count);
        }
        public void AggregatedMetricTelemetryIntervalDurationPropertyIsPositiveInteger()
        {
            // Arrange
            var sentTelemetry = new List <ITelemetry>();

            var client = this.InitializeTelemetryClient(sentTelemetry);

            using (MetricManager manager = new MetricManager(client))
            {
                Metric metric = manager.CreateMetric("Test Metric");

                // Act
                metric.Track(42);
            }

            // Assert
            var aggregatedMetric = (MetricTelemetry)sentTelemetry.Single();

            Assert.Equal("Test Metric", aggregatedMetric.Name);

            Assert.Equal(1, aggregatedMetric.Count);
            Assert.Equal(1, aggregatedMetric.Properties.Count);

            Assert.True(aggregatedMetric.Properties.ContainsKey("_MS.AggregationIntervalMs"));
            Assert.True(long.Parse(aggregatedMetric.Properties["_MS.AggregationIntervalMs"]) > 0);
        }
        public void CanCreateMetricExplicitlySettingDimensionsToNull()
        {
            // Arrange
            var sentTelemetry = new List <ITelemetry>();

            var client = this.InitializeTelemetryClient(sentTelemetry);

            using (MetricManager manager = new MetricManager(client))
            {
                // Act
                Metric metric = manager.CreateMetric("Test Metric", null);
                metric.Track(42);
            }

            // Assert
            var aggregatedMetric = (MetricTelemetry)sentTelemetry.Single();

            Assert.Equal("Test Metric", aggregatedMetric.Name);

            Assert.Equal(1, aggregatedMetric.Count);
            Assert.Equal(42, aggregatedMetric.Sum);

            // note: interval duration property is auto-generated
            Assert.Equal(1, aggregatedMetric.Properties.Count);
        }
Esempio n. 10
0
        public void MetricAggregatorCalculatesSumCorrectly()
        {
            // Arrange
            double[] testValues = { 4.45, 8, 29.21, 78.43, 0 };

            var sentTelemetry = new List <ITelemetry>();
            var sentSamples   = new List <MetricSample>();

            var client = this.InitializeTelemetryClient(sentTelemetry, sentSamples);

            using (MetricManager manager = new MetricManager(client))
            {
                Metric metric = manager.CreateMetric("Test Metric");

                // Act
                for (int i = 0; i < testValues.Length; i++)
                {
                    metric.Track(testValues[i]);
                }
            }

            // Assert
            double sentSampleSum = sentTelemetry.Sum(
                (telemetry) => {
                var metric = telemetry as MetricTelemetry;
                return(metric == null ? 0 : metric.Sum);
            });

            Assert.Equal(testValues.Sum(), sentSampleSum);
        }
Esempio n. 11
0
        public void MetricEqualsItself()
        {
            using (var manager = new MetricManager())
            {
                Metric metric = manager.CreateMetric("My metric");

                Assert.True(metric.Equals(metric));
            }
        }
        public void EqualMetricsAreCombinedIntoSignleAggregatedStatsStructure()
        {
            // Arrange
            var sentTelemetry = new List <ITelemetry>();

            var client = this.InitializeTelemetryClient(sentTelemetry);

            Metric metric1 = null;
            Metric metric2 = null;

            using (MetricManager manager = new MetricManager(client))
            {
                // note: on first go aggregators may be different because manager may
                // snapshot after first got created but before the second
                for (int i = 0; i < 2; i++)
                {
                    metric1 = manager.CreateMetric("Test Metric");
                    metric2 = manager.CreateMetric("Test Metric");

                    // Act
                    metric1.Track(10);
                    metric2.Track(5);

                    manager.Flush();

                    if (sentTelemetry.Count == 1)
                    {
                        break;
                    }
                    else
                    {
                        sentTelemetry.Clear();
                    }
                }
            }

            // Assert
            Assert.Equal(1, sentTelemetry.Count);

            var aggregatedMetric = (MetricTelemetry)sentTelemetry.Single();

            Assert.Equal(2, aggregatedMetric.Count);
            Assert.Equal(15, aggregatedMetric.Sum);
        }
Esempio n. 13
0
        public void DimensionValuesAreAccentSensitive()
        {
            using (var manager = new MetricManager())
            {
                var dimensionSet1 = new Dictionary <string, string>()
                {
                    { "Dim1", "Value1" }
                };
                var dimensionSet2 = new Dictionary <string, string>()
                {
                    { "Dim1", "Válue1" }
                };

                Metric metric = manager.CreateMetric("My metric", dimensionSet1);
                Metric other  = manager.CreateMetric("My metric", dimensionSet2);

                Assert.False(metric.Equals(other));
            }
        }
Esempio n. 14
0
        public void MetricNeverEqualsNull()
        {
            using (var manager = new MetricManager())
            {
                Metric metric = manager.CreateMetric("My metric");
                object other  = null;

                Assert.False(metric.Equals(other));
            }
        }
Esempio n. 15
0
        public void MetricNotEqualsOtherObject()
        {
            using (var manager = new MetricManager())
            {
                Metric metric = manager.CreateMetric("My metric");
                var    other  = new object();

                Assert.False(metric.Equals(other));
            }
        }
Esempio n. 16
0
        public void DimensionsAreOrderInsensitive()
        {
            using (var manager = new MetricManager())
            {
                var dimensionSet1 = new Dictionary <string, string>()
                {
                    { "Dim1", "Value1" },
                    { "Dim2", "Value2" },
                };

                var dimensionSet2 = new Dictionary <string, string>()
                {
                    { "Dim2", "Value2" },
                    { "Dim1", "Value1" },
                };

                Metric metric = manager.CreateMetric("My metric", dimensionSet1);
                Metric other  = manager.CreateMetric("My metric", dimensionSet2);

                Assert.True(metric.Equals(other));
            }
        }
Esempio n. 17
0
        public void MetricAggregatorCalculatesStandardDeviationCorrectly()
        {
            // Arrange
            double[] testValues = { 1, 2, 3, 4, 5 };

            var sentTelemetry = new List <ITelemetry>();
            var sentSamples   = new List <MetricSample>();

            var client = this.InitializeTelemetryClient(sentTelemetry, sentSamples);

            using (MetricManager manager = new MetricManager(client))
            {
                Metric metric = manager.CreateMetric("Test Metric");

                // Act
                for (int i = 0; i < testValues.Length; i++)
                {
                    metric.Track(testValues[i]);
                }
            }

            // Assert
            double sumOfSquares = sentTelemetry.Sum(
                (telemetry) => {
                var metric = telemetry as MetricTelemetry;
                return
                (metric == null
                        ? 0
                        : Math.Pow(metric.StandardDeviation.Value, 2) * metric.Count.Value + Math.Pow(metric.Sum, 2) / metric.Count.Value);
            });

            int count = sentTelemetry.Sum(
                (telemetry) => {
                var metric = telemetry as MetricTelemetry;
                return(metric == null ? 0 : metric.Count.Value);
            });

            double sum = sentTelemetry.Sum(
                (telemetry) => {
                var metric = telemetry as MetricTelemetry;
                return(metric == null ? 0 : metric.Sum);
            });

            double stddev = Math.Sqrt(sumOfSquares / count - Math.Pow(sum / count, 2));

            Assert.Equal(testValues.StdDev(), stddev);
        }
        public void DisposingManagerCreatesAggregatedMetricTelemetry()
        {
            // Arrange
            var sentTelemetry = new List <ITelemetry>();

            var client = this.InitializeTelemetryClient(sentTelemetry);

            using (MetricManager manager = new MetricManager(client))
            {
                Metric metric = manager.CreateMetric("Test Metric");

                metric.Track(42);

                // Act
                manager.Dispose();

                // Assert
                Assert.Equal(1, sentTelemetry.Count);

                var aggregatedMetric = (MetricTelemetry)sentTelemetry.Single();
                Assert.NotNull(aggregatedMetric);
            }
        }