예제 #1
0
        public void TestMatch()
        {
            List <IMeasure> measures =
                new List <IMeasure>()
            {
                MeasureDouble.Create("measure1", "description", "1"),
                MeasureLong.Create("measure2", "description", "1"),
            };
            List <String> outputs = new List <string>();

            foreach (IMeasure measure in measures)
            {
                outputs.Add(
                    measure.Match(
                        (arg) =>
                {
                    return("double");
                },
                        (arg) =>
                {
                    return("long");
                },
                        (arg) =>
                {
                    throw new ArgumentException();
                }));
            }

            Assert.Equal(new List <string>()
            {
                "double", "long"
            }, outputs);
        }
예제 #2
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);
        }
예제 #3
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);
        }
예제 #4
0
 public void TestRecord_MeasureTypeNotMatch()
 {
     TestRecord_MeasureNotMatch(
         MeasureLong.Create(MEASURE_NAME, "measure", MEASURE_UNIT),
         MeasureDouble.Create(MEASURE_NAME, "measure", MEASURE_UNIT),
         10.0);
 }
예제 #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 TestMultipleViews_DifferentMeasureTypes()
 {
     TestMultipleViews_DifferentMeasures(
         MeasureDouble.Create(MEASURE_NAME, MEASURE_DESCRIPTION, MEASURE_UNIT),
         MeasureLong.Create(MEASURE_NAME_2, MEASURE_DESCRIPTION, MEASURE_UNIT),
         1.1,
         5000);
 }
예제 #7
0
        public void TestMeasureDoubleComponents()
        {
            IMeasure measurement = MeasureDouble.Create("Foo", "The description of Foo", "Mbit/s");

            Assert.Equal("Foo", measurement.Name);
            Assert.Equal("The description of Foo", measurement.Description);
            Assert.Equal("Mbit/s", measurement.Unit);
        }
예제 #8
0
        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"]);
        }
예제 #9
0
        public void Invoke_WithMetricsRequest_ReturnsExpected()
        {
            var opts          = new MetricsEndpointOptions();
            var stats         = new OpenCensusStats();
            var tagsComponent = new TagsComponent();
            var tagger        = tagsComponent.Tagger;
            var ep            = new MetricsEndpoint(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 += i;
                stats.StatsRecorder.NewMeasureMap().Put(testMeasure, i).Record(context1);
            }

            var alltags = new List <KeyValuePair <string, string> >()
            {
                new KeyValuePair <string, string>("a", "v1"),
                new KeyValuePair <string, string>("b", "v1"),
                new KeyValuePair <string, string>("c", "v1")
            };

            var req  = new MetricsRequest("test.test1", alltags);
            var resp = ep.Invoke(req) as MetricsResponse;

            Assert.NotNull(resp);

            Assert.Equal("test.test1", resp.Name);

            Assert.NotNull(resp.Measurements);
            Assert.Single(resp.Measurements);
            var sample = resp.Measurements[0];

            Assert.Equal(MetricStatistic.TOTAL, sample.Statistic);
            Assert.Equal(allKeyssum, sample.Value);

            Assert.NotNull(resp.AvailableTags);
            Assert.Equal(3, resp.AvailableTags.Count);

            req  = new MetricsRequest("foo.bar", alltags);
            resp = ep.Invoke(req) as MetricsResponse;
            Assert.Null(resp);
        }
예제 #10
0
        public void PreventTooLongMeasureName()
        {
            char[] chars = new char[Measure.NAME_MAX_LENGTH + 1];

            for (int i = 0; i < chars.Length; i++)
            {
                chars[i] = 'a';
            }
            String longName = new string(chars);

            Assert.Throws <ArgumentOutOfRangeException>(() => MeasureDouble.Create(longName, "description", "1"));
        }
