Пример #1
0
        public void TestGetCumulativeViewDataWithEmptyBucketBoundaries()
        {
            IAggregation noHistogram =
                Distribution.Create(BucketBoundaries.Create(new List <double>()));
            IView view = CreateCumulativeView(VIEW_NAME, MEASURE_DOUBLE, noHistogram, new List <ITagKey>()
            {
                KEY
            });

            clock.Time = Timestamp.Create(1, 0);
            viewManager.RegisterView(view);
            statsRecorder
            .NewMeasureMap()
            .Put(MEASURE_DOUBLE, 1.1)
            .Record(tagger.EmptyBuilder.Put(KEY, VALUE).Build());
            clock.Time = Timestamp.Create(3, 0);
            IViewData viewData = viewManager.GetView(VIEW_NAME);
            var       tv       = TagValues.Create(new List <ITagValue>()
            {
                VALUE
            });

            StatsTestUtil.AssertAggregationMapEquals(
                viewData.AggregationMap,
                new Dictionary <TagValues, IAggregationData>()
            {
                { tv, StatsTestUtil.CreateAggregationData(noHistogram, MEASURE_DOUBLE, 1.1) },
            },
                EPSILON);
        }
Пример #2
0
        public HttpClientDesktopObserver(IMetricsOptions options, IStats censusStats, ITags censusTags, ILogger <HttpClientDesktopObserver> logger)
            : base(OBSERVER_NAME, DIAGNOSTIC_NAME, options, censusStats, censusTags, logger)
        {
            PathMatcher = new Regex(options.EgressIgnorePattern);

            clientTimeMeasure  = MeasureDouble.Create("client.desk.totalTime", "Total request time", MeasureUnit.MilliSeconds);
            clientCountMeasure = MeasureLong.Create("client.core.totalRequests", "Total request count", "count");

            var view = View.Create(
                ViewName.Create("http.desktop.client.request.time"),
                "Total request time",
                clientTimeMeasure,
                Distribution.Create(BucketBoundaries.Create(new List <double>()
            {
                0.0, 1.0, 5.0, 10.0, 100.0
            })),
                new List <ITagKey>()
            {
                statusTagKey, uriTagKey, methodTagKey, clientTagKey
            });

            ViewManager.RegisterView(view);

            view = View.Create(
                ViewName.Create("http.desktop.client.request.count"),
                "Total request counts",
                clientCountMeasure,
                Sum.Create(),
                new List <ITagKey>()
            {
                statusTagKey, uriTagKey, methodTagKey, clientTagKey
            });
            ViewManager.RegisterView(view);
        }
Пример #3
0
        public OwinHostingObserver(IMetricsOptions options, IStats censusStats, ITags censusTags, ILogger <OwinHostingObserver> logger)
            : base(OBSERVER_NAME, DIAGNOSTIC_NAME, options, censusStats, censusTags, logger)
        {
            PathMatcher = new Regex(options.IngressIgnorePattern);

            responseTimeMeasure = MeasureDouble.Create("server.owin.totalTime", "Total request time", MeasureUnit.MilliSeconds);
            serverCountMeasure  = MeasureLong.Create("server.owin.totalRequests", "Total request count", "count");

            var view = View.Create(
                ViewName.Create("http.server.request.time"),
                "Total request time",
                responseTimeMeasure,
                Distribution.Create(BucketBoundaries.Create(new List <double>()
            {
                0.0, 1.0, 5.0, 10.0, 100.0
            })),
                new List <ITagKey>()
            {
                statusTagKey, exceptionTagKey, methodTagKey, uriTagKey
            });

            ViewManager.RegisterView(view);

            view = View.Create(
                ViewName.Create("http.server.request.count"),
                "Total request counts",
                serverCountMeasure,
                Sum.Create(),
                new List <ITagKey>()
            {
                statusTagKey, exceptionTagKey, methodTagKey, uriTagKey
            });

            ViewManager.RegisterView(view);
        }
        public void TestNoBoundaries()
        {
            var buckets          = new List <double>();
            var bucketBoundaries = BucketBoundaries.Create(buckets);

            Assert.Equal(buckets, bucketBoundaries.Boundaries);
        }
