コード例 #1
0
        public void ShouldInstantiatePipelineFromValidConfiguration()
        {
            string pipelineConfiguration = @"
                {
                    ""inputs"": [
                        {  ""type"": ""EventSource"",
                            ""sources"": [
                                { ""providerName"": ""Microsoft-ServiceFabric-Services"" },
                                { ""providerName"": ""MyCompany-AirTrafficControlApplication-Frontend"" }
                            ]
                        }
                    ],

                    ""filters"": [
                        {
                            ""type"": ""metadata"",
                            ""metadata"": ""importance"",
                            ""include"": ""Level == Verbose"",
                            ""importance"": ""can be discarded""
                        }
                    ],

                    ""outputs"": [
                        {
                            ""type"": ""StdOutput"",

                            ""filters"": [
                                {
                                    ""type"": ""metadata"",
                                    ""metadata"": ""metric"",
                                    ""include"": ""ProviderName == Microsoft-ServiceFabric-Services && EventName == StatefulRunAsyncFailure"",
                                    ""metricName"": ""StatefulRunAsyncFailure"",
                                    ""metricValue"": ""1.0""
                                }
                            ]
                        }
                    ],

                    ""schemaVersion"": ""2016-08-11"",

                    ""settings"": {
                        ""maxConcurrency"": ""2"",
                        ""pipelineCompletionTimeoutMsec"": ""1000""
                    },
                    ""healthReporter"": {
                        ""type"": ""CustomHealthReporter"",
                    },
                    ""extensions"": [
                         {
                            ""category"": ""healthReporter"",
                            ""type"": ""CustomHealthReporter"",
                            ""qualifiedTypeName"": ""Microsoft.Diagnostics.EventFlow.TestHelpers.CustomHealthReporter, Microsoft.Diagnostics.EventFlow.TestHelpers""
                        }
                    ]
                }";

            try
            {
                using (var configFile = new TemporaryFile())
                {
                    configFile.Write(pipelineConfiguration);
                    ConfigurationBuilder builder = new ConfigurationBuilder();
                    builder.AddJsonFile(configFile.FilePath);
                    var configuration = builder.Build();

                    using (var pipeline = DiagnosticPipelineFactory.CreatePipeline(configuration))
                    {
                        Assert.NotNull(pipeline);

                        Assert.Single(pipeline.Inputs);
                        var eventSourceInput = pipeline.Inputs.First() as EventSourceInput;
                        Assert.NotNull(eventSourceInput);

                        var expectedEventSources = new EventSourceConfiguration[3];
                        expectedEventSources[0] = new EventSourceConfiguration {
                            ProviderName = "Microsoft-ServiceFabric-Services"
                        };
                        expectedEventSources[1] = new EventSourceConfiguration {
                            ProviderName = "MyCompany-AirTrafficControlApplication-Frontend"
                        };
                        // Microsoft-ApplicationInsights-Data is disabled by default to work around https://github.com/dotnet/coreclr/issues/14434
                        expectedEventSources[2] = new EventSourceConfiguration {
                            DisabledProviderNamePrefix = "Microsoft-ApplicationInsights-Data"
                        };
                        Assert.True(eventSourceInput.EventSources.SequenceEqual(expectedEventSources));

                        var metadata = new EventMetadata("importance");
                        metadata.Properties.Add("importance", "can be discarded");
                        var metadataFilter = new EventMetadataFilter(metadata);
                        metadataFilter.IncludeCondition = "Level == Verbose";
                        Assert.True(pipeline.GlobalFilters.Count == 1);
                        Assert.True(pipeline.GlobalFilters.First().Equals(metadataFilter));

                        Assert.Single(pipeline.Sinks);
                        EventSink sink = pipeline.Sinks.First();

                        var stdSender = sink.Output as StdOutput;
                        Assert.NotNull(stdSender);

                        metadata = new EventMetadata("metric");
                        metadata.Properties.Add("metricName", "StatefulRunAsyncFailure");
                        metadata.Properties.Add("metricValue", "1.0");
                        metadataFilter = new EventMetadataFilter(metadata);
                        metadataFilter.IncludeCondition = "ProviderName == Microsoft-ServiceFabric-Services && EventName == StatefulRunAsyncFailure";

                        Assert.True(sink.Filters.Count == 1);
                        Assert.True(sink.Filters.First().Equals(metadataFilter));
                    }
                }
            }
            finally
            {
                TryDeleteFile(CsvHealthReporter.DefaultLogFilePrefix);
            }
        }
