Skip to content

Commit

Permalink
#188509201 [Part 3 of 3] : Updated example and tests. Moved deprecate…
Browse files Browse the repository at this point in the history
…d 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.
  • Loading branch information
praves77 authored Dec 16, 2024
1 parent 44600e7 commit 590590e
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 12 deletions.
4 changes: 2 additions & 2 deletions MoesifNet6Example/Controllers/EmployeeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
7 changes: 6 additions & 1 deletion MoesifNet6Example/LambdaEntryPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ public override async Task<APIGatewayProxyResponse> 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;

Expand Down Expand Up @@ -98,7 +103,7 @@ public override async Task<APIGatewayProxyResponse> 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;
Expand Down
9 changes: 7 additions & 2 deletions MoesifNet6Example/MoesifNet6Example.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,16 @@
<PackageReference Include="Amazon.Lambda.AspNetCoreServer" Version="9.0.0" />
<PackageReference Include="Amazon.Lambda.Core" Version="2.2.0" />
<PackageReference Include="Amazon.Lambda.RuntimeSupport" Version="1.10.0" />
<PackageReference Include="Moesif.Api" Version="3.1.1" />
<PackageReference Include="Moesif.Middleware" Version="3.1.2"/>
<!-- <PackageReference Include="Moesif.Api" Version="3.1.2" />-->
<!-- <PackageReference Include="Moesif.Middleware" Version="3.1.3"/>-->
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\moesif-dotnet\Moesif.Middleware\Moesif.Middleware.csproj" />
<ProjectReference Include="..\..\moesifapi-csharp\Moesif.Api\Moesif.Api.csproj" />
</ItemGroup>

<!-- <ItemGroup> -->
<!-- <ProjectReference Include="..\..\moesif-dotnet\Moesif.Middleware\Moesif.Middleware.csproj"> -->
<!-- <ReferenceSourceTarget></ReferenceSourceTarget> -->
Expand Down
9 changes: 6 additions & 3 deletions MoesifNet6Example/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#define MOESIF_INSTRUMENT
// #define MOESIF_INSTRUMENT

using System;
using System.Collections.Generic;
Expand All @@ -19,6 +19,7 @@ namespace MoesifNet6Example
{
public class Startup
{
public static int counter = 0;
public IConfiguration Configuration { get; private set; }

public Startup(IConfiguration configuration)
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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())
{
Expand All @@ -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)
// {
Expand Down
8 changes: 4 additions & 4 deletions MoesifNet6Example/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
"MoesifOptions": {
"IsMoesifEnabled": true,
"MyTag": "ILT_Org_PK_App",
"ApplicationId": "<MOESIF_APPLICATION_ID>",
"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
Expand All @@ -23,4 +23,4 @@
},
"AllowedHosts": "*"
}


0 comments on commit 590590e

Please sign in to comment.