public void GetMetricName_ReturnsExpected() { var opts = new CloudFoundryForwarderOptions(); var stats = new OpenCensusStats(); var ep = new SpringBootMetricWriter(opts, stats); IList <ITagKey> keys = new List <ITagKey>() { TagKey.Create("status"), TagKey.Create("exception"), TagKey.Create("method"), TagKey.Create("uri") }; IList <ITagValue> values = new List <ITagValue>() { TagValue.Create("200"), TagValue.Create("None"), TagValue.Create("GET"), TagValue.Create("/foo/bar") }; var tagDict = ep.GetTagKeysAndValues(keys, values); Assert.Equal("http.server.requests.mean.GET.200.foo.bar", ep.GetMetricName("http.server.requests", "mean", tagDict)); Assert.Equal("http.server.requests.mean", ep.GetMetricName("http.server.requests", "mean", new Dictionary <string, string>())); keys = new List <ITagKey>() { TagKey.Create("foo"), TagKey.Create("bar") }; values = new List <ITagValue>() { TagValue.Create("foo"), TagValue.Create("bar") }; tagDict = ep.GetTagKeysAndValues(keys, values); Assert.Equal("http.server.requests.bar.foo", ep.GetMetricName("http.server.requests", null, tagDict)); }
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); }
public void CreateMetrics_CountAgg_ReturnsExpected() { var opts = new CloudFoundryForwarderOptions(); var stats = new OpenCensusStats(); var tagsComponent = new TagsComponent(); var tagger = tagsComponent.Tagger; var ep = new MicrometerMetricWriter(opts, stats); IMeasureDouble testMeasure = MeasureDouble.Create("test.total", "test", MeasureUnit.Bytes); SetupTestView(stats, Count.Create(), testMeasure, "test.test1"); ITagContext context1 = tagger .EmptyBuilder .Put(TagKey.Create("a"), TagValue.Create("v1")) .Put(TagKey.Create("b"), TagValue.Create("v1")) .Put(TagKey.Create("c"), TagValue.Create("v1")) .Build(); long allKeyssum = 0; for (int i = 0; i < 10; i++) { allKeyssum = allKeyssum + i; stats.StatsRecorder.NewMeasureMap().Put(testMeasure, i).Record(context1); } var viewData = stats.ViewManager.GetView(ViewName.Create("test.test1")); Assert.NotNull(viewData); var aggMap = viewData.AggregationMap; Assert.Single(aggMap); var tagValues = aggMap.Keys.Single(); var data = aggMap.Values.Single(); Assert.NotNull(tagValues); Assert.NotNull(data); var result = ep.CreateMetrics(viewData, data, tagValues, 1L); Assert.NotNull(result); Assert.Single(result); var metric = result[0]; Assert.Equal("test.test1", metric.Name); Assert.Equal(1L, metric.Timestamp); Assert.Equal("gauge", metric.Type); Assert.Equal("bytes", metric.Unit); Assert.Equal(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"]); }
public void GetTagKeysAndValues_ReturnsExpected() { var opts = new CloudFoundryForwarderOptions(); var stats = new OpenCensusStats(); var ep = new SpringBootMetricWriter(opts, stats); IList <ITagKey> keys = new List <ITagKey>() { TagKey.Create("status"), TagKey.Create("exception"), TagKey.Create("method"), TagKey.Create("uri") }; IList <ITagValue> values = new List <ITagValue>() { TagValue.Create("v1"), TagValue.Create("v2"), TagValue.Create("v3"), TagValue.Create("v4") }; var result = ep.GetTagKeysAndValues(keys, values); Assert.Equal("v1", result["status"]); Assert.Equal("v2", result["exception"]); Assert.Equal("v3", result["method"]); Assert.Equal("v4", result["uri"]); // Verify sorted var sortedKeys = result.Keys.ToList(); Assert.Equal("exception", sortedKeys[0]); Assert.Equal("method", sortedKeys[1]); Assert.Equal("status", sortedKeys[2]); Assert.Equal("uri", sortedKeys[3]); values = new List <ITagValue>() { TagValue.Create("v1"), null, null, null }; result = ep.GetTagKeysAndValues(keys, values); Assert.Equal("v1", result["status"]); Assert.Single(result); values = new List <ITagValue>() { null, TagValue.Create("v2"), null, null }; result = ep.GetTagKeysAndValues(keys, values); Assert.Equal("v2", result["exception"]); Assert.Single(result); values = new List <ITagValue>() { TagValue.Create("v1"), }; result = ep.GetTagKeysAndValues(keys, values); Assert.Empty(result); }
public void ShouldSkipTag_ReturnsExpected() { var opts = new CloudFoundryForwarderOptions(); var stats = new OpenCensusStats(); var ep = new SpringBootMetricWriter(opts, stats); Assert.True(ep.ShouldSkipTag("exception")); Assert.True(ep.ShouldSkipTag("clientName")); Assert.False(ep.ShouldSkipTag("foobar")); }
public void GetTagValue_ReturnsExpected() { var opts = new CloudFoundryForwarderOptions(); var stats = new OpenCensusStats(); var ep = new SpringBootMetricWriter(opts, stats); Assert.Equal("root", ep.GetTagValue("/")); Assert.Equal(".foo.bar", ep.GetTagValue("/foo/bar")); Assert.Equal("foo.bar", ep.GetTagValue("foo/bar")); Assert.Equal("bar", ep.GetTagValue("bar")); }
public void GetMetricsForExportedViews_ReturnsExpected() { var opts = new CloudFoundryForwarderOptions() { MicrometerMetricWriter = true }; var stats = new OpenCensusStats(); var tagsComponent = new TagsComponent(); var tagger = tagsComponent.Tagger; var ep = new CloudFoundryForwarderExporter(opts, stats); IMeasureDouble testMeasure = MeasureDouble.Create("test.total", "test", MeasureUnit.Bytes); SetupTestView(stats, Sum.Create(), testMeasure, "test.test1"); ITagContext context1 = tagger .EmptyBuilder .Put(TagKey.Create("a"), TagValue.Create("v1")) .Put(TagKey.Create("b"), TagValue.Create("v1")) .Put(TagKey.Create("c"), TagValue.Create("v1")) .Build(); long allKeyssum = 0; for (int i = 0; i < 10; i++) { allKeyssum = allKeyssum + i; stats.StatsRecorder.NewMeasureMap().Put(testMeasure, i).Record(context1); } var result = ep.GetMetricsForExportedViews(stats.ViewManager.AllExportedViews, 1L); Assert.NotNull(result); Assert.Single(result); var metric = result[0]; Assert.Equal("test.test1", metric.Name); Assert.Equal(1L, metric.Timestamp); Assert.Equal("gauge", metric.Type); Assert.Equal("bytes", metric.Unit); Assert.Equal(allKeyssum, metric.Value); var tags = metric.Tags; Assert.Equal("total", tags["statistic"]); Assert.Equal("v1", tags["a"]); Assert.Equal("v1", tags["b"]); Assert.Equal("v1", tags["c"]); }
public void GetTagKeysAndValues_ReturnsExpected() { var opts = new CloudFoundryForwarderOptions(); var stats = new OpenCensusStats(); var ep = new MicrometerMetricWriter(opts, stats); IList <ITagKey> keys = new List <ITagKey>() { TagKey.Create("key1"), TagKey.Create("key2") }; IList <ITagValue> values = new List <ITagValue>() { TagValue.Create("v1"), TagValue.Create("v2") }; var result = ep.GetTagKeysAndValues(keys, values); Assert.Equal("v1", result["key1"]); Assert.Equal("v2", result["key2"]); values = new List <ITagValue>() { TagValue.Create("v1"), null }; result = ep.GetTagKeysAndValues(keys, values); Assert.Equal("v1", result["key1"]); Assert.Single(result); values = new List <ITagValue>() { null, TagValue.Create("v2"), }; result = ep.GetTagKeysAndValues(keys, values); Assert.Equal("v2", result["key2"]); Assert.Single(result); values = new List <ITagValue>() { TagValue.Create("v1"), }; result = ep.GetTagKeysAndValues(keys, values); Assert.Empty(result); }
public void GetMessage_ReturnsExpected() { var configsource = new Dictionary <string, string> { { "application:InstanceId", "InstanceId" }, { "application:InstanceIndex", "1" }, { "application:ApplicationId", "ApplicationId" }, { "management:metrics:exporter:cloudfoundry:MicrometerMetricWriter", "true" } }; var config = TestHelpers.GetConfigurationFromDictionary(configsource); var opts = new CloudFoundryForwarderOptions(new ApplicationInstanceInfo(config), new ServicesOptions(config), config); var stats = new OpenCensusStats(); var tagsComponent = new TagsComponent(); var tagger = tagsComponent.Tagger; var ep = new CloudFoundryForwarderExporter(opts, stats); var testMeasure = MeasureDouble.Create("test.total", "test", MeasureUnit.Bytes); SetupTestView(stats, Sum.Create(), testMeasure, "test.test1"); var 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 (var i = 0; i < 10; i++) { allKeyssum = allKeyssum + i; stats.StatsRecorder.NewMeasureMap().Put(testMeasure, i).Record(context1); } var message = ep.GetMessage(stats.ViewManager.AllExportedViews, 1L); Assert.NotNull(message); var result = Serialize(message); Assert.Equal("{\"applications\":[{\"id\":\"ApplicationId\",\"instances\":[{\"id\":\"InstanceId\",\"index\":\"1\",\"metrics\":[{\"name\":\"test.test1\",\"tags\":{\"a\":\"v1\",\"b\":\"v1\",\"c\":\"v1\",\"statistic\":\"total\"},\"timestamp\":1,\"type\":\"gauge\",\"unit\":\"bytes\",\"value\":45.0}]}]}]}", result); }
public void GetMessage_ReturnsExpected() { var opts = new CloudFoundryForwarderOptions() { InstanceId = "InstanceId", InstanceIndex = "InstanceIndex", ApplicationId = "ApplicationId", MicrometerMetricWriter = true }; var stats = new OpenCensusStats(); var tagsComponent = new TagsComponent(); var tagger = tagsComponent.Tagger; var ep = new CloudFoundryForwarderExporter(opts, stats); IMeasureDouble testMeasure = MeasureDouble.Create("test.total", "test", MeasureUnit.Bytes); SetupTestView(stats, Sum.Create(), testMeasure, "test.test1"); ITagContext context1 = tagger .EmptyBuilder .Put(TagKey.Create("a"), TagValue.Create("v1")) .Put(TagKey.Create("b"), TagValue.Create("v1")) .Put(TagKey.Create("c"), TagValue.Create("v1")) .Build(); long allKeyssum = 0; for (int i = 0; i < 10; i++) { allKeyssum = allKeyssum + i; stats.StatsRecorder.NewMeasureMap().Put(testMeasure, i).Record(context1); } var message = ep.GetMessage(stats.ViewManager.AllExportedViews, 1L); Assert.NotNull(message); var result = Serialize(message); Assert.Equal("{\"applications\":[{\"id\":\"ApplicationId\",\"instances\":[{\"id\":\"InstanceId\",\"index\":\"InstanceIndex\",\"metrics\":[{\"name\":\"test.test1\",\"tags\":{\"a\":\"v1\",\"b\":\"v1\",\"c\":\"v1\",\"statistic\":\"total\"},\"timestamp\":1,\"type\":\"gauge\",\"unit\":\"bytes\",\"value\":45.0}]}]}]}", result); }
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 void CreateMetrics_DistributionAgg_ReturnsExpected() { var opts = new CloudFoundryForwarderOptions(); var stats = new OpenCensusStats(); var tagsComponent = new TagsComponent(); var tagger = tagsComponent.Tagger; var ep = new SpringBootMetricWriter(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.v1.v1.v1", 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); var tags = metric.Tags; Assert.Equal("v1", tags["a"]); Assert.Equal("v1", tags["b"]); Assert.Equal("v1", tags["c"]); metric = result[1]; Assert.Equal("test.test1.max.v1.v1.v1", 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("v1", tags["a"]); Assert.Equal("v1", tags["b"]); Assert.Equal("v1", tags["c"]); metric = result[2]; Assert.Equal("test.test1.min.v1.v1.v1", metric.Name); Assert.Equal(1L, metric.Timestamp); Assert.Equal("gauge", metric.Type); Assert.Equal("seconds", metric.Unit); Assert.Equal(0, metric.Value); tags = metric.Tags; Assert.Equal("v1", tags["a"]); Assert.Equal("v1", tags["b"]); Assert.Equal("v1", tags["c"]); metric = result[3]; Assert.Equal("test.test1.stddev.v1.v1.v1", metric.Name); Assert.Equal(1L, metric.Timestamp); Assert.Equal("gauge", metric.Type); Assert.Equal("seconds", metric.Unit); Assert.InRange(metric.Value, 2.0d, 3.0d); tags = metric.Tags; Assert.Equal("v1", tags["a"]); Assert.Equal("v1", tags["b"]); Assert.Equal("v1", tags["c"]); }