Exemplo n.º 1
0
        public void CurrentBuilder_DefaultIsEmpty()
        {
            ITagContextBuilder currentBuilder = tagger.CurrentBuilder;

            Assert.IsType <TagContextBuilder>(currentBuilder);
            Assert.Empty(TagsTestUtil.TagContextToList(currentBuilder.Build()));
        }
Exemplo n.º 2
0
        public void EmptyBuilder()
        {
            ITagContextBuilder builder = tagger.EmptyBuilder;

            Assert.IsType <TagContextBuilder>(builder);
            Assert.Empty(TagsTestUtil.TagContextToList(builder.Build()));
        }
        public void TestRoundtrip_TagContextWithMaximumSize()
        {
            ITagContextBuilder builder = tagger.EmptyBuilder;

            for (int i = 0; i < SerializationUtils.TagContextSerializedSizeLimit / 8; i++)
            {
                // Each tag will be with format {key : "0123", value : "0123"}, so the length of it is 8.
                // Add 1024 tags, the total size should just be 8192.
                String str;
                if (i < 10)
                {
                    str = "000" + i;
                }
                else if (i < 100)
                {
                    str = "00" + i;
                }
                else if (i < 1000)
                {
                    str = "0" + i;
                }
                else
                {
                    str = "" + i;
                }
                builder.Put(TagKey.Create(str), TagValue.Create(str));
            }
            TestRoundtripSerialization(builder.Build());
        }
        private void TestSerialize(params ITag[] tags)
        {
            ITagContextBuilder builder = tagger.EmptyBuilder;

            foreach (var tag in tags)
            {
                builder.Put(tag.Key, tag.Value);
            }

            byte[]        actual          = serializer.ToByteArray(builder.Build());
            var           tagsList        = tags.ToList();
            var           tagPermutation  = Permutate(tagsList, tagsList.Count);
            ISet <String> possibleOutPuts = new HashSet <String>();

            foreach (List <ITag> list in tagPermutation)
            {
                MemoryStream expected = new MemoryStream();
                expected.WriteByte(SerializationUtils.VersionId);
                foreach (ITag tag in list)
                {
                    expected.WriteByte(SerializationUtils.TagFieldId);
                    EncodeString(tag.Key.Name, expected);
                    EncodeString(tag.Value.AsString, expected);
                }
                var bytes = expected.ToArray();
                possibleOutPuts.Add(Encoding.UTF8.GetString(bytes));
            }
            var exp = Encoding.UTF8.GetString(actual);

            Assert.Contains(exp, possibleOutPuts);
        }
        public void TestSerializeTooLargeTagContext()
        {
            ITagContextBuilder builder = tagger.EmptyBuilder;

            for (int i = 0; i < SerializationUtils.TagContextSerializedSizeLimit / 8 - 1; i++)
            {
                // Each tag will be with format {key : "0123", value : "0123"}, so the length of it is 8.
                String str;
                if (i < 10)
                {
                    str = "000" + i;
                }
                else if (i < 100)
                {
                    str = "00" + i;
                }
                else if (i < 1000)
                {
                    str = "0" + i;
                }
                else
                {
                    str = i.ToString();
                }
                builder.Put(TagKey.Create(str), TagValue.Create(str));
            }
            // The last tag will be of size 9, so the total size of the TagContext (8193) will be one byte
            // more than limit.
            builder.Put(TagKey.Create("last"), TagValue.Create("last1"));

            ITagContext tagContext = builder.Build();

            Assert.Throws <TagContextSerializationException>(() => serializer.ToByteArray(tagContext));
        }
Exemplo n.º 6
0
        public void CurrentBuilder_SkipNullTag()
        {
            ITagContext        tagContextWithNullTag = new SimpleTagContext(TAG1, null, TAG2);
            ITagContextBuilder result = GetResultOfCurrentBuilder(tagContextWithNullTag);

            Assert.Equal(new List <ITag>()
            {
                TAG1, TAG2
            }, TagsTestUtil.TagContextToList(result.Build()));
        }
Exemplo n.º 7
0
        public void Put_NullValue()
        {
            TagContext tags = new TagContext(new Dictionary <ITagKey, ITagValue>()
            {
                { K1, V1 }
            });
            ITagContextBuilder builder = tagger.ToBuilder(tags);

            Assert.Throws <ArgumentNullException>(() => builder.Put(K2, null));
        }
        public void Remove_NullKey()
        {
            TagContext tags = new TagContext(new Dictionary <TagKey, TagValue>()
            {
                { K1, V1 }
            });
            ITagContextBuilder builder = tagger.ToBuilder(tags);

            Assert.Throws <ArgumentNullException>(() => builder.Remove(null));
        }
Exemplo n.º 9
0
        public void CurrentBuilder()
        {
            ITagContext        tags   = new SimpleTagContext(TAG1, TAG2, TAG3);
            ITagContextBuilder result = GetResultOfCurrentBuilder(tags);

            Assert.IsType <TagContextBuilder>(result);
            Assert.Equal(new List <ITag>()
            {
                TAG1, TAG2, TAG3
            }, TagsTestUtil.TagContextToList(result.Build()));
        }
