public void CounterAggregatorFiltersQueryParametersProperly()
        {
            var aggregator = new CounterAggregator(DefaultDimensions);

            Assert.IsEmpty(aggregator.ApplyPercentileCalculationAggregation(null));
            Assert.IsEmpty(aggregator.ApplyPercentileCalculationAggregation(new Dictionary <string, string>()));
            Assert.IsEmpty(aggregator.ApplyPercentileCalculationAggregation(new Dictionary <string, string> {
                { "PERCENTILE", "50.0" }
            }));
            Assert.IsEmpty(aggregator.ApplyPercentileCalculationAggregation(new Dictionary <string, string> {
                { "percentile", "50.0" }
            }));
            Assert.IsEmpty(aggregator.ApplyPercentileCalculationAggregation(new Dictionary <string, string> {
                { "Percentile", "50.0" }
            }));
            Assert.IsEmpty(aggregator.ApplyPercentileCalculationAggregation(new Dictionary <string, string> {
                { "PErcenTILe", "50.0" }
            }));

            Assert.AreEqual(1, aggregator.ApplyPercentileCalculationAggregation(new Dictionary <string, string> {
                { "percentile", "MAX" }
            }).Count());
            Assert.AreEqual(1, aggregator.ApplyPercentileCalculationAggregation(new Dictionary <string, string> {
                { "percentile", "Average" }
            }).Count());
            Assert.AreEqual(1, aggregator.ApplyPercentileCalculationAggregation(new Dictionary <string, string> {
                { "tacos", "delicious" }
            }).Count());
            Assert.AreEqual(1, aggregator.ApplyPercentileCalculationAggregation(new Dictionary <string, string> {
                { "percentile", "i am a key tree!" }
            }).Count());
        }
        public void CounterAggregatorCalculatesPercentileAfterAggregation()
        {
            var aggregator = new CounterAggregator(DefaultDimensions);

            var response = new CounterQueryResponse
            {
                HttpResponseCode = 200,
                Samples          = new List <DataSample>
                {
                    new DataSample
                    {
                        Name       = "bob",
                        StartTime  = DateTime.Now.ToMillisecondTimestamp(),
                        EndTime    = DateTime.Now.ToMillisecondTimestamp(),
                        Dimensions =
                            new Dictionary <string, string> {
                            { AnyDimensionName, "tacos" }
                        },
                        SampleType = DataSampleType.Histogram,
                        Histogram  = new Dictionary <long, uint> {
                            { 1, 1 }, { 2, 1 }, { 3, 1 }, { 4, 1 }, { 5, 1 }, { 6, 1 }, { 7, 1 }, { 8, 1 }, { 9, 1 }, { 10, 1 }
                        }
                    }
                }
            };

            // by default, we do not apply percentile filtering
            aggregator.AddMachineResponse(response);
            var defaultValue = aggregator.Samples.First();

            Assert.AreEqual(DataSampleType.Histogram, defaultValue.SampleType);

            // now that the client asked for filtering, we calculate the 99.999% percentile (should be the max value from earlier)
            aggregator.ApplyPercentileCalculationAggregation(new Dictionary <string, string> {
                { "Percentile", "99.999" }
            });
            var aggregatedValue = aggregator.Samples.First();

            Assert.AreEqual(DataSampleType.Percentile, aggregatedValue.SampleType);
            Assert.AreEqual(10, aggregatedValue.PercentileValue);
        }
        public void CounterAggregatorFiltersQueryParametersProperly()
        {
            var aggregator = new CounterAggregator(DefaultDimensions);

            Assert.IsEmpty(aggregator.ApplyPercentileCalculationAggregation(null));
            Assert.IsEmpty(aggregator.ApplyPercentileCalculationAggregation(new Dictionary<string, string>()));
            Assert.IsEmpty(aggregator.ApplyPercentileCalculationAggregation(new Dictionary<string, string> {{"PERCENTILE", "50.0"}}));
            Assert.IsEmpty(aggregator.ApplyPercentileCalculationAggregation(new Dictionary<string, string> { { "percentile", "50.0" } }));
            Assert.IsEmpty(aggregator.ApplyPercentileCalculationAggregation(new Dictionary<string, string> { { "Percentile", "50.0" } }));
            Assert.IsEmpty(aggregator.ApplyPercentileCalculationAggregation(new Dictionary<string, string> { { "PErcenTILe", "50.0" } }));

            Assert.AreEqual(1, aggregator.ApplyPercentileCalculationAggregation(new Dictionary<string, string> { { "percentile", "MAX" } }).Count());
            Assert.AreEqual(1, aggregator.ApplyPercentileCalculationAggregation(new Dictionary<string, string> { { "percentile", "Average" } }).Count());
            Assert.AreEqual(1, aggregator.ApplyPercentileCalculationAggregation(new Dictionary<string, string> { { "tacos", "delicious" } }).Count());
            Assert.AreEqual(1, aggregator.ApplyPercentileCalculationAggregation(new Dictionary<string, string> { { "percentile", "i am a key tree!" } }).Count());
        }
        public void CounterAggregatorCalculatesPercentileAfterAggregation()
        {
            var aggregator = new CounterAggregator(DefaultDimensions);

            var response = new CounterQueryResponse
            {
                HttpResponseCode = 200,
                Samples = new List<DataSample>
                                         {
                                             new DataSample
                                             {
                                                 Name = "bob",
                                                 StartTime = DateTime.Now.ToMillisecondTimestamp(),
                                                 EndTime = DateTime.Now.ToMillisecondTimestamp(),
                                                 Dimensions =
                                                     new Dictionary<string, string> {{AnyDimensionName, "tacos"}},
                                                 SampleType = DataSampleType.Histogram,
                                                 Histogram = new Dictionary<long, uint> {{1,1},{2,1},{3,1},{4,1},{5,1},{6,1},{7,1},{8,1},{9,1},{10,1}}
                                             }
                                         }
            };

            // by default, we do not apply percentile filtering
            aggregator.AddMachineResponse(response);
            var defaultValue = aggregator.Samples.First();
            Assert.AreEqual(DataSampleType.Histogram, defaultValue.SampleType);

            // now that the client asked for filtering, we calculate the 99.999% percentile (should be the max value from earlier)
            aggregator.ApplyPercentileCalculationAggregation(new Dictionary<string, string> {{"Percentile", "99.999"}});
            var aggregatedValue = aggregator.Samples.First();
            Assert.AreEqual(DataSampleType.Percentile, aggregatedValue.SampleType);
            Assert.AreEqual(10, aggregatedValue.PercentileValue);
        }