예제 #1
0
 /// <summary />
 /// <param name="seriesCountLimit"></param>
 /// <param name="valuesPerDimensionLimit"></param>
 /// <param name="seriesConfig"></param>
 public MetricConfigurationForNaiveDistinctCount(
     int seriesCountLimit,
     int valuesPerDimensionLimit,
     MetricSeriesConfigurationForNaiveDistinctCount seriesConfig)
     : base(seriesCountLimit, valuesPerDimensionLimit, seriesConfig)
 {
 }
 public NaiveDistinctCountMetricSeriesAggregator(
     MetricSeriesConfigurationForNaiveDistinctCount configuration,
     MetricSeries dataSeries,
     MetricAggregationCycleKind aggregationCycleKind)
     : base(MetricValuesBufferFactory, configuration, dataSeries, aggregationCycleKind)
 {
     _caseSensitive = configuration.IsCaseSensitiveDistinctions;
 }
예제 #3
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"]);
        }
예제 #4
0
        /// <summary>
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        public bool Equals(MetricSeriesConfigurationForNaiveDistinctCount other)
        {
            if (other == null)
            {
                return(false);
            }

            if (Object.ReferenceEquals(this, other))
            {
                return(true);
            }

            return(this.RequiresPersistentAggregation == other.RequiresPersistentAggregation);
        }
예제 #5
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);
        }
예제 #6
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);
        }