Exemplo n.º 1
0
        public void RegisterRecordAndGetView_StatsDisabled()
        {
            statsComponent.State = StatsCollectionState.DISABLED;
            IView view = CreateCumulativeView(VIEW_NAME, MEASURE_DOUBLE, MEAN, new List <ITagKey>()
            {
                KEY
            });

            viewManager.RegisterView(view);
            statsRecorder
            .NewMeasureMap()
            .Put(MEASURE_DOUBLE, 1.1)
            .Record(tagger.EmptyBuilder.Put(KEY, VALUE).Build());
            Assert.Equal(StatsTestUtil.CreateEmptyViewData(view), viewManager.GetView(VIEW_NAME));
        }
Exemplo n.º 2
0
        private void TestMultipleViews_DifferentMeasures(IMeasure measure1, IMeasure measure2, double value1, double value2)
        {
            IView view1 = CreateCumulativeView(VIEW_NAME, measure1, DISTRIBUTION, new List <ITagKey>()
            {
                KEY
            });
            IView view2 =
                CreateCumulativeView(VIEW_NAME_2, measure2, DISTRIBUTION, new List <ITagKey>()
            {
                KEY
            });

            clock.Time = Timestamp.Create(1, 0);
            viewManager.RegisterView(view1);
            clock.Time = Timestamp.Create(2, 0);
            viewManager.RegisterView(view2);
            ITagContext tags       = tagger.EmptyBuilder.Put(KEY, VALUE).Build();
            IMeasureMap measureMap = statsRecorder.NewMeasureMap();

            PutToMeasureMap(measureMap, measure1, value1);
            PutToMeasureMap(measureMap, measure2, value2);
            measureMap.Record(tags);
            clock.Time = Timestamp.Create(3, 0);
            IViewData viewData1 = viewManager.GetView(VIEW_NAME);

            clock.Time = Timestamp.Create(4, 0);
            IViewData viewData2 = viewManager.GetView(VIEW_NAME_2);
            var       tv        = TagValues.Create(new List <ITagValue>()
            {
                VALUE
            });

            StatsTestUtil.AssertAggregationMapEquals(
                viewData1.AggregationMap,
                new Dictionary <TagValues, IAggregationData>()
            {
                { tv, StatsTestUtil.CreateAggregationData(DISTRIBUTION, measure1, value1) }
            },
                EPSILON);

            StatsTestUtil.AssertAggregationMapEquals(
                viewData2.AggregationMap,
                new Dictionary <TagValues, IAggregationData>()
            {
                { tv, StatsTestUtil.CreateAggregationData(DISTRIBUTION, measure2, value2) }
            },
                EPSILON);
        }
Exemplo n.º 3
0
        public void TestMultipleViewSameMeasure()
        {
            IView view1 =
                CreateCumulativeView(VIEW_NAME, MEASURE_DOUBLE, DISTRIBUTION, new List <ITagKey>()
            {
                KEY
            });
            IView view2 =
                CreateCumulativeView(VIEW_NAME_2, MEASURE_DOUBLE, DISTRIBUTION, new List <ITagKey>()
            {
                KEY
            });

            clock.Time = Timestamp.Create(1, 1);
            viewManager.RegisterView(view1);
            clock.Time = Timestamp.Create(2, 2);
            viewManager.RegisterView(view2);
            statsRecorder
            .NewMeasureMap()
            .Put(MEASURE_DOUBLE, 5.0)
            .Record(tagger.EmptyBuilder.Put(KEY, VALUE).Build());
            clock.Time = Timestamp.Create(3, 3);
            IViewData viewData1 = viewManager.GetView(VIEW_NAME);

            clock.Time = Timestamp.Create(4, 4);
            IViewData viewData2 = viewManager.GetView(VIEW_NAME_2);
            var       tv        = TagValues.Create(new List <ITagValue>()
            {
                VALUE
            });

            StatsTestUtil.AssertAggregationMapEquals(
                viewData1.AggregationMap,
                new Dictionary <TagValues, IAggregationData>()
            {
                { tv, StatsTestUtil.CreateAggregationData(DISTRIBUTION, MEASURE_DOUBLE, 5.0) }
            },
                EPSILON);

            StatsTestUtil.AssertAggregationMapEquals(
                viewData2.AggregationMap,
                new Dictionary <TagValues, IAggregationData>()
            {
                { tv, StatsTestUtil.CreateAggregationData(DISTRIBUTION, MEASURE_DOUBLE, 5.0) }
            },
                EPSILON);
        }
