public void GetAllExportedViewsResultIsUnmodifiable() { IViewName viewName1 = CreateRandomViewName(); IViewName viewName2 = CreateRandomViewName(); IMeasureDouble measure = CreateRandomMeasureDouble(); IView view1 = View.Create( viewName1, VIEW_DESCRIPTION, measure, Distribution, new List <string>() { Key }); viewManager.RegisterView(view1); ISet <IView> exported = viewManager.AllExportedViews; IView view2 = View.Create( viewName2, VIEW_DESCRIPTION, measure, Distribution, new List <string>() { Key }); Assert.Throws <NotSupportedException>(() => exported.Add(view2)); }
public void RegisterDifferentViewWithSameNameWithStatsDisabled() { Stats.State = StatsCollectionState.DISABLED; IViewName viewName = CreateRandomViewName(); IView view1 = View.Create( viewName, "View description.", MeasureDouble, Distribution, new List <string>() { Key }); IView view2 = View.Create( viewName, "This is a different description.", MeasureDouble, Distribution, new List <string>() { Key }); TestFailedToRegisterView( view1, view2, "A different view with the same name is already registered"); }
public void Record_CurrentContextNotSet() { Stats.State = StatsCollectionState.ENABLED; IViewName viewName = CreateRandomViewName(); IView view = View.Create( viewName, "description", MEASURE_DOUBLE, Sum.Create(), new List <string>() { KEY }); viewManager.RegisterView(view); statsRecorder.NewMeasureMap().Put(MEASURE_DOUBLE, 1.0).Record(); IViewData viewData = viewManager.GetView(viewName); // record() should have used the default TagContext, so the tag value should be null. ICollection <TagValues> expected = new List <TagValues>() { TagValues.Create(new List <string>() { null }) }; ICollection <TagValues> actual = viewData.AggregationMap.Keys.ToList(); Assert.Equal(expected, actual); }
private MutableViewData GetMutableViewData(IViewName viewName) { lock (_lck) { registeredViews.TryGetValue(viewName, out IView view); if (view == null) { return(null); } mutableMap.TryGetValue(view.Measure.Name, out IList <MutableViewData> views); if (views != null) { foreach (MutableViewData viewData in views) { if (viewData.View.Name.Equals(viewName)) { return(viewData); } } } throw new InvalidOperationException( "Internal error: Not recording stats for view: \"" + viewName + "\" registeredViews=" + registeredViews + ", mutableMap=" + mutableMap); } }
internal View(IViewName name, string description, IMeasure measure, IAggregation aggregation, IList <ITagKey> columns) { if (name == null) { throw new ArgumentNullException(nameof(name)); } this.Name = name; if (description == null) { throw new ArgumentNullException(nameof(description)); } this.Description = description; if (measure == null) { throw new ArgumentNullException(nameof(measure)); } this.Measure = measure; if (aggregation == null) { throw new ArgumentNullException(nameof(aggregation)); } this.Aggregation = aggregation; if (columns == null) { throw new ArgumentNullException(nameof(columns)); } this.Columns = columns; }
public void PreventRegisteringDifferentViewWithSameName() { IViewName viewName = CreateRandomViewName(); IMeasureDouble measure = CreateRandomMeasureDouble(); IView view1 = View.Create( viewName, "View description.", measure, Distribution, new List <string>() { Key }); IView view2 = View.Create( viewName, "This is a different description.", measure, Distribution, new List <string>() { Key }); TestFailedToRegisterView(view1, view2, "A different view with the same name is already registered"); }
internal IViewData GetView(IViewName viewName, IClock clock, StatsCollectionState state) { lock (this.lck) { MutableViewData view = this.GetMutableViewData(viewName); return(view?.ToViewData(clock.Now, state)); } }
internal View(IViewName name, string description, IMeasure measure, IAggregation aggregation, IReadOnlyList <TagKey> columns) { this.Name = name ?? throw new ArgumentNullException(nameof(name)); this.Description = description ?? throw new ArgumentNullException(nameof(description)); this.Measure = measure ?? throw new ArgumentNullException(nameof(measure)); this.Aggregation = aggregation ?? throw new ArgumentNullException(nameof(aggregation)); this.Columns = columns ?? throw new ArgumentNullException(nameof(columns)); }
/** Returns a {@link ViewData} corresponding to the given {@link View.Name}. */ internal IViewData GetView(IViewName viewName, IClock clock, StatsCollectionState state) { lock (_lck) { MutableViewData view = GetMutableViewData(viewName); return(view == null ? null : view.ToViewData(clock.Now, state)); } }
internal IViewData GetView(IViewName viewName, StatsCollectionState state) { lock (this.lck) { var view = this.GetMutableViewData(viewName); return(view?.ToViewData(DateTimeOffset.Now, state)); } }
public static IView Create(IViewName name, String description, IMeasure measure,IAggregation aggregation,IList<ITagKey> columns) { var set = new HashSet<ITagKey>(columns); if (set.Count != columns.Count) { throw new ArgumentException("Columns have duplicate."); } return new View( name, description, measure, aggregation, new List<ITagKey>(columns).AsReadOnly()); }
private void SetupStats(OpenCensusStats stats) { ITagKey exceptionKey = TagKey.Create("exception"); ITagKey methodKey = TagKey.Create("method"); ITagKey uriKey = TagKey.Create("uri"); ITagKey statusKey = TagKey.Create("status"); IMeasureDouble httpServerRquestMeasure = MeasureDouble.Create("server.totalTime", "server request times", MeasureUnit.MilliSeconds); IViewName httpServerRequestsViewName = ViewName.Create("http.server.requests"); IView 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); ITagKey area = TagKey.Create("area"); ITagKey id = TagKey.Create("id"); IMeasureDouble memoryUsageMeasure = MeasureDouble.Create("memory.value", "memory usage", MeasureUnit.Bytes); IViewName memoryUsageName = ViewName.Create("jvm.memory.used"); IView 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 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 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); }
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 PreventRegisteringDifferentMeasureWithSameName() { IMeasureDouble measure1 = Measures.MeasureDouble.Create("measure", "description", "1"); IMeasureLong measure2 = Measures.MeasureLong.Create("measure", "description", "1"); IViewName viewName1 = CreateRandomViewName(); IViewName viewName2 = CreateRandomViewName(); IView view1 = View.Create( viewName1, VIEW_DESCRIPTION, measure1, Distribution, new List <string>() { Key }); IView view2 = View.Create( viewName2, VIEW_DESCRIPTION, measure2, Distribution, new List <string>() { Key }); TestFailedToRegisterView(view1, view2, "A different measure with the same name is already registered"); }
public override IViewData GetView(IViewName name) { if (name == null) { throw new ArgumentNullException(nameof(name)); } lock (registeredViews) { registeredViews.TryGetValue(name, out IView view); if (view == null) { return(null); } else { return(ViewData.Create( view, new Dictionary <TagValues, IAggregationData>(), ZERO_TIMESTAMP, ZERO_TIMESTAMP)); } } }
public void TestGetAllExportedViews() { //Assert.Empty(viewManager.AllExportedViews); IViewName viewName1 = CreateRandomViewName(); IViewName viewName2 = CreateRandomViewName(); IMeasureDouble measure = CreateRandomMeasureDouble(); IView cumulativeView1 = CreateCumulativeView( viewName1, measure, Distribution, new List <string>() { Key }); IView cumulativeView2 = CreateCumulativeView( viewName2, measure, Distribution, new List <string>() { Key }); // View intervalView = // View.Create( // View.Name.Create("View 3"), // VIEW_DESCRIPTION, // measure, // Distribution, // Arrays.asList(Key), // INTERVAL); viewManager.RegisterView(cumulativeView1); viewManager.RegisterView(cumulativeView2); // Only cumulative views should be exported. Assert.Contains(cumulativeView1, viewManager.AllExportedViews); Assert.Contains(cumulativeView2, viewManager.AllExportedViews); //Assert.Equal(2, viewManager.AllExportedViews.Count); }
private void SetupTestView(OpenCensusStats stats) { var tagsComponent = new TagsComponent(); var tagger = tagsComponent.Tagger; ITagKey aKey = TagKey.Create("a"); ITagKey bKey = TagKey.Create("b"); ITagKey cKey = TagKey.Create("c"); string viewName = "test.test"; IMeasureDouble measure = MeasureDouble.Create(Guid.NewGuid().ToString(), "test", MeasureUnit.Bytes); IViewName testViewName = ViewName.Create(viewName); IView testView = View.Create( testViewName, "test", measure, Sum.Create(), new List <ITagKey>() { aKey, bKey, cKey }); stats.ViewManager.RegisterView(testView); 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(); for (int i = 0; i < 10; i++) { stats.StatsRecorder.NewMeasureMap().Put(measure, i).Record(context1); } }
public void SetupTestView(OpenCensusStats stats, IAggregation agg, IMeasure measure = null, string viewName = "test.test") { ITagKey aKey = TagKey.Create("a"); ITagKey bKey = TagKey.Create("b"); ITagKey cKey = TagKey.Create("c"); if (measure == null) { measure = MeasureDouble.Create(Guid.NewGuid().ToString(), "test", MeasureUnit.Bytes); } IViewName testViewName = ViewName.Create(viewName); IView testView = View.Create( testViewName, "test", measure, agg, new List <ITagKey>() { aKey, bKey, cKey }); stats.ViewManager.RegisterView(testView); }
public override IViewData GetView(IViewName name) { if (name == null) { throw new ArgumentNullException(nameof(name)); } lock (this.registeredViews) { this.registeredViews.TryGetValue(name, out var view); if (view == null) { return(null); } else { return(ViewData.Create( view, new Dictionary <TagValues, IAggregationData>(), DateTimeOffset.MinValue, DateTimeOffset.MinValue)); } } }
private static string GenerateMetricDescriptorTypeName(IViewName viewName, string domain) { return(domain + viewName.AsString); }
internal IViewData GetView(IViewName viewName) { return measureToViewMap.GetView(viewName, clock, state.Internal); }
private static IView CreateCumulativeView( IViewName name, IMeasure measure, IAggregation aggregation, List <ITagKey> keys) { return(View.Create(name, VIEW_DESCRIPTION, measure, aggregation, keys)); }
public override void DataInit() { varIViewName = "_" + IViewName.ToLower(); }
public abstract IViewData GetView(IViewName view);
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()); }
internal IViewData GetView(IViewName viewName) { return(this.measureToViewMap.GetView(viewName, this.state.Internal)); }
public override IViewData GetView(IViewName viewName) { return(this.statsManager.GetView(viewName)); }