Пример #5
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);
        }
Пример #6
0
        public void TestNoBoundaries()
        {
            List <Double>       buckets      = new List <double>();
            MutableDistribution noBoundaries = MutableDistribution.Create(BucketBoundaries.Create(buckets));

            Assert.Single(noBoundaries.BucketCounts);
            Assert.Equal(0, noBoundaries.BucketCounts[0]);
        }
        public void TestUnsortedBoundaries()
        {
            var buckets = new List <double>()
            {
                0.0, 1.0, 1.0
            };

            Assert.Throws <ArgumentOutOfRangeException>(() => BucketBoundaries.Create(buckets));
        }
Пример #8
0
        public void TestCreateDistribution()
        {
            var bucketBoundaries = BucketBoundaries.Create(new List <double>()
            {
                0.1, 2.2, 33.3
            });
            var distribution = Distribution.Create(bucketBoundaries);

            Assert.Equal(bucketBoundaries, distribution.BucketBoundaries);
        }
        public void TestConstructBoundaries()
        {
            var buckets = new List <double>()
            {
                0.0, 1.0, 2.0
            };
            var bucketBoundaries = BucketBoundaries.Create(buckets);

            Assert.Equal(buckets, bucketBoundaries.Boundaries);
        }
Пример #10
0
        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);
        }
Пример #11
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);
        }
Пример #12
0
        private void SetupStats(OpenCensusStats stats)
        {
            var exceptionKey = TagKey.Create("exception");
            var methodKey    = TagKey.Create("method");
            var uriKey       = TagKey.Create("uri");
            var statusKey    = TagKey.Create("status");

            var httpServerRquestMeasure = MeasureDouble.Create("server.totalTime", "server request times", MeasureUnit.MilliSeconds);

            var httpServerRequestsViewName = ViewName.Create("http.server.requests");
            var httpServerRequestsView     = View.Create(
                httpServerRequestsViewName,
                "server request times",
                httpServerRquestMeasure,
                Distribution.Create(BucketBoundaries.Create(new List <double>()
            {
                0.0, 1.0, 2.0
            })),
                new List <ITagKey>()
            {
                exceptionKey, methodKey, uriKey, statusKey
            });

            stats.ViewManager.RegisterView(httpServerRequestsView);

            var area = TagKey.Create("area");
            var id   = TagKey.Create("id");

            var memoryUsageMeasure = MeasureDouble.Create("memory.value", "memory usage", MeasureUnit.Bytes);

            var memoryUsageName = ViewName.Create("jvm.memory.used");
            var memoryUsageView = View.Create(
                memoryUsageName,
                "memory usage",
                memoryUsageMeasure,
                Distribution.Create(BucketBoundaries.Create(new List <double>()
            {
                0.0, 1000.0, 10000.0, 100000.0, 1000000.0, 10000000.0, 100000000.0
            })),
                new List <ITagKey>()
            {
                area, id
            });

            stats.ViewManager.RegisterView(memoryUsageView);
        }
        public void TestBoundariesDoesNotChangeWithOriginalList()
        {
            var original = new List <double>();

            original.Add(0.0);
            original.Add(1.0);
            original.Add(2.0);
            var bucketBoundaries = BucketBoundaries.Create(original);

            original[2] = 3.0;
            original.Add(4.0);
            var expected = new List <double>()
            {
                0.0, 1.0, 2.0
            };

            Assert.NotEqual(original, bucketBoundaries.Boundaries);
            Assert.Equal(expected, bucketBoundaries.Boundaries);
        }
Пример #14
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);
        }
