public void Properties()
        {
            var manager = new MetricManager(new MemoryMetricTelemetryPipeline());
            IMetricSeriesConfiguration config = new MetricSeriesConfigurationForMeasurement(restrictToUInt32Values: false);
            MetricSeries series = manager.CreateNewSeries("Foo Bar", config);

            Assert.AreEqual("Foo Bar", series.MetricId);

            Assert.AreEqual(config, series.GetConfiguration());
            Assert.AreSame(config, series.GetConfiguration());

            Util.CompleteDefaultAggregationCycle(manager);
        }
Пример #2
0
        public void CreateAggregateUnsafe()
        {
            var aggregationManager = new MetricAggregationManager();
            var seriesConfig       = new MetricSeriesConfigurationForMeasurement(restrictToUInt32Values: true);

            IEnumerable <KeyValuePair <string, string> > setDimensionNamesValues = new KeyValuePair <string, string>[] { new KeyValuePair <string, string>("Dim 1", "DV1"),
                                                                                                                         new KeyValuePair <string, string>("Dim 2", "DV2"),
                                                                                                                         new KeyValuePair <string, string>("Dim 3", "DV3"),
                                                                                                                         new KeyValuePair <string, string>("Dim 2", "DV2a") };

            IEnumerable <KeyValuePair <string, string> > expectedDimensionNamesValues = new KeyValuePair <string, string>[] { new KeyValuePair <string, string>("Dim 1", "DV1"),
                                                                                                                              new KeyValuePair <string, string>("Dim 2", "DV2a"),
                                                                                                                              new KeyValuePair <string, string>("Dim 3", "DV3") };

            var metric = new MetricSeries(
                aggregationManager,
                new MetricIdentifier(String.Empty, "Cows Sold", expectedDimensionNamesValues.Select(nv => nv.Key).ToArray()),
                setDimensionNamesValues,
                seriesConfig);

            var aggregator = new MeasurementAggregator(
                (MetricSeriesConfigurationForMeasurement)metric.GetConfiguration(),
                metric,
                CycleKind.Custom);

            CommonSimpleDataSeriesAggregatorTests.CreateAggregateUnsafe(aggregator, metric, expectedDimensionNamesValues);
        }
        public void CreateNewSeries()
        {
            var manager = new MetricManager(new MemoryMetricTelemetryPipeline());

            IMetricSeriesConfiguration config = new SimpleMetricSeriesConfiguration(restrictToUInt32Values: false);

            Assert.ThrowsException <ArgumentNullException>(() => manager.CreateNewSeries(null, config));
            Assert.ThrowsException <ArgumentNullException>(() => manager.CreateNewSeries("Foo Bar", null));

            MetricSeries series = manager.CreateNewSeries("Foo Bar", config);

            Assert.IsNotNull(series);

            Assert.AreEqual(config, series.GetConfiguration());
            Assert.AreSame(config, series.GetConfiguration());

            Assert.AreEqual("Foo Bar", series.MetricId);

            Util.CompleteDefaultAggregationCycle(manager);
        }
Пример #4
0
        public void CreateAggregateUnsafe()
        {
            var aggregationManager = new MetricAggregationManager();
            var seriesConfig       = new MetricSeriesConfigurationForNaiveDistinctCount(usePersistentAggregation: false);
            var metric             = new MetricSeries(
                aggregationManager,
                new MetricIdentifier(null, "Distinct Cows Sold", "Dim 2", "Dim 3", "Dim 1"),
                new KeyValuePair <string, string>[] { new KeyValuePair <string, string>("Dim 1", "DV1"),
                                                      new KeyValuePair <string, string>("Dim 2", "DV2"),
                                                      new KeyValuePair <string, string>("Dim 3", "DV3"),
                                                      new KeyValuePair <string, string>("Dim 2", "DV2a") },
                seriesConfig);

            var aggregator = new NaiveDistinctCountMetricSeriesAggregator(
                (MetricSeriesConfigurationForNaiveDistinctCount)metric.GetConfiguration(),
                metric,
                CycleKind.Custom);

            var startTS = new DateTimeOffset(2017, 9, 25, 17, 0, 0, TimeSpan.FromHours(-8));
            var endTS   = new DateTimeOffset(2017, 9, 25, 17, 1, 0, TimeSpan.FromHours(-8));

            aggregator.Reset(startTS, valueFilter: null);

            aggregator.TrackValue("Foo");
            aggregator.TrackValue("Bar");
            aggregator.TrackValue("Foo");

            MetricAggregate aggregate = aggregator.CreateAggregateUnsafe(endTS);

            Assert.IsNotNull(aggregate);

            Assert.AreEqual("Distinct Cows Sold", aggregate.MetricId, "aggregate.MetricId mismatch");
            Assert.AreEqual(3, aggregate.Data["TotalCount"], "aggregate.Data[TotalCount] mismatch");
            Assert.AreEqual(2, aggregate.Data["DistinctCount"], "aggregate.Data[DistinctCount] mismatch");

            Assert.AreEqual(startTS, aggregate.AggregationPeriodStart, "metricAggregate.Timestamp mismatch");
            Assert.AreEqual(
                (endTS - startTS).TotalMilliseconds,
                aggregate.AggregationPeriodDuration.TotalMilliseconds,
                "aggregate.AggregationPeriodDuration mismatch");

            Assert.AreEqual(3, aggregate.Dimensions.Count);

            Assert.IsTrue(aggregate.Dimensions.ContainsKey("Dim 1"));
            Assert.AreEqual("DV1", aggregate.Dimensions["Dim 1"]);

            Assert.IsTrue(aggregate.Dimensions.ContainsKey("Dim 2"));
            Assert.AreEqual("DV2a", aggregate.Dimensions["Dim 2"]);

            Assert.IsTrue(aggregate.Dimensions.ContainsKey("Dim 3"));
            Assert.AreEqual("DV3", aggregate.Dimensions["Dim 3"]);
        }
