From 590590e410758c79a370ffd4eebd981bd32d8a7d Mon Sep 17 00:00:00 2001 From: Praves Date: Sun, 15 Dec 2024 23:24:44 -0800 Subject: [PATCH] #188509201 [Part 3 of 3] : Updated example and tests. Moved deprecated examples under sub-folder. (#47) * Moved deprecated examples to depcrecated folder * Configuration based ability to enable/disable moesif to avoid rebuilding app for perf-testing. Added more endpoints. * Support for IfMoesifEnabled + CounterBased apiEndPoint testing to use payload if id is > 10000. * Cleanup + Use Latest Version. * Cleanup + Use Latest Version. --- MoesifNet6Example/Controllers/EmployeeController.cs | 4 ++-- MoesifNet6Example/LambdaEntryPoint.cs | 7 ++++++- MoesifNet6Example/MoesifNet6Example.csproj | 9 +++++++-- MoesifNet6Example/Startup.cs | 9 ++++++--- MoesifNet6Example/appsettings.json | 8 ++++---- 5 files changed, 25 insertions(+), 12 deletions(-) diff --git a/MoesifNet6Example/Controllers/EmployeeController.cs b/MoesifNet6Example/Controllers/EmployeeController.cs index 95347e2..7fc3848 100644 --- a/MoesifNet6Example/Controllers/EmployeeController.cs +++ b/MoesifNet6Example/Controllers/EmployeeController.cs @@ -109,7 +109,7 @@ public IActionResult GetNotificationId(int id) int sleepTime = 8000; // random.Next(1, 101); // 300 - 9000 var size = 1; string lastName = $"Delayed-By-{sleepTime}-MS"; - if (id > 10) + if (id > 10000) { size = MAX_SIZE_75_KB; lastName = GenerateLargeResponseBody(MAX_SIZE_75_KB); @@ -135,7 +135,7 @@ public IActionResult GetSubsId(int id) int sleepTime = 3500; // random.Next(1, 101); // 300 - 4000 var size = 1; string lastName = $"Delayed-By-{sleepTime}-MS"; - if (id > 10) + if (id > 10000) { size = MAX_SIZE_150_KB; lastName = GenerateLargeResponseBody(MAX_SIZE_150_KB); diff --git a/MoesifNet6Example/LambdaEntryPoint.cs b/MoesifNet6Example/LambdaEntryPoint.cs index 6c02f7a..b3893cc 100644 --- a/MoesifNet6Example/LambdaEntryPoint.cs +++ b/MoesifNet6Example/LambdaEntryPoint.cs @@ -53,6 +53,11 @@ public override async Task FunctionHandlerAsync(APIGate stopwatch.Start(); long dbgTime = 0; + var hdr = $"AwsRequestId, InvokedFunctionArn, RemainingTime, LogGroupName"; + var msg = $"{lambdaContext.AwsRequestId}, {lambdaContext.InvokedFunctionArn}, {lambdaContext.RemainingTime}, {lambdaContext.LogGroupName}"; + _logger.LogInformation(hdr); + _logger.LogInformation(msg); + _logger.LogInformation($"Enter handler FunctionHandlerAsync Iteration - {invovationCount}"); invovationCount += 1; @@ -98,7 +103,7 @@ public override async Task FunctionHandlerAsync(APIGate // }; dbgTime = stopwatch.ElapsedMilliseconds; - _logger.LogInformation($"EXITING handler FunctionHandlerAsync ExecutionTime - {dbgTime}ms", dbgTime); + _logger.LogInformation($"EXITING handler moesifEnable = true FunctionHandlerAsync ExecutionTime - {dbgTime}ms", dbgTime); stopwatch.Stop(); #endif return response; diff --git a/MoesifNet6Example/MoesifNet6Example.csproj b/MoesifNet6Example/MoesifNet6Example.csproj index 46914ce..198ef28 100644 --- a/MoesifNet6Example/MoesifNet6Example.csproj +++ b/MoesifNet6Example/MoesifNet6Example.csproj @@ -23,11 +23,16 @@ - - + + + + + + + diff --git a/MoesifNet6Example/Startup.cs b/MoesifNet6Example/Startup.cs index 17c2e11..9138c27 100644 --- a/MoesifNet6Example/Startup.cs +++ b/MoesifNet6Example/Startup.cs @@ -1,4 +1,4 @@ -#define MOESIF_INSTRUMENT +// #define MOESIF_INSTRUMENT using System; using System.Collections.Generic; @@ -19,6 +19,7 @@ namespace MoesifNet6Example { public class Startup { + public static int counter = 0; public IConfiguration Configuration { get; private set; } public Startup(IConfiguration configuration) @@ -34,6 +35,7 @@ public void ConfigureServices(IServiceCollection services) public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { + counter += 1; #if MOESIF_INSTRUMENT Console.WriteLine($"Begin: Configure"); #endif @@ -42,7 +44,6 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) var msg = ""; MoesifOptions mo = new MoesifOptions(Configuration); ensureValidConfig(mo); - isLambda = mo.IsLambda(); isMoesifEnabled = mo.IsMoesifEnabled(); if (isMoesifEnabled) @@ -55,6 +56,8 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) msg = $"++++++ Moesif is Disabled because [IsMoesifEnabled = {isMoesifEnabled}] and [IsLambda = {isLambda}]"; } Console.WriteLine($"{msg}"); + string isoUtcDateString = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssZ"); + Console.WriteLine($"[{isoUtcDateString}] **** Moesif-INIT = [{counter}]"); if (env.IsDevelopment()) { @@ -69,7 +72,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { endpoints.MapGet("/", async context => { - var msg = $"Hello World! isLambda = {isLambda}"; + var msg = $"Hello World! isLambda = {isLambda}"; Console.WriteLine($"Hit the home page: {msg}"); // if (isLambda) // { diff --git a/MoesifNet6Example/appsettings.json b/MoesifNet6Example/appsettings.json index 948d3c2..b30a137 100644 --- a/MoesifNet6Example/appsettings.json +++ b/MoesifNet6Example/appsettings.json @@ -2,13 +2,13 @@ "MoesifOptions": { "IsMoesifEnabled": true, "MyTag": "ILT_Org_PK_App", - "ApplicationId": "", + "ApplicationId": "eyJhcHAiOiIyODU6NTY4IiwidmVyIjoiMi4xIiwib3JnIjoiNjQwOjEyOCIsImlhdCI6MTczMzAxMTIwMH0.L9S2iwcLjeBL-HC7mFFXZyJCgQV8QiBZ9GNbPiCMXGA", "LocalDebug": false, - "LogBody": true, + "LogBody": false, "RequestMaxBodySize": 100000, "ResponseMaxBodySize": 100000, "LogBodyOutgoing": true, - "ApiVersion": "3.1.2", + "ApiVersion": "3.1.3", "EnableBatching": true, "BatchSize": 1, "IsLambda": true @@ -23,4 +23,4 @@ }, "AllowedHosts": "*" } - + \ No newline at end of file