Exemplo n.º 4
0
        public void Record_StatsReenabled()
        {
            IView view =
                View.Create(
                    VIEW_NAME,
                    "description",
                    MEASURE_DOUBLE,
                    Sum.Create(),
                    new List <ITagKey>()
            {
                KEY
            });

            viewManager.RegisterView(view);

            statsComponent.State = StatsCollectionState.DISABLED;
            statsRecorder
            .NewMeasureMap()
            .Put(MEASURE_DOUBLE, 1.0)
            .Record(new SimpleTagContext(Tag.Create(KEY, VALUE)));
            Assert.Equal(CreateEmptyViewData(view), viewManager.GetView(VIEW_NAME));

            statsComponent.State = StatsCollectionState.ENABLED;
            Assert.Empty(viewManager.GetView(VIEW_NAME).AggregationMap);

            // assertThat(viewManager.getView(VIEW_NAME).getWindowData())
            //    .isNotEqualTo(CumulativeData.Create(ZERO_TIMESTAMP, ZERO_TIMESTAMP));
            statsRecorder
            .NewMeasureMap()
            .Put(MEASURE_DOUBLE, 4.0)
            .Record(new SimpleTagContext(Tag.Create(KEY, VALUE)));
            TagValues tv = TagValues.Create(new List <ITagValue>()
            {
                VALUE
            });

            StatsTestUtil.AssertAggregationMapEquals(
                viewManager.GetView(VIEW_NAME).AggregationMap,
                new Dictionary <TagValues, IAggregationData>()
            {
                { tv, StatsTestUtil.CreateAggregationData(Sum.Create(), MEASURE_DOUBLE, 4.0) }
            },
                1e-6);
        }
Exemplo n.º 5
0
        public void GetViewDoesNotClearStats()
        {
            IView view = CreateCumulativeView(VIEW_NAME, MEASURE_DOUBLE, DISTRIBUTION, new List <ITagKey>()
            {
                KEY
            });

            clock.Time = Timestamp.Create(10, 0);
            viewManager.RegisterView(view);
            ITagContext tags = tagger.EmptyBuilder.Put(KEY, VALUE).Build();

            statsRecorder.NewMeasureMap().Put(MEASURE_DOUBLE, 0.1).Record(tags);
            clock.Time = Timestamp.Create(11, 0);
            IViewData viewData1 = viewManager.GetView(VIEW_NAME);
            var       tv        = TagValues.Create(new List <ITagValue>()
            {
                VALUE
            });

            StatsTestUtil.AssertAggregationMapEquals(
                viewData1.AggregationMap,
                new Dictionary <TagValues, IAggregationData>()
            {
                { tv, StatsTestUtil.CreateAggregationData(DISTRIBUTION, MEASURE_DOUBLE, 0.1) },
            },
                EPSILON);

            statsRecorder.NewMeasureMap().Put(MEASURE_DOUBLE, 0.2).Record(tags);
            clock.Time = Timestamp.Create(12, 0);
            IViewData viewData2 = viewManager.GetView(VIEW_NAME);

            // The second view should have the same start time as the first view, and it should include both
            // Recorded values:

            StatsTestUtil.AssertAggregationMapEquals(
                viewData2.AggregationMap,
                new Dictionary <TagValues, IAggregationData>()
            {
                { tv, StatsTestUtil.CreateAggregationData(DISTRIBUTION, MEASURE_DOUBLE, 0.1, 0.2) },
            },
                EPSILON);
        }