Пример #15
0
        public void TestCreateEmpty()
        {
            Assert.InRange(MutableSum.Create().Sum, 0 - TOLERANCE, 0 + TOLERANCE);
            Assert.Equal(0, MutableCount.Create().Count);
            Assert.InRange(MutableMean.Create().Mean, 0 - TOLERANCE, 0 + TOLERANCE);
            Assert.True(Double.IsNaN(MutableLastValue.Create().LastValue));

            IBucketBoundaries bucketBoundaries = BucketBoundaries.Create(new List <double>()
            {
                0.1, 2.2, 33.3
            });
            MutableDistribution mutableDistribution = MutableDistribution.Create(bucketBoundaries);

            Assert.InRange(mutableDistribution.Mean, 0, TOLERANCE);
            Assert.Equal(0, mutableDistribution.Count);
            Assert.Equal(double.PositiveInfinity, mutableDistribution.Min);
            Assert.Equal(double.NegativeInfinity, mutableDistribution.Max);
            Assert.InRange(mutableDistribution.SumOfSquaredDeviations, 0 - TOLERANCE, 0 + TOLERANCE);
            Assert.Equal(new long[4], mutableDistribution.BucketCounts);
        }
        public void TestBucketBoundariesEquals()
        {
            var b1 = BucketBoundaries.Create(new List <double>()
            {
                -1.0, 2.0
            });
            var b2 = BucketBoundaries.Create(new List <double>()
            {
                -1.0, 2.0
            });
            var b3 = BucketBoundaries.Create(new List <double>()
            {
                -1.0
            });

            Assert.Equal(b1, b2);
            Assert.Equal(b3, b3);
            Assert.NotEqual(b1, b3);
            Assert.NotEqual(b2, b3);
        }
        public void CreateMutableAggregation()
        {
            var 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));

            var 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);
        }
Пример #18
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 TestNullBoundaries()
 {
     Assert.Throws <ArgumentNullException>(() => BucketBoundaries.Create(null));
 }
Пример #20
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);
        }