Пример #5
0
        public void CompleteAggregation()
        {
            var aggregationManager = new MetricAggregationManager();

            var mesurementConfig  = new MetricSeriesConfigurationForMeasurement(restrictToUInt32Values: true);
            var measurementMetric = new MetricSeries(aggregationManager, new MetricIdentifier("Cows Sold"), null, mesurementConfig);

            var measurementAggregator = new MeasurementAggregator(
                (MetricSeriesConfigurationForMeasurement)measurementMetric.GetConfiguration(),
                measurementMetric,
                CycleKind.Custom);

            CommonSimpleDataSeriesAggregatorTests.CompleteAggregation_NonpersistentAggregator(measurementAggregator);
        }
Пример #6
0
        public void GetDataSeries()
        {
            var aggregationManager = new MetricAggregationManager();
            var seriesConfig       = new MetricSeriesConfigurationForMeasurement(restrictToUInt32Values: true);
            var metric             = new MetricSeries(aggregationManager, new MetricIdentifier("Cows Sold"), null, seriesConfig);

            var aggregatorForConcreteSeries = new MeasurementAggregator(
                (MetricSeriesConfigurationForMeasurement)metric.GetConfiguration(),
                dataSeries: metric,
                aggregationCycleKind: CycleKind.Custom);

            var aggregatorForNullSeries = new MeasurementAggregator(
                new MetricSeriesConfigurationForMeasurement(restrictToUInt32Values: true),
                dataSeries: null,
                aggregationCycleKind: CycleKind.Custom);

            CommonSimpleDataSeriesAggregatorTests.GetDataSeries(aggregatorForConcreteSeries, aggregatorForNullSeries, metric);
        }