Exemplo n.º 10
0
        public void CurrentBuilder_RemoveDuplicateTags()
        {
            ITag               tag1 = Tag.Create(K1, V1);
            ITag               tag2 = Tag.Create(K1, V2);
            ITagContext        tagContextWithDuplicateTags = new SimpleTagContext(tag1, tag2);
            ITagContextBuilder result = GetResultOfCurrentBuilder(tagContextWithDuplicateTags);

            Assert.Equal(new List <ITag>()
            {
                tag2
            }, TagsTestUtil.TagContextToList(result.Build()));
        }
Exemplo n.º 11
0
        internal static object Run()
        {
            var exporter = new PrometheusExporter(
                new PrometheusExporterOptions()
            {
                Url = new Uri("http://localhost:9184/metrics/")
            },
                Stats.ViewManager);

            exporter.Start();

            try
            {
                ITagContextBuilder tagContextBuilder = tagger.CurrentBuilder.Put(FrontendKey, TagValue.Create("mobile-ios9.3.5"));

                Stats.ViewManager.RegisterView(VideoSizeView);

                var t = new Task(() =>
                {
                    Random r      = new Random();
                    byte[] values = new byte[1];

                    while (true)
                    {
                        using (var scopedTags = tagContextBuilder.BuildScoped())
                        {
                            r.NextBytes(values);
                            statsRecorder.NewMeasureMap().Put(VideoSize, values[0] * MiB).Record();
                            Thread.Sleep(TimeSpan.FromSeconds(1));
                        }
                    }
                });
                t.Start();

                Console.WriteLine("Look at metrics in Prometetheus console!");
                Console.ReadLine();
            }
            finally
            {
                exporter.Stop();
            }

            return(null);
        }
Exemplo n.º 12
0
        internal static object Run(string projectId)
        {
            var exporter = new StackdriverExporter(
                projectId,
                Tracing.ExportComponent,
                Stats.ViewManager);

            exporter.Start();

            ITagContextBuilder tagContextBuilder = tagger.CurrentBuilder.Put(FrontendKey, TagValue.Create("mobile-ios9.3.5"));

            var spanBuilder = tracer
                              .SpanBuilder("incoming request")
                              .SetRecordEvents(true)
                              .SetSampler(Samplers.AlwaysSample);

            Stats.ViewManager.RegisterView(VideoSizeView);

            using (var scopedTags = tagContextBuilder.BuildScoped())
            {
                using (var scopedSpan = spanBuilder.StartScopedSpan())
                {
                    tracer.CurrentSpan.AddEvent("Processing video.");
                    Thread.Sleep(TimeSpan.FromMilliseconds(10));

                    statsRecorder.NewMeasureMap()
                    .Put(VideoSize, 25 * MiB)
                    .Record();
                }
            }

            Thread.Sleep(TimeSpan.FromMilliseconds(5100));

            var viewData = Stats.ViewManager.GetView(VideoSizeViewName);

            Console.WriteLine(viewData);

            Console.WriteLine("Done... wait for events to arrive to backend!");
            Console.ReadLine();

            return(null);
        }
Exemplo n.º 13
0
        internal static object Run()
        {
            TelemetryConfiguration.Active.InstrumentationKey = "instrumentation-key";
            var exporter = new ApplicationInsightsExporter(Tracing.ExportComponent, Stats.ViewManager, TelemetryConfiguration.Active);

            exporter.Start();

            ITagContextBuilder tagContextBuilder = tagger.CurrentBuilder.Put(FrontendKey, TagValue.Create("mobile-ios9.3.5"));

            var spanBuilder = tracer
                              .SpanBuilder("incoming request")
                              .SetRecordEvents(true)
                              .SetSampler(Samplers.AlwaysSample);

            Stats.ViewManager.RegisterView(VideoSizeView);

            using (var scopedTags = tagContextBuilder.BuildScoped())
            {
                using (var scopedSpan = spanBuilder.StartScopedSpan())
                {
                    tracer.CurrentSpan.AddAnnotation("Start processing video.");
                    Thread.Sleep(TimeSpan.FromMilliseconds(10));
                    statsRecorder.NewMeasureMap().Put(VideoSize, 25 * MiB).Record();
                    tracer.CurrentSpan.AddAnnotation("Finished processing video.");
                }
            }

            Thread.Sleep(TimeSpan.FromMilliseconds(5100));

            var viewData = Stats.ViewManager.GetView(VideoSizeViewName);

            Console.WriteLine(viewData);

            Console.WriteLine("Done... wait for events to arrive to backend!");
            Console.ReadLine();

            return(null);
        }
Exemplo n.º 14
0
        public void NoopTagContextBuilder_Remove_DisallowsNullKey()
        {
            ITagContextBuilder noopBuilder = NoopTags.NoopTagContextBuilder;

            Assert.Throws <ArgumentNullException>(() => noopBuilder.Remove(null));
        }
Exemplo n.º 15
0
        public void NoopTagContextBuilder_Put_DisallowsNullValue()
        {
            ITagContextBuilder noopBuilder = NoopTags.NoopTagContextBuilder;

            Assert.Throws <ArgumentNullException>(() => noopBuilder.Put(KEY, null));
        }
Exemplo n.º 16
0
        public void NoopTagContextBuilder_Put_DisallowsNullKey()
        {
            ITagContextBuilder noopBuilder = NoopTags.NoopTagContextBuilder;

            Assert.Throws <ArgumentNullException>(() => noopBuilder.Put(null, VALUE));
        }