Пример #21
0
        public void CreateMetrics_DistributionAgg_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.Seconds);

            SetupTestView(stats, Distribution.Create(BucketBoundaries.Create(new List <double>()
            {
                0.0, 1.0, 5.0, 10.0, 100.0
            })), 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.Equal(4, result.Count);

            var metric = result[0];

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

            Assert.Equal("count", tags["statistic"]);
            Assert.Equal("v1", tags["a"]);
            Assert.Equal("v1", tags["b"]);
            Assert.Equal("v1", tags["c"]);

            metric = result[1];
            Assert.Equal("test.test1", metric.Name);
            Assert.Equal(1L, metric.Timestamp);
            Assert.Equal("gauge", metric.Type);
            Assert.Equal("seconds", metric.Unit);
            Assert.Equal((double)allKeyssum / 10.0, metric.Value);
            tags = metric.Tags;
            Assert.Equal("mean", tags["statistic"]);
            Assert.Equal("v1", tags["a"]);
            Assert.Equal("v1", tags["b"]);
            Assert.Equal("v1", tags["c"]);

            metric = result[2];
            Assert.Equal("test.test1", metric.Name);
            Assert.Equal(1L, metric.Timestamp);
            Assert.Equal("gauge", metric.Type);
            Assert.Equal("seconds", metric.Unit);
            Assert.Equal(9, metric.Value);
            tags = metric.Tags;
            Assert.Equal("max", tags["statistic"]);
            Assert.Equal("v1", tags["a"]);
            Assert.Equal("v1", tags["b"]);
            Assert.Equal("v1", tags["c"]);

            metric = result[3];
            Assert.Equal("test.test1", metric.Name);
            Assert.Equal(1L, metric.Timestamp);
            Assert.Equal("gauge", metric.Type);
            Assert.Equal("seconds", metric.Unit);
            Assert.Equal(allKeyssum, metric.Value);
            tags = metric.Tags;
            Assert.Equal("totalTime", tags["statistic"]);
            Assert.Equal("v1", tags["a"]);
            Assert.Equal("v1", tags["b"]);
            Assert.Equal("v1", tags["c"]);
        }
        public void Main()
        {
            var statsComponent = new StatsComponent();
            var viewManager    = statsComponent.ViewManager;
            var statsRecorder  = statsComponent.StatsRecorder;
            var tagsComponent  = new TagsComponent();
            var tagger         = tagsComponent.Tagger;

            ITagKey FRONTEND_KEY            = TagKey.Create("my.org/keys/frontend");
            ITagKey FRONTEND_OS_KEY         = TagKey.Create("my.org/keys/frontend/os");
            ITagKey FRONTEND_OS_VERSION_KEY = TagKey.Create("my.org/keys/frontend/os/version");

            IMeasureLong VIDEO_SIZE = MeasureLong.Create("my.org/measure/video_size", "size of processed videos", "MBy");

            IViewName VIDEO_SIZE_BY_FRONTEND_VIEW_NAME = ViewName.Create("my.org/views/video_size_byfrontend");
            IView     VIDEO_SIZE_BY_FRONTEND_VIEW      = View.Create(
                VIDEO_SIZE_BY_FRONTEND_VIEW_NAME,
                "processed video size over time",
                VIDEO_SIZE,
                Distribution.Create(BucketBoundaries.Create(new List <double>()
            {
                0.0, 256.0, 65536.0
            })),
                new List <ITagKey>()
            {
                FRONTEND_KEY
            });

            IViewName VIDEO_SIZE_ALL_VIEW_NAME = ViewName.Create("my.org/views/video_size_all");
            IView     VIDEO_SIZE_VIEW_ALL      = View.Create(
                VIDEO_SIZE_ALL_VIEW_NAME,
                "processed video size over time",
                VIDEO_SIZE,
                Distribution.Create(BucketBoundaries.Create(new List <double>()
            {
                0.0, 256.0, 65536.0
            })),
                new List <ITagKey>()
            {
            });


            IViewName VIDEO_SIZE_TOTAL_VIEW_NAME = ViewName.Create("my.org/views/video_size_total");
            IView     VIDEO_SIZE_TOTAL           = View.Create(
                VIDEO_SIZE_TOTAL_VIEW_NAME,
                "total video size over time",
                VIDEO_SIZE,
                Sum.Create(),
                new List <ITagKey>()
            {
                FRONTEND_KEY
            });

            IViewName VIDEOS_PROCESSED_VIEW_NAME = ViewName.Create("my.org/views/videos_processed");
            IView     VIDEOS_PROCESSED           = View.Create(
                VIDEOS_PROCESSED_VIEW_NAME,
                "total video processed",
                VIDEO_SIZE,
                Count.Create(),
                new List <ITagKey>()
            {
                FRONTEND_KEY
            });

            viewManager.RegisterView(VIDEO_SIZE_VIEW_ALL);
            viewManager.RegisterView(VIDEO_SIZE_BY_FRONTEND_VIEW);
            viewManager.RegisterView(VIDEO_SIZE_TOTAL);
            viewManager.RegisterView(VIDEOS_PROCESSED);

            ITagContext context1 = tagger
                                   .EmptyBuilder
                                   .Put(FRONTEND_KEY, TagValue.Create("front1"))
                                   .Build();
            ITagContext context2 = tagger
                                   .EmptyBuilder
                                   .Put(FRONTEND_KEY, TagValue.Create("front2"))
                                   .Build();

            long sum = 0;

            for (int i = 0; i < 10; i++)
            {
                sum = sum + (25648 * i);
                if (i % 2 == 0)
                {
                    statsRecorder.NewMeasureMap().Put(VIDEO_SIZE, 25648 * i).Record(context1);
                }
                else
                {
                    statsRecorder.NewMeasureMap().Put(VIDEO_SIZE, 25648 * i).Record(context2);
                }
            }

            IViewData viewDataByFrontend = viewManager.GetView(VIDEO_SIZE_BY_FRONTEND_VIEW_NAME);
            var       viewDataAggMap     = viewDataByFrontend.AggregationMap.ToList();

            output.WriteLine(viewDataByFrontend.ToString());

            IViewData viewDataAll       = viewManager.GetView(VIDEO_SIZE_ALL_VIEW_NAME);
            var       viewDataAggMapAll = viewDataAll.AggregationMap.ToList();

            output.WriteLine(viewDataAll.ToString());

            IViewData viewData1       = viewManager.GetView(VIDEO_SIZE_TOTAL_VIEW_NAME);
            var       viewData1AggMap = viewData1.AggregationMap.ToList();

            output.WriteLine(viewData1.ToString());

            IViewData viewData2       = viewManager.GetView(VIDEOS_PROCESSED_VIEW_NAME);
            var       viewData2AggMap = viewData2.AggregationMap.ToList();

            output.WriteLine(viewData2.ToString());

            output.WriteLine(sum.ToString());
        }
        public void Main2()
        {
            var statsComponent = new StatsComponent();
            var viewManager    = statsComponent.ViewManager;
            var statsRecorder  = statsComponent.StatsRecorder;
            var tagsComponent  = new TagsComponent();
            var tagger         = tagsComponent.Tagger;

            ITagKey FRONTEND_KEY            = TagKey.Create("my.org/keys/frontend");
            ITagKey FRONTEND_OS_KEY         = TagKey.Create("my.org/keys/frontend/os");
            ITagKey FRONTEND_OS_VERSION_KEY = TagKey.Create("my.org/keys/frontend/os/version");

            IMeasureLong VIDEO_SIZE = MeasureLong.Create("my.org/measure/video_size", "size of processed videos", "MBy");

            IViewName VIDEO_SIZE_VIEW_NAME = ViewName.Create("my.org/views/video_size_byfrontend");
            IView     VIDEO_SIZE_VIEW      = View.Create(
                VIDEO_SIZE_VIEW_NAME,
                "processed video size over time",
                VIDEO_SIZE,
                Distribution.Create(BucketBoundaries.Create(new List <double>()
            {
                0.0, 256.0, 65536.0
            })),
                new List <ITagKey>()
            {
                FRONTEND_KEY, FRONTEND_OS_KEY, FRONTEND_OS_VERSION_KEY
            });


            viewManager.RegisterView(VIDEO_SIZE_VIEW);


            ITagContext context1 = tagger
                                   .EmptyBuilder
                                   .Put(FRONTEND_KEY, TagValue.Create("front1"))
                                   .Put(FRONTEND_OS_KEY, TagValue.Create("windows"))
                                   .Build();
            ITagContext context2 = tagger
                                   .EmptyBuilder
                                   .Put(FRONTEND_KEY, TagValue.Create("front2"))
                                   .Put(FRONTEND_OS_VERSION_KEY, TagValue.Create("1.1.1"))
                                   .Build();

            long sum = 0;

            for (int i = 0; i < 10; i++)
            {
                sum = sum + (25648 * i);
                if (i % 2 == 0)
                {
                    statsRecorder.NewMeasureMap().Put(VIDEO_SIZE, 25648 * i).Record(context1);
                }
                else
                {
                    statsRecorder.NewMeasureMap().Put(VIDEO_SIZE, 25648 * i).Record(context2);
                }
            }

            IViewData videoSizeView  = viewManager.GetView(VIDEO_SIZE_VIEW_NAME);
            var       viewDataAggMap = videoSizeView.AggregationMap.ToList();
            var       view           = viewManager.AllExportedViews.ToList()[0];

            for (int i = 0; i < view.Columns.Count; i++)
            {
                output.WriteLine(view.Columns[i] + "=" + GetTagValues(i, viewDataAggMap));
            }

            var keys = new List <ITagValue>()
            {
                TagValue.Create("1.1.1")
            };

            var results = videoSizeView.AggregationMap.Where((kvp) =>
            {
                foreach (var key in keys)
                {
                    if (!kvp.Key.Values.Contains(key))
                    {
                        return(false);
                    }
                }
                return(true);
            });

            output.WriteLine(videoSizeView.ToString());

            output.WriteLine(sum.ToString());
        }