From 38bf3f3a83eee996dc489643121bd2a472035cfb Mon Sep 17 00:00:00 2001 From: Timothy Mothra Lee Date: Mon, 26 Feb 2024 18:48:27 -0800 Subject: [PATCH] use Demo for testing. REVERT THIS BEFORE MERGING --- ...re.Monitor.OpenTelemetry.AspNetCore.csproj | 6 +-- .../Program.cs | 54 ++++++++++++++++++- 2 files changed, 56 insertions(+), 4 deletions(-) diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.AspNetCore/src/Azure.Monitor.OpenTelemetry.AspNetCore.csproj b/sdk/monitor/Azure.Monitor.OpenTelemetry.AspNetCore/src/Azure.Monitor.OpenTelemetry.AspNetCore.csproj index 362958bcedd19..8578206e1adbb 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.AspNetCore/src/Azure.Monitor.OpenTelemetry.AspNetCore.csproj +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.AspNetCore/src/Azure.Monitor.OpenTelemetry.AspNetCore.csproj @@ -1,4 +1,4 @@ - + An OpenTelemetry .NET distro that exports to Azure Monitor AzureMonitor OpenTelemetry ASP.NET Core Distro @@ -24,11 +24,11 @@ - + - + diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.AspNetCore/tests/Azure.Monitor.OpenTelemetry.AspNetCore.Demo/Program.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.AspNetCore/tests/Azure.Monitor.OpenTelemetry.AspNetCore.Demo/Program.cs index 949139bc44f3f..f833d52fa7a2b 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.AspNetCore/tests/Azure.Monitor.OpenTelemetry.AspNetCore.Demo/Program.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.AspNetCore/tests/Azure.Monitor.OpenTelemetry.AspNetCore.Demo/Program.cs @@ -2,16 +2,21 @@ // Licensed under the MIT License. #if NET6_0_OR_GREATER +using System; using System.Diagnostics; using System.Net.Http; +using System.Threading.Tasks; +using System.Threading; using Azure.Monitor.OpenTelemetry.AspNetCore; using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; +CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(); + var builder = WebApplication.CreateBuilder(args); -builder.Services.AddOpenTelemetry().UseAzureMonitor(); +//builder.Services.AddOpenTelemetry().UseAzureMonitor(); /* builder.Services.AddOpenTelemetry().UseAzureMonitor(o => @@ -33,5 +38,52 @@ return $"Hello World! OpenTelemetry Trace: {Activity.Current?.Id}"; }); +#if !NETFRAMEWORK +app.MapGet("/StressTest", () => +{ + RunStressTest(); + return "StressTest!"; +}); +#endif + app.Run(); #endif + +#if !NETFRAMEWORK +void RunStressTest() +{ + // Get the number of available processors + int numProcessors = Environment.ProcessorCount; + + Task[] tasks = new Task[numProcessors]; + + // Start each task + for (int i = 0; i < numProcessors; i++) + { + tasks[i] = Task.Run(() => Compute(cancellationTokenSource.Token)); + } + + var timeStamp = DateTime.Now.AddSeconds(20); + while (DateTime.Now < timeStamp) + { + // do nothing + } + + cancellationTokenSource.Cancel(); + + Task.WaitAll(tasks); +} + +void Compute(CancellationToken cancellationToken) +{ + while (!cancellationToken.IsCancellationRequested) + { + // Simulate intensive computation + double result = 0; + for (int i = 0; i < 1000000; i++) + { + result += Math.Sqrt(i); + } + } +} +#endif