Пример #7
0
        public void GetDataSeries()
        {
            var aggregationManager = new MetricAggregationManager();
            var seriesConfig       = new MetricSeriesConfigurationForNaiveDistinctCount(usePersistentAggregation: false);
            var metric             = new MetricSeries(aggregationManager, new MetricIdentifier("Cows Sold"), null, seriesConfig);

            var aggregatorForConcreteSeries = new NaiveDistinctCountMetricSeriesAggregator(
                (MetricSeriesConfigurationForNaiveDistinctCount)metric.GetConfiguration(),
                dataSeries: metric,
                aggregationCycleKind: CycleKind.Custom);

            var aggregatorForNullSeries = new NaiveDistinctCountMetricSeriesAggregator(
                new MetricSeriesConfigurationForNaiveDistinctCount(usePersistentAggregation: false),
                dataSeries: null,
                aggregationCycleKind: CycleKind.Custom);

            Assert.IsNotNull(aggregatorForConcreteSeries.DataSeries);
            Assert.AreSame(metric, aggregatorForConcreteSeries.DataSeries);

            Assert.IsNull(aggregatorForNullSeries.DataSeries);
        }
        public void CompleteAggregation()
        {
            var aggregationManager = new MetricAggregationManager();

            var mesurementConfig  = new SimpleMetricSeriesConfiguration(restrictToUInt32Values: false);
            var measurementMetric = new MetricSeries(aggregationManager, "Cows Sold", null, mesurementConfig);

            var measurementAggregator = new MeasurementAggregator(
                (SimpleMetricSeriesConfiguration)measurementMetric.GetConfiguration(),
                measurementMetric,
                CycleKind.Custom);

            var accumulatorConfig = new AccumulatorMetricSeriesConfiguration(restrictToUInt32Values: false);
            var accumulatorMetric = new MetricSeries(aggregationManager, "Cows Sold", null, accumulatorConfig);

            var accumulatorAggregator = new AccumulatorAggregator(
                (AccumulatorMetricSeriesConfiguration)accumulatorMetric.GetConfiguration(),
                accumulatorMetric,
                CycleKind.Custom);

            CommonSimpleDataSeriesAggregatorTests.CompleteAggregation_NonpersistentAggregator(measurementAggregator);
            CommonSimpleDataSeriesAggregatorTests.CompleteAggregation_PersistentAggregator(accumulatorAggregator);
        }
        public void CreateAggregateUnsafe()
        {
            var aggregationManager = new MetricAggregationManager();
            var seriesConfig       = new SimpleMetricSeriesConfiguration(restrictToUInt32Values: false);

            IEnumerable <KeyValuePair <string, string> > setDimensionNamesValues = new KeyValuePair <string, string>[] { new KeyValuePair <string, string>("Dim 1", "DV1"),
                                                                                                                         new KeyValuePair <string, string>("Dim 2", "DV2"),
                                                                                                                         new KeyValuePair <string, string>("Dim 3", "DV3"),
                                                                                                                         new KeyValuePair <string, string>("Dim 2", "DV2a") };

            IEnumerable <KeyValuePair <string, string> > expectedDimensionNamesValues = new KeyValuePair <string, string>[] { new KeyValuePair <string, string>("Dim 1", "DV1"),
                                                                                                                              new KeyValuePair <string, string>("Dim 2", "DV2a"),
                                                                                                                              new KeyValuePair <string, string>("Dim 3", "DV3") };

            var metric = new MetricSeries(aggregationManager, "Cows Sold", setDimensionNamesValues, seriesConfig);

            var aggregator = new MeasurementAggregator(
                (SimpleMetricSeriesConfiguration)metric.GetConfiguration(),
                metric,
                CycleKind.Custom);

            CommonSimpleDataSeriesAggregatorTests.CreateAggregateUnsafe(aggregator, metric, expectedDimensionNamesValues);
        }
        public void CompleteAggregation()
        {
            var aggregationManager = new MetricAggregationManager();

            var mesurementConfig  = new MetricSeriesConfigurationForMeasurement(restrictToUInt32Values: false);
            var measurementMetric = new MetricSeries(aggregationManager, new MetricIdentifier("Animal Metrics", "Cows Sold"), null, mesurementConfig);

            var measurementAggregator = new MeasurementAggregator(
                (MetricSeriesConfigurationForMeasurement)measurementMetric.GetConfiguration(),
                measurementMetric,
                CycleKind.Custom);

            var accumulatorConfig = new MetricSeriesConfigurationForTestingAccumulatorBehavior();
            var accumulatorMetric = new MetricSeries(aggregationManager, new MetricIdentifier("Animal Metrics", "Cows Sold"), null, accumulatorConfig);

            var accumulatorAggregator = new MetricSeriesConfigurationForTestingAccumulatorBehavior.Aggregator(
                (MetricSeriesConfigurationForTestingAccumulatorBehavior)accumulatorMetric.GetConfiguration(),
                accumulatorMetric,
                CycleKind.Custom);

            CommonSimpleDataSeriesAggregatorTests.CompleteAggregation_NonpersistentAggregator(measurementAggregator);
            CommonSimpleDataSeriesAggregatorTests.CompleteAggregation_PersistentAggregator(accumulatorAggregator);
        }
