Exemple #1
0
        public void GetStatistic_ReturnsExpected()
        {
            var opts = new CloudFoundryForwarderOptions();
            var stats = new OpenCensusStats();
            var ep = new MicrometerMetricWriter(opts, stats);

            var m1 = MeasureDouble.Create("test.totalTime", "test", MeasureUnit.Seconds);
            var result = ep.GetStatistic(Sum.Create(), m1);
            Assert.Equal("totalTime", result);

            var m2 = MeasureDouble.Create("test.value", "test", MeasureUnit.Seconds);
            result = ep.GetStatistic(LastValue.Create(), m2);
            Assert.Equal("value", result);

            var m3 = MeasureDouble.Create("test.count", "test", MeasureUnit.Seconds);
            result = ep.GetStatistic(Count.Create(), m3);
            Assert.Equal("count", result);

            var m4 = MeasureDouble.Create("test.sum", "test", MeasureUnit.Bytes);
            result = ep.GetStatistic(Sum.Create(), m4);
            Assert.Equal("total", result);

            var m5 = MeasureDouble.Create("foobar", "test", MeasureUnit.Seconds);
            result = ep.GetStatistic(Distribution.Create(BucketBoundaries.Create(new List<double>() { 0.0, 1.0, 5.0, 10.0, 100.0 })), m5);
            Assert.Equal("totalTime", result);

            var m6 = MeasureDouble.Create("foobar", "test", MeasureUnit.Bytes);
            result = ep.GetStatistic(Distribution.Create(BucketBoundaries.Create(new List<double>() { 0.0, 1.0, 5.0, 10.0, 100.0 })), m6);
            Assert.Equal("total", result);
        }
Exemple #2
0
        public void CreateMetrics_LastValueAgg_ReturnsExpected()
        {
            var opts          = new CloudFoundryForwarderOptions();
            var stats         = new OpenCensusStats();
            var tagsComponent = new TagsComponent();
            var tagger        = tagsComponent.Tagger;
            var ep            = new MicrometerMetricWriter(opts, stats);

            IMeasureDouble testMeasure = MeasureDouble.Create("test.total", "test", MeasureUnit.Bytes);

            SetupTestView(stats, LastValue.Create(), testMeasure, "test.test1");

            ITagContext context1 = tagger
                                   .EmptyBuilder
                                   .Put(TagKey.Create("a"), TagValue.Create("v1"))
                                   .Put(TagKey.Create("b"), TagValue.Create("v1"))
                                   .Put(TagKey.Create("c"), TagValue.Create("v1"))
                                   .Build();

            long allKeyssum = 0;

            for (int i = 0; i < 10; i++)
            {
                allKeyssum = allKeyssum + i;
                stats.StatsRecorder.NewMeasureMap().Put(testMeasure, i).Record(context1);
            }

            var viewData = stats.ViewManager.GetView(ViewName.Create("test.test1"));

            Assert.NotNull(viewData);
            var aggMap = viewData.AggregationMap;

            Assert.Single(aggMap);

            var tagValues = aggMap.Keys.Single();
            var data      = aggMap.Values.Single();

            Assert.NotNull(tagValues);
            Assert.NotNull(data);

            var result = ep.CreateMetrics(viewData, data, tagValues, 1L);

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

            Assert.Equal("test.test1", metric.Name);
            Assert.Equal(1L, metric.Timestamp);
            Assert.Equal("gauge", metric.Type);
            Assert.Equal("bytes", metric.Unit);
            Assert.Equal(9, metric.Value);
            var tags = metric.Tags;

            Assert.Equal("value", tags["statistic"]);
            Assert.Equal("v1", tags["a"]);
            Assert.Equal("v1", tags["b"]);
            Assert.Equal("v1", tags["c"]);
        }
        public void TestMatch()
        {
            List <IAggregation> aggregations =
                new List <IAggregation>()
            {
                Sum.Create(),
                                Count.Create(),
                                Mean.Create(),
                                Distribution.Create(BucketBoundaries.Create(new List <double>()
                {
                    -10.0, 1.0, 5.0
                })),
                LastValue.Create()
            };
            List <string> actual = new List <string>();

            foreach (IAggregation aggregation in aggregations)
            {
                actual.Add(
                    aggregation.Match(
                        (arg) =>
                {
                    return("SUM");
                },
                        (arg) =>
                {
                    return("COUNT");
                },
                        (arg) =>
                {
                    return("MEAN");
                },
                        (arg) =>
                {
                    return("DISTRIBUTION");
                },
                        (arg) =>
                {
                    return("LASTVALUE");
                },
                        (arg) =>
                {
                    throw new ArgumentException();
                }));
            }

            Assert.Equal(new List <string>()
            {
                "SUM", "COUNT", "MEAN", "DISTRIBUTION", "LASTVALUE"
            }, actual);
        }