예제 #11
0
        public void PreventTooLongMeasureName()
        {
            var chars = new char[Measure.NameMaxLength + 1];

            for (var i = 0; i < chars.Length; i++)
            {
                chars[i] = 'a';
            }

            var longName = new string(chars);

            Assert.Throws <ArgumentOutOfRangeException>(() => MeasureDouble.Create(longName, "description", "1"));
        }
        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"]);
        }
예제 #13
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);
        }
예제 #14
0
        public void PreventRegisteringDifferentMeasureWithSameName()
        {
            IMeasureDouble measure1 = MeasureDouble.Create("measure", "description", "1");
            IMeasureLong   measure2 = MeasureLong.Create("measure", "description", "1");
            IView          view1    =
                View.Create(
                    VIEW_NAME, VIEW_DESCRIPTION, measure1, DISTRIBUTION, new List <ITagKey>()
            {
                KEY
            });
            IView view2 =
                View.Create(
                    VIEW_NAME_2, VIEW_DESCRIPTION, measure2, DISTRIBUTION, new List <ITagKey>()
            {
                KEY
            });

            TestFailedToRegisterView(view1, view2, "A different measure with the same name is already registered");
        }
예제 #15
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);
        }
        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);
        }
예제 #18
0
        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);
            }
        }
예제 #19
0
        private void SetupTestView(OpenCensusStats stats, IAggregation agg, IMeasure measure = null, string viewName = "test.test")
        {
            var aKey = TagKey.Create("a");
            var bKey = TagKey.Create("b");
            var cKey = TagKey.Create("c");

            if (measure == null)
            {
                measure = MeasureDouble.Create(Guid.NewGuid().ToString(), "test", MeasureUnit.MilliSeconds);
            }

            var testViewName = ViewName.Create(viewName);
            var testView     = View.Create(
                testViewName,
                "test",
                measure,
                agg,
                new List <ITagKey>()
            {
                aKey, bKey, cKey
            });

            stats.ViewManager.RegisterView(testView);
        }
예제 #20
0
        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);
        }
예제 #21
0
 private static IMeasureDouble MakeSimpleMeasureDouble(String measure)
 {
     return(MeasureDouble.Create(measure, measure + " description", "1"));
 }
        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"]);
        }
예제 #23
0
 public void TestMeasureDoubleIsNotEqualToMeasureLong()
 {
     Assert.NotEqual(MeasureDouble.Create("name", "description", "bit/s"), (IMeasure)MeasureLong.Create("name", "description", "bit/s"));
 }
예제 #24
0
 public void PreventNonPrintableMeasureName()
 {
     Assert.Throws <ArgumentOutOfRangeException>(() => MeasureDouble.Create("\u0002", "description", "1"));
 }
예제 #25
0
 public void TestMeasureDoubleEquals()
 {
     Assert.Equal(MeasureDouble.Create("name", "description", "bit/s"), MeasureDouble.Create("name", "description", "bit/s"));
     Assert.NotEqual(MeasureDouble.Create("name", "description", "bit/s"), MeasureDouble.Create("name", "description 2", "bit/s"));
 }