Пример #11
0
        public void CompleteAggregation()
        {
            var aggregationManager = new MetricAggregationManager();

            var nonPersistentConfig = new MetricSeriesConfigurationForNaiveDistinctCount(usePersistentAggregation: false);
            var nonPersistentMetric = new MetricSeries(aggregationManager, new MetricIdentifier("Unique Cows Sold"), null, nonPersistentConfig);

            var nonPersistentAggregator = new NaiveDistinctCountMetricSeriesAggregator(
                (MetricSeriesConfigurationForNaiveDistinctCount)nonPersistentMetric.GetConfiguration(),
                nonPersistentMetric,
                CycleKind.Custom);

            var persistentConfig = new MetricSeriesConfigurationForNaiveDistinctCount(usePersistentAggregation: true);
            var persistentMetric = new MetricSeries(aggregationManager, new MetricIdentifier("Unique Cows Sold"), null, persistentConfig);

            var persistentAggregator = new NaiveDistinctCountMetricSeriesAggregator(
                (MetricSeriesConfigurationForNaiveDistinctCount)persistentMetric.GetConfiguration(),
                persistentMetric,
                CycleKind.Custom);

            var  startTS      = new DateTimeOffset(2017, 9, 25, 17, 0, 0, TimeSpan.FromHours(-8));
            var  endTS        = new DateTimeOffset(2017, 9, 25, 17, 1, 0, TimeSpan.FromHours(-8));
            long periodMillis = (long)(endTS - startTS).TotalMilliseconds;

            int filterDoubleInvocationsCount = 0;
            int filterObjectInvocationsCount = 0;

            nonPersistentAggregator.Reset(
                startTS,
                new CommonSimpleDataSeriesAggregatorTests.CustomDoubleValueFilter(
                    filterFunctionDouble: (s, v) => { filterDoubleInvocationsCount++; return(true); },
                    filterFunctionObject: (s, v) => { filterObjectInvocationsCount++; return(true); }));

            Assert.AreEqual(0, filterDoubleInvocationsCount);
            Assert.AreEqual(0, filterObjectInvocationsCount);

            nonPersistentAggregator.TrackValue(1);
            nonPersistentAggregator.TrackValue("2");
            nonPersistentAggregator.TrackValue(2);

            MetricAggregate aggregate = nonPersistentAggregator.CompleteAggregation(endTS);

            ValidateNumericAggregateValues(aggregate, name: "Unique Cows Sold", count: 3, sum: 2, max: 0, min: 0, stdDev: 0, timestamp: startTS, periodMs: periodMillis);
            Assert.AreEqual(2, filterDoubleInvocationsCount);
            Assert.AreEqual(1, filterObjectInvocationsCount);

            nonPersistentAggregator.TrackValue("3");
            nonPersistentAggregator.TrackValue(4);

            aggregate = nonPersistentAggregator.CompleteAggregation(endTS);

            //// We had this originally when completed agregators did not take any more values when they were non-persistent. This complexity has no benefit.
            //ValidateNumericAggregateValues(aggregate, name: "Unique Cows Sold", count: 3, sum: 2, max: 0, min: 0, stdDev: 0, timestamp: startTS, periodMs: periodMillis);
            //Assert.AreEqual(2, filterDoubleInvocationsCount);
            //Assert.AreEqual(1, filterObjectInvocationsCount);
            ValidateNumericAggregateValues(aggregate, name: "Unique Cows Sold", count: 5, sum: 4, max: 0, min: 0, stdDev: 0, timestamp: startTS, periodMs: periodMillis);
            Assert.AreEqual(3, filterDoubleInvocationsCount);
            Assert.AreEqual(2, filterObjectInvocationsCount);

            filterDoubleInvocationsCount = 0;
            filterObjectInvocationsCount = 0;

            persistentAggregator.Reset(
                startTS,
                new CommonSimpleDataSeriesAggregatorTests.CustomDoubleValueFilter(
                    filterFunctionDouble: (s, v) => { filterDoubleInvocationsCount++; return(true); },
                    filterFunctionObject: (s, v) => { filterObjectInvocationsCount++; return(true); }));

            Assert.AreEqual(0, filterDoubleInvocationsCount);
            Assert.AreEqual(0, filterObjectInvocationsCount);

            persistentAggregator.TrackValue(1);
            persistentAggregator.TrackValue("2");
            persistentAggregator.TrackValue("1");

            aggregate = persistentAggregator.CompleteAggregation(endTS);
            ValidateNumericAggregateValues(aggregate, name: "Unique Cows Sold", count: 3, sum: 2, max: 0, min: 0, stdDev: 0, timestamp: startTS, periodMs: periodMillis);
            Assert.AreEqual(1, filterDoubleInvocationsCount);
            Assert.AreEqual(2, filterObjectInvocationsCount);

            persistentAggregator.TrackValue("3");
            persistentAggregator.TrackValue(4);

            aggregate = persistentAggregator.CompleteAggregation(endTS);
            ValidateNumericAggregateValues(aggregate, name: "Unique Cows Sold", count: 5, sum: 4, max: 0, min: 0, stdDev: 0, timestamp: startTS, periodMs: periodMillis);
            Assert.AreEqual(2, filterDoubleInvocationsCount);
            Assert.AreEqual(3, filterObjectInvocationsCount);
        }