Exemple #4
0
        public void PreventAggregationAndAggregationDataMismatch_LastValueLong_LastValueDouble()
        {
            var tagValues = TagValues.Create(new List <ITagValue>()
            {
                V1, V2
            });

            AggregationAndAggregationDataMismatch(
                CreateView(LastValue.Create(), MEASURE_LONG),
                new Dictionary <TagValues, IAggregationData>()
            {
                { tagValues, LastValueDataDouble.Create(100) },
            });
        }
        public void PreventAggregationAndAggregationDataMismatch_LastValueDouble_LastValueLong()
        {
            var tagValues = TagValues.Create(new List <string>()
            {
                V1, V2
            });

            AggregationAndAggregationDataMismatch(
                CreateView(LastValue.Create(), MEASURE_DOUBLE),
                new Dictionary <TagValues, IAggregationData>()
            {
                { tagValues, LastValueDataLong.Create(100) },
            });
        }
Exemple #6
0
        public void GetStatistic_ReturnsExpected()
        {
            var opts  = new MetricsEndpointOptions();
            var stats = new OpenCensusStats();
            var ep    = new MetricsEndpoint(opts, stats);

            var m1     = MeasureDouble.Create("test.totalTime", "test", MeasureUnit.Seconds);
            var result = ep.GetStatistic(Sum.Create(), m1);

            Assert.Equal(MetricStatistic.TOTALTIME, result);

            var m2 = MeasureDouble.Create("test.value", "test", MeasureUnit.Seconds);

            result = ep.GetStatistic(LastValue.Create(), m2);
            Assert.Equal(MetricStatistic.VALUE, result);

            var m3 = MeasureDouble.Create("test.count", "test", MeasureUnit.Seconds);

            result = ep.GetStatistic(Count.Create(), m3);
            Assert.Equal(MetricStatistic.COUNT, result);

            var m4 = MeasureDouble.Create("test.sum", "test", MeasureUnit.Bytes);

            result = ep.GetStatistic(Sum.Create(), m4);
            Assert.Equal(MetricStatistic.TOTAL, result);

            var m5 = MeasureDouble.Create("foobar", "test", MeasureUnit.Seconds);

            result = ep.GetStatistic(Distribution.Create(BucketBoundaries.Create(new List <double>()
            {
                0.0, 1.0, 5.0, 10.0, 100.0
            })), m5);
            Assert.Equal(MetricStatistic.TOTALTIME, result);

            var m6 = MeasureDouble.Create("foobar", "test", MeasureUnit.Bytes);

            result = ep.GetStatistic(Distribution.Create(BucketBoundaries.Create(new List <double>()
            {
                0.0, 1.0, 5.0, 10.0, 100.0
            })), m6);
            Assert.Equal(MetricStatistic.TOTAL, result);
        }
Exemple #7
0
        public void TestEquals()
        {
            IAggregation a1 = Sum.Create();
            IAggregation a2 = Sum.Create();

            IAggregation a3 = Count.Create();
            IAggregation a4 = Count.Create();

            IAggregation a5 = Distribution.Create(BucketBoundaries.Create(new List <double>()
            {
                -10.0, 1.0, 5.0
            }));
            IAggregation a6 = Distribution.Create(BucketBoundaries.Create(new List <double>()
            {
                -10.0, 1.0, 5.0
            }));

            IAggregation a7 = Distribution.Create(BucketBoundaries.Create(new List <double>()
            {
                0.0, 1.0, 5.0
            }));
            IAggregation a8 = Distribution.Create(BucketBoundaries.Create(new List <double>()
            {
                0.0, 1.0, 5.0
            }));

            IAggregation a9  = Mean.Create();
            IAggregation a10 = Mean.Create();

            IAggregation a11 = LastValue.Create();
            IAggregation a12 = LastValue.Create();

            Assert.Equal(a1, a2);
            Assert.Equal(a3, a4);
            Assert.Equal(a5, a6);
            Assert.Equal(a7, a8);
            Assert.Equal(a9, a10);
            Assert.Equal(a11, a12);
        }
        public void CreateMutableAggregation()
        {
            IBucketBoundaries bucketBoundaries = BucketBoundaries.Create(new List <double>()
            {
                -1.0, 0.0, 1.0
            });

            Assert.InRange(((MutableSum)MutableViewData.CreateMutableAggregation(Sum.Create())).Sum, 0.0 - EPSILON, 0.0 + EPSILON);
            Assert.Equal(0, ((MutableCount)MutableViewData.CreateMutableAggregation(Count.Create())).Count);
            Assert.InRange(((MutableMean)MutableViewData.CreateMutableAggregation(Mean.Create())).Mean, 0.0 - EPSILON, 0.0 + EPSILON);
            Assert.True(Double.IsNaN(((MutableLastValue)MutableViewData.CreateMutableAggregation(LastValue.Create())).LastValue));

            MutableDistribution mutableDistribution =
                (MutableDistribution)
                MutableViewData.CreateMutableAggregation(Distribution.Create(bucketBoundaries));

            Assert.Equal(double.PositiveInfinity, mutableDistribution.Min);
            Assert.Equal(double.NegativeInfinity, mutableDistribution.Max);
            Assert.InRange(mutableDistribution.SumOfSquaredDeviations, 0.0 - EPSILON, 0.0 + EPSILON);
            Assert.Equal(new long[4], mutableDistribution.BucketCounts);
        }