예제 #26
0
        public void GetMetricMeasurements_ReturnsExpected()
        {
            var opts          = new MetricsEndpointOptions();
            var stats         = new OpenCensusStats();
            var tagsComponent = new TagsComponent();
            var tagger        = tagsComponent.Tagger;
            var ep            = new MetricsEndpoint(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();

            var context2 = tagger
                           .EmptyBuilder
                           .Put(TagKey.Create("a"), TagValue.Create("v1"))
                           .Build();

            var context3 = tagger
                           .EmptyBuilder
                           .Put(TagKey.Create("b"), TagValue.Create("v1"))
                           .Build();

            var context4 = tagger
                           .EmptyBuilder
                           .Put(TagKey.Create("c"), TagValue.Create("v1"))
                           .Build();

            long allKeyssum = 0;

            for (var i = 0; i < 10; i++)
            {
                allKeyssum += i;
                stats.StatsRecorder.NewMeasureMap().Put(testMeasure, i).Record(context1);
            }

            long asum = 0;

            for (var i = 0; i < 10; i++)
            {
                asum += i;
                stats.StatsRecorder.NewMeasureMap().Put(testMeasure, i).Record(context2);
            }

            long bsum = 0;

            for (var i = 0; i < 10; i++)
            {
                bsum += i;
                stats.StatsRecorder.NewMeasureMap().Put(testMeasure, i).Record(context3);
            }

            long csum = 0;

            for (var i = 0; i < 10; i++)
            {
                csum += i;
                stats.StatsRecorder.NewMeasureMap().Put(testMeasure, i).Record(context4);
            }

            var alltags = new List <KeyValuePair <string, string> >()
            {
                new KeyValuePair <string, string>("a", "v1"),
                new KeyValuePair <string, string>("b", "v1"),
                new KeyValuePair <string, string>("c", "v1")
            };

            var viewData = stats.ViewManager.GetView(ViewName.Create("test.test1"));
            var result   = ep.GetMetricMeasurements(viewData, alltags);

            Assert.NotNull(result);
            Assert.Single(result);
            var sample = result[0];

            Assert.Equal(allKeyssum, sample.Value);
            Assert.Equal(MetricStatistic.TOTAL, sample.Statistic);

            var atags = new List <KeyValuePair <string, string> >()
            {
                new KeyValuePair <string, string>("a", "v1"),
            };

            result = ep.GetMetricMeasurements(viewData, atags);
            Assert.NotNull(result);
            Assert.Single(result);
            sample = result[0];
            Assert.Equal(allKeyssum + asum, sample.Value);
            Assert.Equal(MetricStatistic.TOTAL, sample.Statistic);

            var btags = new List <KeyValuePair <string, string> >()
            {
                new KeyValuePair <string, string>("b", "v1"),
            };

            result = ep.GetMetricMeasurements(viewData, btags);
            Assert.NotNull(result);
            Assert.Single(result);
            sample = result[0];
            Assert.Equal(allKeyssum + bsum, sample.Value);
            Assert.Equal(MetricStatistic.TOTAL, sample.Statistic);

            var ctags = new List <KeyValuePair <string, string> >()
            {
                new KeyValuePair <string, string>("c", "v1"),
            };

            result = ep.GetMetricMeasurements(viewData, ctags);
            Assert.NotNull(result);
            Assert.Single(result);
            sample = result[0];
            Assert.Equal(allKeyssum + csum, sample.Value);
            Assert.Equal(MetricStatistic.TOTAL, sample.Statistic);

            var abtags = new List <KeyValuePair <string, string> >()
            {
                new KeyValuePair <string, string>("a", "v1"),
                new KeyValuePair <string, string>("b", "v1"),
            };

            result = ep.GetMetricMeasurements(viewData, abtags);
            Assert.NotNull(result);
            Assert.Single(result);
            sample = result[0];
            Assert.Equal(allKeyssum, sample.Value);
            Assert.Equal(MetricStatistic.TOTAL, sample.Statistic);

            var actags = new List <KeyValuePair <string, string> >()
            {
                new KeyValuePair <string, string>("a", "v1"),
                new KeyValuePair <string, string>("c", "v1"),
            };

            result = ep.GetMetricMeasurements(viewData, actags);
            Assert.NotNull(result);
            Assert.Single(result);
            sample = result[0];
            Assert.Equal(allKeyssum, sample.Value);
            Assert.Equal(MetricStatistic.TOTAL, sample.Statistic);

            var bctags = new List <KeyValuePair <string, string> >()
            {
                new KeyValuePair <string, string>("b", "v1"),
                new KeyValuePair <string, string>("c", "v1"),
            };

            result = ep.GetMetricMeasurements(viewData, bctags);
            Assert.NotNull(result);
            Assert.Single(result);
            sample = result[0];
            Assert.Equal(allKeyssum, sample.Value);
            Assert.Equal(MetricStatistic.TOTAL, sample.Statistic);
        }