コード例 #2
0
        static void Main(string[] args)
        {
            var healthReporter = new BenchmarkHealthReporter();

            var esConfiguration = new EventSourceConfiguration();

            esConfiguration.ProviderName = "Microsoft-AzureTools-BenchmarkEventSource";
            var eventSourceInput = new EventSourceInput(new EventSourceConfiguration[] { esConfiguration }, healthReporter);

            var metadata = new EventMetadata("importantEvent");

            metadata.Properties.Add("Importance", "High");
            EventMetadataFilter metadataFilter = new EventMetadataFilter(metadata);

            metadataFilter.IncludeCondition = "name==ImportantEvent";

            var oddSequenceNumberFilter  = new CallbackFilter((e) => HasLongPropertyWhere(e.Payload, "sequenceNumber", (n) => (n & 0x1) != 0));
            var evenSequenceNumberFilter = new CallbackFilter((e) => HasLongPropertyWhere(e.Payload, "sequenceNumber", (n) => (n & 0x1) == 0));
            var oddSequenceNumberOutput  = new BenchmarkOutput("Odd sequence number output");
            var evenSequenceNumberOutput = new BenchmarkOutput("Even sequence number output");
            var sinks = new EventSink[]
            {
                new EventSink(oddSequenceNumberOutput, new IFilter[] { oddSequenceNumberFilter }),
                new EventSink(evenSequenceNumberOutput, new IFilter[] { evenSequenceNumberFilter })
            };

            var configuration = new DiagnosticPipelineConfiguration();

            configuration.PipelineCompletionTimeoutMsec = Convert.ToInt32(CoolDownTime.TotalMilliseconds);
            var pipeline = new DiagnosticPipeline(
                healthReporter,
                new IObservable <EventData>[] { eventSourceInput },
                new IFilter[] { metadataFilter },
                sinks,
                configuration);

            Console.WriteLine(string.Format("Starting test... will take {0} seconds", (WarmUpTime + MeasurementTime).TotalSeconds));
            Console.WriteLine("A dot represents 10 000 events submitted");

            DateTimeOffset startTime            = DateTimeOffset.Now;
            DateTimeOffset measurementStartTime = startTime + WarmUpTime;
            DateTimeOffset measurementStopTime  = measurementStartTime + MeasurementTime;
            DateTimeOffset stopTime             = measurementStopTime + CoolDownTime;

            bool debugMode = args.Length == 1 && string.Equals(args[0], "debug", StringComparison.OrdinalIgnoreCase);

            long eventSequenceNo    = 1;
            bool measuring          = debugMode;
            long measuredEventCount = 0;

            while (true)
            {
                // Every tenth event is important
                string name = "RegularEvent";
                if (eventSequenceNo % 10 == 0)
                {
                    name = "ImportantEvent";
                }

                BenchmarkEventSource.Log.ComplexMessage(
                    Guid.NewGuid(),
                    Guid.NewGuid(),
                    eventSequenceNo++,
                    name,
                    DateTime.Now,
                    DateTime.UtcNow,
                    "Complex event message. blah blah");

                if (measuring)
                {
                    measuredEventCount++;
                }

                if (debugMode)
                {
                    if (measuredEventCount == 10)
                    {
                        break;
                    }
                }
                else
                {
                    if (eventSequenceNo % EventBatchSize == 0)
                    {
                        DateTimeOffset now = DateTimeOffset.Now;

                        // In this benchmmark we do not really have a cooldown period, so we do not have to account for not-measuring period at the end.
                        if (!measuring)
                        {
                            bool shouldBeMeasuring = (now >= measurementStartTime && now < measurementStopTime);
                            if (shouldBeMeasuring)
                            {
                                oddSequenceNumberOutput.ResetCounter();
                                evenSequenceNumberOutput.ResetCounter();
                                healthReporter.ResetCounters();
                                measuring = true;
                            }
                        }


                        if (eventSequenceNo % 10000 == 0)
                        {
                            Console.Write(".");
                        }

                        if (now >= stopTime)
                        {
                            break;
                        }
                    }
                }
            }

            Console.WriteLine(string.Empty);
            Console.WriteLine("Enterning cooldown period...");
            Thread.Sleep(CoolDownTime);
            pipeline.Dispose();

            Console.WriteLine(string.Empty);
            Console.WriteLine($"Total events raised during measurement period: {measuredEventCount}");
            Console.WriteLine(oddSequenceNumberOutput.Summary);
            Console.WriteLine(evenSequenceNumberOutput.Summary);
            double processingRate = (oddSequenceNumberOutput.EventCount + evenSequenceNumberOutput.EventCount) / MeasurementTime.TotalSeconds;

            Console.WriteLine($"Processing rate (events/sec): {processingRate}");
            Console.WriteLine(healthReporter.Summary);

            Console.WriteLine("Press any key to exit");
            Console.ReadKey(intercept: true);
        }