Exemplo n.º 6
0
        public void RecordTwice()
        {
            IView view =
                View.Create(
                    VIEW_NAME,
                    "description",
                    MEASURE_DOUBLE,
                    Sum.Create(),
                    new List <ITagKey>()
            {
                KEY
            });

            viewManager.RegisterView(view);
            IMeasureMap statsRecord = statsRecorder.NewMeasureMap().Put(MEASURE_DOUBLE, 1.0);

            statsRecord.Record(new SimpleTagContext(Tag.Create(KEY, VALUE)));
            statsRecord.Record(new SimpleTagContext(Tag.Create(KEY, VALUE_2)));
            IViewData viewData = viewManager.GetView(VIEW_NAME);

            // There should be two entries.
            var tv = TagValues.Create(new List <ITagValue>()
            {
                VALUE
            });
            var tv2 = TagValues.Create(new List <ITagValue>()
            {
                VALUE_2
            });

            Dictionary <TagValues, IAggregationData> expected = new Dictionary <TagValues, IAggregationData>()
            {
                { tv, StatsTestUtil.CreateAggregationData(Sum.Create(), MEASURE_DOUBLE, 1.0) },
                { tv2, StatsTestUtil.CreateAggregationData(Sum.Create(), MEASURE_DOUBLE, 1.0) }
            };

            StatsTestUtil.AssertAggregationMapEquals(
                viewData.AggregationMap,
                expected,
                1e-6);
        }
Exemplo n.º 7
0
        public void TestRecordCumulativeMultipleTagValues()
        {
            viewManager.RegisterView(
                CreateCumulativeView(VIEW_NAME, MEASURE_DOUBLE, DISTRIBUTION, new List <ITagKey>()
            {
                KEY
            }));
            statsRecorder
            .NewMeasureMap()
            .Put(MEASURE_DOUBLE, 10.0)
            .Record(tagger.EmptyBuilder.Put(KEY, VALUE).Build());
            statsRecorder
            .NewMeasureMap()
            .Put(MEASURE_DOUBLE, 30.0)
            .Record(tagger.EmptyBuilder.Put(KEY, VALUE_2).Build());
            statsRecorder
            .NewMeasureMap()
            .Put(MEASURE_DOUBLE, 50.0)
            .Record(tagger.EmptyBuilder.Put(KEY, VALUE_2).Build());
            IViewData viewData = viewManager.GetView(VIEW_NAME);
            var       tv       = TagValues.Create(new List <ITagValue>()
            {
                VALUE
            });
            var tv2 = TagValues.Create(new List <ITagValue>()
            {
                VALUE_2
            });

            StatsTestUtil.AssertAggregationMapEquals(
                viewData.AggregationMap,
                new Dictionary <TagValues, IAggregationData>()
            {
                { tv, StatsTestUtil.CreateAggregationData(DISTRIBUTION, MEASURE_DOUBLE, 10.0) },
                { tv2, StatsTestUtil.CreateAggregationData(DISTRIBUTION, MEASURE_DOUBLE, 30.0, 50.0) }
            },
                EPSILON);
        }
Exemplo n.º 8
0
#pragma warning disable SA1202 // Elements must be ordered by access
        public void TestRecordWithTagsThatDoNotMatchViewData()
