예제 #1
0
        public void CreateAggregationData()
        {
            IBucketBoundaries bucketBoundaries = BucketBoundaries.Create(new List <double>()
            {
                -1.0, 0.0, 1.0
            });
            List <MutableAggregation> mutableAggregations =
                new List <MutableAggregation>()
            {
                MutableCount.Create(),
                                      MutableMean.Create(),
                                      MutableDistribution.Create(bucketBoundaries)
            };
            List <IAggregationData> aggregates = new List <IAggregationData>
            {
                MutableViewData.CreateAggregationData(MutableSum.Create(), MEASURE_DOUBLE),
                MutableViewData.CreateAggregationData(MutableSum.Create(), MEASURE_LONG),
                MutableViewData.CreateAggregationData(MutableLastValue.Create(), MEASURE_DOUBLE),
                MutableViewData.CreateAggregationData(MutableLastValue.Create(), MEASURE_LONG)
            };

            foreach (MutableAggregation mutableAggregation in mutableAggregations)
            {
                aggregates.Add(MutableViewData.CreateAggregationData(mutableAggregation, MEASURE_DOUBLE));
            }

            List <IAggregationData> expected = new List <IAggregationData>()
            {
                SumDataDouble.Create(0),
                SumDataLong.Create(0),
                LastValueDataDouble.Create(double.NaN),
                LastValueDataLong.Create(0),
                CountData.Create(0),
                MeanData.Create(0, 0, double.MaxValue, double.MinValue),
                DistributionData.Create(
                    0,
                    0,
                    double.PositiveInfinity,
                    double.NegativeInfinity,
                    0,
                    new List <long>()
                {
                    0L, 0L, 0L, 0L
                })
            };

            Assert.Equal(expected, aggregates);
        }
예제 #2
0
        public void GetMetricSamples_ReturnsExpected()
        {
            var opts  = new MetricsEndpointOptions();
            var stats = new OpenCensusStats();
            var ep    = new MetricsEndpoint(opts, stats);

            SetupTestView(stats, Sum.Create(), null, "test.test1");
            var viewData             = stats.ViewManager.GetView(ViewName.Create("test.test1"));
            IAggregationData aggData = SumDataDouble.Create(100);

            Assert.NotNull(viewData);
            var result = ep.GetMetricSamples(aggData, viewData);

            Assert.NotNull(result);
            Assert.Single(result);
            var sample = result[0];

            Assert.Equal(100, sample.Value);
            Assert.Equal(MetricStatistic.TOTALTIME, sample.Statistic);

            SetupTestView(stats, Sum.Create(), null, "test.test2");
            viewData = stats.ViewManager.GetView(ViewName.Create("test.test2"));
            aggData  = SumDataLong.Create(100);

            Assert.NotNull(viewData);
            result = ep.GetMetricSamples(aggData, viewData);
            Assert.NotNull(result);
            Assert.Single(result);
            sample = result[0];
            Assert.Equal(100, sample.Value);
            Assert.Equal(MetricStatistic.TOTALTIME, sample.Statistic);

            SetupTestView(stats, Count.Create(), null, "test.test3");
            viewData = stats.ViewManager.GetView(ViewName.Create("test.test3"));
            aggData  = CountData.Create(100);

            Assert.NotNull(viewData);
            result = ep.GetMetricSamples(aggData, viewData);
            Assert.NotNull(result);
            Assert.Single(result);
            sample = result[0];
            Assert.Equal(100, sample.Value);
            Assert.Equal(MetricStatistic.COUNT, sample.Statistic);

            SetupTestView(stats, Mean.Create(), null, "test.test4");
            viewData = stats.ViewManager.GetView(ViewName.Create("test.test4"));
            aggData  = MeanData.Create(100, 50, 1, 500);

            Assert.NotNull(viewData);
            result = ep.GetMetricSamples(aggData, viewData);
            Assert.NotNull(result);
            Assert.Equal(2, result.Count);
            sample = result[0];
            Assert.Equal(50, sample.Value);
            Assert.Equal(MetricStatistic.COUNT, sample.Statistic);
            sample = result[1];
            Assert.Equal(100 * 50, sample.Value);
            Assert.Equal(MetricStatistic.TOTALTIME, sample.Statistic);

            SetupTestView(stats, Distribution.Create(BucketBoundaries.Create(new List <double>()
            {
                0.0, 10.0, 20.0
            })), null, "test.test5");
            viewData = stats.ViewManager.GetView(ViewName.Create("test.test5"));
            aggData  = DistributionData.Create(100, 50, 5, 200, 5, new List <long>()
            {
                10, 20, 20
            });

            Assert.NotNull(viewData);
            result = ep.GetMetricSamples(aggData, viewData);
            Assert.NotNull(result);
            Assert.Equal(3, result.Count);

            sample = result[0];
            Assert.Equal(50, sample.Value);
            Assert.Equal(MetricStatistic.COUNT, sample.Statistic);

            sample = result[1];
            Assert.Equal(200, sample.Value);
            Assert.Equal(MetricStatistic.MAX, sample.Statistic);

            sample = result[2];
            Assert.Equal(100 * 50, sample.Value);
            Assert.Equal(MetricStatistic.TOTALTIME, sample.Statistic);
        }
