public void TestRecordWithEmptyStatsContext() { viewManager.RegisterView( CreateCumulativeView(VIEW_NAME, MEASURE_DOUBLE, DISTRIBUTION, new List <TagKey>() { KEY })); // DEFAULT doesn't have tags, but the view has tag key "KEY". statsRecorder.NewMeasureMap().Put(MEASURE_DOUBLE, 10.0).Record(tagger.Empty); var viewData = viewManager.GetView(VIEW_NAME); var tv = TagValues.Create(new List <TagValue>() { MutableViewData.UnknownTagValue }); StatsTestUtil.AssertAggregationMapEquals( viewData.AggregationMap, new Dictionary <TagValues, IAggregationData>() { // Tag is missing for associated measureValues, should 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) }, }, EPSILON); }
public void TestRecordWithTagsThatDoNotMatchViewData() { viewManager.RegisterView( CreateCumulativeView(VIEW_NAME, MEASURE_DOUBLE, DISTRIBUTION, new List <TagKey>() { 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()); var viewData = viewManager.GetView(VIEW_NAME); var tv = TagValues.Create(new List <TagValue>() { MutableViewData.UnknownTagValue }); 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); }
private void TestRecordCumulative(IMeasure measure, IAggregation aggregation, params double[] values) { var view = CreateCumulativeView(VIEW_NAME, measure, aggregation, new List <TagKey>() { KEY }); viewManager.RegisterView(view); var tags = tagger.EmptyBuilder.Put(KEY, VALUE).Build(); foreach (var val in values) { PutToMeasureMap(statsRecorder.NewMeasureMap(), measure, val).Record(tags); } var viewData = viewManager.GetView(VIEW_NAME); Assert.Equal(view, viewData.View); var tv = TagValues.Create(new List <TagValue>() { VALUE }); StatsTestUtil.AssertAggregationMapEquals( viewData.AggregationMap, new Dictionary <TagValues, IAggregationData>() { { tv, StatsTestUtil.CreateAggregationData(aggregation, measure, values) }, }, EPSILON); }
internal override void Record(ITagContext context, double value, ITimestamp timestamp) { IList <ITagValue> values = GetTagValues(GetTagMap(context), View.Columns); var tagValues = TagValues.Create(values); if (!tagValueAggregationMap.ContainsKey(tagValues)) { tagValueAggregationMap.Add(tagValues, CreateMutableAggregation(View.Aggregation)); } tagValueAggregationMap[tagValues].Add(value); }
internal override void Record(ITagContext context, double value, DateTimeOffset timestamp) { var values = GetTagValues(GetTagMap(context), this.View.Columns); var tagValues = TagValues.Create(values); if (!this.tagValueAggregationMap.ContainsKey(tagValues)) { this.tagValueAggregationMap.Add(tagValues, CreateMutableAggregation(this.View.Aggregation)); } this.tagValueAggregationMap[tagValues].Add(value); }
// [Fact] // public void SettingStateToDisabledWillClearStats_Interval() // { // View intervalView = // View.Create( // VIEW_NAME_2, // VIEW_DESCRIPTION, // MEASURE_DOUBLE, // MEAN, // Arrays.asList(KEY), // Interval.Create(Duration.Create(60, 0))); // settingStateToDisabledWillClearStats(intervalView); //// } private void SettingStateToDisabledWillClearStats(IView view) { ITimestamp timestamp1 = Timestamp.Create(1, 0); clock.Time = timestamp1; viewManager.RegisterView(view); statsRecorder .NewMeasureMap() .Put(MEASURE_DOUBLE, 1.1) .Record(tagger.EmptyBuilder.Put(KEY, VALUE).Build()); TagValues tv = TagValues.Create(new List <ITagValue>() { VALUE }); StatsTestUtil.AssertAggregationMapEquals( viewManager.GetView(view.Name).AggregationMap, new Dictionary <TagValues, IAggregationData>() { { tv, StatsTestUtil.CreateAggregationData(view.Aggregation, view.Measure, 1.1) } }, EPSILON); ITimestamp timestamp2 = Timestamp.Create(2, 0); clock.Time = timestamp2; statsComponent.State = StatsCollectionState.DISABLED; // This will clear stats. Assert.Equal(StatsTestUtil.CreateEmptyViewData(view), viewManager.GetView(view.Name)); ITimestamp timestamp3 = Timestamp.Create(3, 0); clock.Time = timestamp3; statsComponent.State = StatsCollectionState.ENABLED; ITimestamp timestamp4 = Timestamp.Create(4, 0); clock.Time = timestamp4; // This ViewData does not have any stats, but it should not be an empty ViewData, since it has // non-zero TimeStamps. IViewData viewData = viewManager.GetView(view.Name); Assert.Empty(viewData.AggregationMap); Assert.Equal(timestamp3, viewData.Start); Assert.Equal(timestamp4, viewData.End); // if (windowData instanceof CumulativeData) { // Assert.Equal(windowData).isEqualTo(CumulativeData.Create(timestamp3, timestamp4)); // } else { // Assert.Equal(windowData).isEqualTo(IntervalData.Create(timestamp4)); // } }
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_SumDouble_SumLong() { var tagValues = TagValues.Create(new List <ITagValue>() { V1, V2 }); AggregationAndAggregationDataMismatch( CreateView(Sum.Create(), MEASURE_DOUBLE), new Dictionary <TagValues, IAggregationData>() { { tagValues, SumDataLong.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) }, }); }
public void PreventAggregationAndAggregationDataMismatch_SumLong_SumDouble() { var tagValues = TagValues.Create(new List <string>() { V1, V2 }); AggregationAndAggregationDataMismatch( CreateView(Sum.Create(), MEASURE_LONG), new Dictionary <TagValues, IAggregationData>() { { tagValues, SumDataDouble.Create(100) }, }); }
// [Fact] // public void SettingStateToDisabledWillClearStats_Interval() // { // View intervalView = // View.Create( // VIEW_NAME_2, // VIEW_DESCRIPTION, // MeasureDouble, // Mean, // Arrays.asList(Key), // Interval.Create(Duration.Create(60, 0))); // settingStateToDisabledWillClearStats(intervalView); // } private void SettingStateToDisabledWillClearStats(IView view) { // TODO: deal with timestamp validation var timestamp1 = PreciseTimestamp.GetUtcNow().AddSeconds(-10); //clock.Time = timestamp1; viewManager.RegisterView(view); statsRecorder .NewMeasureMap() .Put(MeasureDouble, 1.1) .Record(tagger.EmptyBuilder.Put(Key, Value).Build()); TagValues tv = TagValues.Create(new List <string>() { Value }); StatsTestUtil.AssertAggregationMapEquals( viewManager.GetView(view.Name).AggregationMap, new Dictionary <TagValues, IAggregationData>() { { tv, StatsTestUtil.CreateAggregationData(view.Aggregation, view.Measure, 1.1) }, }, Epsilon); var timestamp2 = timestamp1.AddSeconds(2); //clock.Time = timestamp2; Stats.State = StatsCollectionState.DISABLED; // This will clear stats. Assert.Equal(StatsTestUtil.CreateEmptyViewData(view), viewManager.GetView(view.Name)); var timestamp3 = timestamp1.AddSeconds(3); //clock.Time = timestamp3; Stats.State = StatsCollectionState.ENABLED; var timestamp4 = timestamp1.AddSeconds(4); //clock.Time = timestamp4; // This ViewData does not have any stats, but it should not be an empty ViewData, since it has // non-zero TimeStamps. IViewData viewData = viewManager.GetView(view.Name); Assert.Empty(viewData.AggregationMap); //Assert.Equal(timestamp3, viewData.Start); //Assert.Equal(timestamp4, viewData.End); // if (windowData instanceof CumulativeData) { // Assert.Equal(windowData).isEqualTo(CumulativeData.Create(timestamp3, timestamp4)); // } else { // Assert.Equal(windowData).isEqualTo(IntervalData.Create(timestamp4)); // } }
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); }
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); }
public void Record_CurrentContextSet() { Stats.State = StatsCollectionState.ENABLED; IViewName viewName = CreateRandomViewName(); IView view = View.Create( viewName, "description", MEASURE_DOUBLE, Sum.Create(), new List <string>() { KEY }); viewManager.RegisterView(view); var orig = AsyncLocalContext.CurrentTagContext; AsyncLocalContext.CurrentTagContext = new SimpleTagContext(new DistributedContextEntry(KEY, VALUE)); try { statsRecorder.NewMeasureMap().Put(MEASURE_DOUBLE, 1.0).Record(); } finally { AsyncLocalContext.CurrentTagContext = orig; } IViewData viewData = viewManager.GetView(viewName); // record() should have used the given TagContext. ICollection <TagValues> expected = new List <TagValues>() { TagValues.Create(new List <string>() { VALUE }) }; ICollection <TagValues> actual = viewData.AggregationMap.Keys.ToList(); Assert.Equal(expected, actual); }
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); }
public void RecordTwice() { Stats.State = StatsCollectionState.ENABLED; IViewName viewName = CreateRandomViewName(); IView view = View.Create( viewName, "description", MEASURE_DOUBLE, Sum.Create(), new List <string>() { KEY }); viewManager.RegisterView(view); IMeasureMap statsRecord = statsRecorder.NewMeasureMap().Put(MEASURE_DOUBLE, 1.0); statsRecord.Record(new SimpleTagContext(new DistributedContextEntry(KEY, VALUE))); statsRecord.Record(new SimpleTagContext(new DistributedContextEntry(KEY, VALUE_2))); IViewData viewData = viewManager.GetView(viewName); // There should be two entries. var tv = TagValues.Create(new List <string>() { VALUE }); var tv2 = TagValues.Create(new List <string>() { VALUE_2 }); StatsTestUtil.AssertAggregationMapEquals( viewData.AggregationMap, new Dictionary <TagValues, IAggregationData>() { { tv, StatsTestUtil.CreateAggregationData(Sum.Create(), MEASURE_DOUBLE, 1.0) }, { tv2, StatsTestUtil.CreateAggregationData(Sum.Create(), MEASURE_DOUBLE, 1.0) }, }, 1e-6); }
private void TestMultipleViews_DifferentMeasures(IMeasure measure1, IMeasure measure2, double value1, double value2) { IView view1 = CreateCumulativeView(CreateRandomViewName(), measure1, Distribution, new List <string>() { Key }); IView view2 = CreateCumulativeView(CreateRandomViewName(), measure2, Distribution, new List <string>() { Key }); viewManager.RegisterView(view1); 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); IViewData viewData1 = viewManager.GetView(view1.Name); IViewData viewData2 = viewManager.GetView(view2.Name); var tv = TagValues.Create(new List <string>() { 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); }
public void TestMultipleViewSameMeasure() { IView view1 = CreateCumulativeView(CreateRandomViewName(), MeasureDouble, Distribution, new List <string>() { Key }); IView view2 = CreateCumulativeView(CreateRandomViewName(), MeasureDouble, Distribution, new List <string>() { Key }); viewManager.RegisterView(view1); viewManager.RegisterView(view2); statsRecorder .NewMeasureMap() .Put(MeasureDouble, 5.0) .Record(tagger.EmptyBuilder.Put(Key, Value).Build()); IViewData viewData1 = viewManager.GetView(view1.Name); IViewData viewData2 = viewManager.GetView(view2.Name); var tv = TagValues.Create(new List <string>() { Value }); StatsTestUtil.AssertAggregationMapEquals( viewData1.AggregationMap, new Dictionary <TagValues, IAggregationData>() { { tv, StatsTestUtil.CreateAggregationData(Distribution, MeasureDouble, 5.0) }, }, Epsilon); StatsTestUtil.AssertAggregationMapEquals( viewData2.AggregationMap, new Dictionary <TagValues, IAggregationData>() { { tv, StatsTestUtil.CreateAggregationData(Distribution, MeasureDouble, 5.0) }, }, Epsilon); }
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); }
public void Record_UnregisteredMeasure() { Stats.State = StatsCollectionState.ENABLED; IViewName viewName = CreateRandomViewName(); IView view = View.Create( viewName, "description", MEASURE_DOUBLE, Sum.Create(), new List <TagKey>() { 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(viewName); // There should be one entry. var tv = TagValues.Create(new List <TagValue>() { VALUE }); StatsTestUtil.AssertAggregationMapEquals( viewData.AggregationMap, new Dictionary <TagValues, IAggregationData>() { { tv, StatsTestUtil.CreateAggregationData(Sum.Create(), MEASURE_DOUBLE, 2.0) } }, 1e-6); }
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); }
public void PreventAggregationAndAggregationDataMismatch_Distribution_Count() { var tagValues1 = TagValues.Create(new List <ITagValue>() { V1, V2 }); var tagValues2 = TagValues.Create(new List <ITagValue>() { V10, V20 }); Dictionary <TagValues, IAggregationData> entries = new Dictionary <TagValues, IAggregationData>() { { tagValues1, DistributionData.Create(1, 1, 1, 1, 0, new List <long>() { 0L, 1L, 0L }) }, { tagValues2, CountData.Create(100) } }; AggregationAndAggregationDataMismatch(CreateView(DISTRIBUTION), entries); }
public void Record_CurrentContextSet() { IView view = View.Create( VIEW_NAME, "description", MEASURE_DOUBLE, Sum.Create(), new List <ITagKey>() { KEY }); viewManager.RegisterView(view); var orig = AsyncLocalContext.CurrentTagContext; AsyncLocalContext.CurrentTagContext = new SimpleTagContext(Tag.Create(KEY, VALUE)); try { statsRecorder.NewMeasureMap().Put(MEASURE_DOUBLE, 1.0).Record(); } finally { AsyncLocalContext.CurrentTagContext = orig; } IViewData viewData = viewManager.GetView(VIEW_NAME); // record() should have used the given TagContext. ICollection <TagValues> expected = new List <TagValues>() { TagValues.Create(new List <ITagValue>() { VALUE }) }; Assert.Equal(expected, viewData.AggregationMap.Keys); }
public void GetViewDoesNotClearStats() { IView view = CreateCumulativeView(CreateRandomViewName(), MeasureDouble, Distribution, new List <string>() { Key }); viewManager.RegisterView(view); ITagContext tags = tagger.EmptyBuilder.Put(Key, Value).Build(); statsRecorder.NewMeasureMap().Put(MeasureDouble, 0.1).Record(tags); IViewData viewData1 = viewManager.GetView(view.Name); var tv = TagValues.Create(new List <string>() { Value }); StatsTestUtil.AssertAggregationMapEquals( viewData1.AggregationMap, new Dictionary <TagValues, IAggregationData>() { { tv, StatsTestUtil.CreateAggregationData(Distribution, MeasureDouble, 0.1) }, }, Epsilon); statsRecorder.NewMeasureMap().Put(MeasureDouble, 0.2).Record(tags); 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, MeasureDouble, 0.1, 0.2) }, }, Epsilon); }
public void TestRecordCumulativeMultipleTagValues() { IView view = CreateCumulativeView(CreateRandomViewName(), MeasureDouble, Distribution, new List <TagKey>() { Key }); viewManager.RegisterView(view); statsRecorder .NewMeasureMap() .Put(MeasureDouble, 10.0) .Record(tagger.EmptyBuilder.Put(Key, Value).Build()); statsRecorder .NewMeasureMap() .Put(MeasureDouble, 30.0) .Record(tagger.EmptyBuilder.Put(Key, Value2).Build()); statsRecorder .NewMeasureMap() .Put(MeasureDouble, 50.0) .Record(tagger.EmptyBuilder.Put(Key, Value2).Build()); IViewData viewData = viewManager.GetView(view.Name); var tv = TagValues.Create(new List <TagValue>() { Value }); var tv2 = TagValues.Create(new List <TagValue>() { Value2 }); StatsTestUtil.AssertAggregationMapEquals( viewData.AggregationMap, new Dictionary <TagValues, IAggregationData>() { { tv, StatsTestUtil.CreateAggregationData(Distribution, MeasureDouble, 10.0) }, { tv2, StatsTestUtil.CreateAggregationData(Distribution, MeasureDouble, 30.0, 50.0) }, }, Epsilon); }
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); }
public void TestRecordWithTagsThatDoNotMatchViewData() { Stats.State = StatsCollectionState.ENABLED; IView view = CreateCumulativeView(CreateRandomViewName(), MeasureDouble, Distribution, new List <string>() { Key }); viewManager.RegisterView(view); statsRecorder .NewMeasureMap() .Put(MeasureDouble, 10.0) .Record(tagger.EmptyBuilder.Put("wrong key", Value).Build()); statsRecorder .NewMeasureMap() .Put(MeasureDouble, 50.0) .Record(tagger.EmptyBuilder.Put("another wrong key", Value).Build()); IViewData viewData = viewManager.GetView(view.Name); var tv = TagValues.Create(new List <string>() { MutableViewData.UnknownTagValue }); 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, MeasureDouble, 10.0, 50.0) }, }, Epsilon); }
public void TestViewDataWithMultipleTagKeys() { string key1 = "Key-1"; string key2 = "Key-2"; IView view = CreateCumulativeView(CreateRandomViewName(), MeasureDouble, Distribution, new List <string>() { key1, key2 }); viewManager.RegisterView(view); statsRecorder .NewMeasureMap() .Put(MeasureDouble, 1.1) .Record( tagger .EmptyBuilder .Put(key1, "v1") .Put(key2, "v10") .Build()); statsRecorder .NewMeasureMap() .Put(MeasureDouble, 2.2) .Record( tagger .EmptyBuilder .Put(key1, "v1") .Put(key2, "v20") .Build()); statsRecorder .NewMeasureMap() .Put(MeasureDouble, 3.3) .Record( tagger .EmptyBuilder .Put(key1, "v2") .Put(key2, "v10") .Build()); statsRecorder .NewMeasureMap() .Put(MeasureDouble, 4.4) .Record( tagger .EmptyBuilder .Put(key1, "v1") .Put(key2, "v10") .Build()); IViewData viewData = viewManager.GetView(view.Name); var tv1 = TagValues.Create(new List <string>() { "v1", "v10" }); var tv2 = TagValues.Create(new List <string>() { "v1", "v20" }); var tv3 = TagValues.Create(new List <string>() { "v2", "v10" }); StatsTestUtil.AssertAggregationMapEquals( viewData.AggregationMap, new Dictionary <TagValues, IAggregationData>() { { tv1, StatsTestUtil.CreateAggregationData(Distribution, MeasureDouble, 1.1, 4.4) }, { tv2, StatsTestUtil.CreateAggregationData(Distribution, MeasureDouble, 2.2) }, { tv3, StatsTestUtil.CreateAggregationData(Distribution, MeasureDouble, 3.3) }, }, Epsilon); }
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); }
public void GetAvailableTags_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")); var dict = new Dictionary <TagValues, IAggregationData>() { { TagValues.Create(new List <ITagValue>() { TagValue.Create("v1"), TagValue.Create("v1"), TagValue.Create("v1") }), SumDataDouble.Create(1) }, { TagValues.Create(new List <ITagValue>() { TagValue.Create("v2"), TagValue.Create("v2"), TagValue.Create("v2") }), SumDataDouble.Create(1) } }; var result = ep.GetAvailableTags(viewData.View.Columns, dict); Assert.NotNull(result); Assert.Equal(3, result.Count); var tag = result[0]; Assert.Equal("a", tag.Tag); Assert.Contains("v1", tag.Values); Assert.Contains("v2", tag.Values); tag = result[1]; Assert.Equal("b", tag.Tag); Assert.Contains("v1", tag.Values); Assert.Contains("v2", tag.Values); tag = result[2]; Assert.Equal("c", tag.Tag); Assert.Contains("v1", tag.Values); Assert.Contains("v2", tag.Values); dict = new Dictionary <TagValues, IAggregationData>(); result = ep.GetAvailableTags(viewData.View.Columns, dict); Assert.NotNull(result); Assert.Equal(3, result.Count); tag = result[0]; Assert.Equal("a", tag.Tag); Assert.Empty(tag.Values); tag = result[1]; Assert.Equal("b", tag.Tag); Assert.Empty(tag.Values); tag = result[2]; Assert.Equal("c", tag.Tag); Assert.Empty(tag.Values); }