#pragma warning restore SA1202 // Elements must be ordered by access
        {
            viewManager.RegisterView(
                CreateCumulativeView(VIEW_NAME, MEASURE_DOUBLE, DISTRIBUTION, new List <ITagKey>()
            {
                KEY
            }));
            statsRecorder
            .NewMeasureMap()
            .Put(MEASURE_DOUBLE, 10.0)
            .Record(tagger.EmptyBuilder.Put(TagKey.Create("wrong key"), VALUE).Build());
            statsRecorder
            .NewMeasureMap()
            .Put(MEASURE_DOUBLE, 50.0)
            .Record(tagger.EmptyBuilder.Put(TagKey.Create("another wrong key"), VALUE).Build());
            IViewData viewData = viewManager.GetView(VIEW_NAME);
            var       tv       = TagValues.Create(new List <ITagValue>()
            {
                MutableViewData.UNKNOWN_TAG_VALUE
            });

            StatsTestUtil.AssertAggregationMapEquals(
                viewData.AggregationMap,
                new Dictionary <TagValues, IAggregationData>()
            {
                // Won't Record the unregistered tag key, for missing registered keys will use default
                // tag value : "unknown/not set".
                {
                    tv,

                    // Should Record stats with default tag value: "KEY" : "unknown/not set".
                    StatsTestUtil.CreateAggregationData(DISTRIBUTION, MEASURE_DOUBLE, 10.0, 50.0)
                }
            },
                EPSILON);
        }
        public void Record_UnregisteredMeasure()
        {
            IView view =
                View.Create(
                    VIEW_NAME,
                    "description",
                    MEASURE_DOUBLE,
                    Sum.Create(),
                    new List <ITagKey>()
            {
                KEY
            });

            viewManager.RegisterView(view);
            statsRecorder
            .NewMeasureMap()
            .Put(MEASURE_DOUBLE_NO_VIEW_1, 1.0)
            .Put(MEASURE_DOUBLE, 2.0)
            .Put(MEASURE_DOUBLE_NO_VIEW_2, 3.0)
            .Record(new SimpleTagContext(Tag.Create(KEY, VALUE)));

            IViewData viewData = viewManager.GetView(VIEW_NAME);

            // There should be one entry.
            var tv = TagValues.Create(new List <ITagValue>()
            {
                VALUE
            });

            StatsTestUtil.AssertAggregationMapEquals(
                viewData.AggregationMap,
                new Dictionary <TagValues, IAggregationData>()
            {
                { tv, StatsTestUtil.CreateAggregationData(Sum.Create(), MEASURE_DOUBLE, 2.0) }
            },
                1e-6);
        }
Exemplo n.º 10
0
        public void TestViewDataWithMultipleTagKeys()
        {
            ITagKey key1 = TagKey.Create("Key-1");
            ITagKey key2 = TagKey.Create("Key-2");

            viewManager.RegisterView(
                CreateCumulativeView(VIEW_NAME, MEASURE_DOUBLE, DISTRIBUTION, new List <ITagKey>()
            {
                key1, key2
            }));
            statsRecorder
            .NewMeasureMap()
            .Put(MEASURE_DOUBLE, 1.1)
            .Record(
                tagger
                .EmptyBuilder
                .Put(key1, TagValue.Create("v1"))
                .Put(key2, TagValue.Create("v10"))
                .Build());
            statsRecorder
            .NewMeasureMap()
            .Put(MEASURE_DOUBLE, 2.2)
            .Record(
                tagger
                .EmptyBuilder
                .Put(key1, TagValue.Create("v1"))
                .Put(key2, TagValue.Create("v20"))
                .Build());
            statsRecorder
            .NewMeasureMap()
            .Put(MEASURE_DOUBLE, 3.3)
            .Record(
                tagger
                .EmptyBuilder
                .Put(key1, TagValue.Create("v2"))
                .Put(key2, TagValue.Create("v10"))
                .Build());
            statsRecorder
            .NewMeasureMap()
            .Put(MEASURE_DOUBLE, 4.4)
            .Record(
                tagger
                .EmptyBuilder
                .Put(key1, TagValue.Create("v1"))
                .Put(key2, TagValue.Create("v10"))
                .Build());
            IViewData viewData = viewManager.GetView(VIEW_NAME);
            var       tv1      = TagValues.Create(new List <ITagValue>()
            {
                TagValue.Create("v1"), TagValue.Create("v10")
            });
            var tv2 = TagValues.Create(new List <ITagValue>()
            {
                TagValue.Create("v1"), TagValue.Create("v20")
            });
            var tv3 = TagValues.Create(new List <ITagValue>()
            {
                TagValue.Create("v2"), TagValue.Create("v10")
            });

            StatsTestUtil.AssertAggregationMapEquals(
                viewData.AggregationMap,
                new Dictionary <TagValues, IAggregationData>()
            {
                { tv1, StatsTestUtil.CreateAggregationData(DISTRIBUTION, MEASURE_DOUBLE, 1.1, 4.4) },
                { tv2, StatsTestUtil.CreateAggregationData(DISTRIBUTION, MEASURE_DOUBLE, 2.2) },
                { tv3, StatsTestUtil.CreateAggregationData(DISTRIBUTION, MEASURE_DOUBLE, 3.3) }
            },
                EPSILON);
        }