예제 #3
0
        public void TestEquals()
        {
            var a1 = SumDataDouble.Create(10.0);
            var a2 = SumDataDouble.Create(20.0);
            var a3 = SumDataLong.Create(20);
            var a5 = CountData.Create(40);
            var a6 = CountData.Create(80);
            var a7 = DistributionData.Create(10, 10, 1, 1, 0, new List <long>()
            {
                0L, 10L, 0L
            });
            var a8 = DistributionData.Create(10, 10, 1, 1, 0, new List <long>()
            {
                0L, 10L, 100L
            });
            var a9 = DistributionData.Create(110, 10, 1, 1, 0, new List <long>()
            {
                0L, 10L, 0L
            });
            var a10 = DistributionData.Create(10, 110, 1, 1, 0, new List <long>()
            {
                0L, 10L, 0L
            });
            var a11 = DistributionData.Create(10, 10, -1, 1, 0, new List <long>()
            {
                0L, 10L, 0L
            });
            var a12 = DistributionData.Create(10, 10, 1, 5, 0, new List <long>()
            {
                0L, 10L, 0L
            });
            var a13 = DistributionData.Create(10, 10, 1, 1, 55.5, new List <long>()
            {
                0L, 10L, 0L
            });
            var a14 = MeanData.Create(5.0, 1, 5.0, 5.0);
            var a15 = MeanData.Create(-5.0, 1, -5.0, -5.0);
            var a16 = LastValueDataDouble.Create(20.0);
            var a17 = LastValueDataLong.Create(20);

            var a1a = SumDataDouble.Create(10.0);
            var a2a = SumDataDouble.Create(20.0);
            var a3a = SumDataLong.Create(20);
            var a5a = CountData.Create(40);
            var a6a = CountData.Create(80);
            var a7a = DistributionData.Create(10, 10, 1, 1, 0, new List <long>()
            {
                0L, 10L, 0L
            });
            var a8a = DistributionData.Create(10, 10, 1, 1, 0, new List <long>()
            {
                0L, 10L, 100L
            });
            var a9a = DistributionData.Create(110, 10, 1, 1, 0, new List <long>()
            {
                0L, 10L, 0L
            });
            var a10a = DistributionData.Create(10, 110, 1, 1, 0, new List <long>()
            {
                0L, 10L, 0L
            });
            var a11a = DistributionData.Create(10, 10, -1, 1, 0, new List <long>()
            {
                0L, 10L, 0L
            });
            var a12a = DistributionData.Create(10, 10, 1, 5, 0, new List <long>()
            {
                0L, 10L, 0L
            });
            var a13a = DistributionData.Create(10, 10, 1, 1, 55.5, new List <long>()
            {
                0L, 10L, 0L
            });
            var a14a = MeanData.Create(5.0, 1, 5.0, 5.0);
            var a15a = MeanData.Create(-5.0, 1, -5.0, -5.0);
            var a16a = LastValueDataDouble.Create(20.0);
            var a17a = LastValueDataLong.Create(20);

            Assert.Equal(a1, a1a);
            Assert.Equal(a2, a2a);
            Assert.Equal(a3, a3a);
            Assert.Equal(a5, a5a);
            Assert.Equal(a6, a6a);
            Assert.Equal(a7, a7a);
            Assert.Equal(a8, a8a);
            Assert.Equal(a9, a9a);
            Assert.Equal(a10, a10a);
            Assert.Equal(a11, a11a);
            Assert.Equal(a12, a12a);
            Assert.Equal(a13, a13a);
            Assert.Equal(a14, a14a);
            Assert.Equal(a15, a15a);
            Assert.Equal(a16, a16a);
            Assert.Equal(a17, a17a);
        }
예제 #4
0
        public void TestMatchAndGet()
        {
            List <IAggregationData> aggregations =
                new List <IAggregationData>()
            {
                SumDataDouble.Create(10.0),
                SumDataLong.Create(100000000),
                CountData.Create(40),
                MeanData.Create(100.0, 10, 300.0, 500.0),
                DistributionData.Create(1, 1, 1, 1, 0, new List <long>()
                {
                    0L, 10L, 0L
                }),
                LastValueDataDouble.Create(20.0),
                LastValueDataLong.Create(200000000L),
            };

            List <object> actual = new List <object>();

            foreach (IAggregationData aggregation in aggregations)
            {
                aggregation.Match <object>(
                    (arg) =>
                {
                    actual.Add(arg.Sum);
                    return(null);
                },
                    (arg) =>
                {
                    actual.Add(arg.Sum);
                    return(null);
                },
                    (arg) =>
                {
                    actual.Add(arg.Count);
                    return(null);
                },
                    (arg) =>
                {
                    actual.Add(arg.Mean);
                    return(null);
                },
                    (arg) =>
                {
                    actual.Add(arg.BucketCounts);
                    return(null);
                },
                    (arg) =>
                {
                    actual.Add(arg.LastValue);
                    return(null);
                },
                    (arg) =>
                {
                    actual.Add(arg.LastValue);
                    return(null);
                },
                    (arg) => { throw new ArgumentException(); });
            }
            Assert.Equal(10.0, actual[0]);
            Assert.Equal(100000000L, actual[1]);
            Assert.Equal(40L, actual[2]);
            Assert.Equal(100.0, actual[3]);
            Assert.Equal(new List <long>()
            {
                0L, 10L, 0L
            }, actual[4]);
            Assert.Equal(20.0, actual[5]);
            Assert.Equal(200000000L, actual[6]);
        }