Skip to content

Commit

Permalink
Refactored metrics as CSV for easy collection. Also added a few more …
Browse files Browse the repository at this point in the history
…api for 75 / 150 kb response body size payload tests.
  • Loading branch information
praves77 committed Dec 6, 2024
1 parent 4b68aa1 commit 5682ea0
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 6 deletions.
10 changes: 10 additions & 0 deletions LambdaExtension/LambdaExtension.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
86 changes: 84 additions & 2 deletions MoesifNet6Example/Controllers/EmployeeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,114 @@
using Microsoft.AspNetCore.Mvc;
using System.Net.Http;
using MoesifNet6Example.Models;
using System.Threading;

namespace MoesifNet6Example.Controllers
{
[Route("api/[controller]")]
public class EmployeeController : ControllerBase
{
private const int MAX_SIZE_75_KB = 75;
private const int MAX_SIZE_150_KB = 150;

public EmployeeController()
{
Console.WriteLine("EmployeeController constructor called");
}

private static string GenerateLargeResponseBody(int sizeInKB)
{
const string baseString = "This is a test string. ";
int repetitions = (sizeInKB * 1024); // / baseString.Length;
return new string('A', repetitions); // Create a large string filled with 'A's
}

[HttpGet("{id}")]
public IActionResult GetByID(int id)
{
Console.WriteLine($"BEGIN: EmployeeController GetByID method called with id: {id}");
var employee = new Employee()
{
ID = id,
FirstName = "firstName",
FirstName = "No Delay",
LastName = "Very Long LastName From Moesif for API Awesomeness of Moesif",
DateOfBirth = DateTime.Now.AddYears(-30)
};

Console.WriteLine($"END : Employee object created: {employee.ID}, {employee.FirstName}, {employee.LastName}");

return Ok(employee);
}

[HttpGet("delay_random/{id}")]
public IActionResult GetEventId(int id)
{
var employee = new Employee()
{
ID = id,
FirstName = $"Get-Event-{id}",
LastName = $"Delayed-By-{id}-MS",
DateOfBirth = DateTime.Now.AddYears(-30)
};

Thread.Sleep(id); // Sleeps for id milliseconds

return Ok(employee);
}

[HttpGet("payload75/{id}")]
public IActionResult GetNotificationId(int id)
{
int sleepTime = 100;
string firstName = $"Get-{id}-{MAX_SIZE_75_KB}-KB-{sleepTime}-MS";
string lastName = $"Delayed-By-{sleepTime}-MS";
if (id > 10)
{
lastName = GenerateLargeResponseBody(MAX_SIZE_75_KB);
}
var employee = new Employee()
{
ID = id,
FirstName = firstName,
LastName = lastName,
DateOfBirth = DateTime.Now.AddYears(-30)
};

Thread.Sleep(sleepTime); // Sleeps for id milliseconds

return Ok(employee);
}

[HttpGet("payload150/{id}")]
public IActionResult GetSubsId(int id)
{
int sleepTime = 100; // in ms
string firstName = $"Get-{id}-{MAX_SIZE_150_KB}-KB-{sleepTime}-MS";
string lastName = $"Delayed-By-{sleepTime}-MS";
if (id > 10)
{
lastName = GenerateLargeResponseBody(MAX_SIZE_150_KB);
}

var employee = new Employee()
{
ID = id,
FirstName = firstName,
LastName = lastName,
DateOfBirth = DateTime.Now.AddYears(-30)
};

Thread.Sleep(sleepTime); // Sleeps for id milliseconds

return Ok(employee);
}


[HttpPost]
public IActionResult Post([FromBody] Employee employee)
{

Console.WriteLine("Post method called");

return Ok(employee);
}
}
Expand Down
4 changes: 2 additions & 2 deletions MoesifNet6Example/MoesifNet6Example.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
<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="Microsoft.Owin" Version="4.2.2" /> -->
<!-- <PackageReference Include="Moesif.Middleware" Version="3.1.0"/>-->
<!-- <PackageReference Include="Moesif.Api" Version="3.1.0" />-->
<!-- <PackageReference Include="Moesif.Middleware" Version="3.1.1"/>-->
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
</ItemGroup>

Expand Down
17 changes: 15 additions & 2 deletions MoesifNet6Example/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define MOESIF_INSTRUMENT

using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Builder;
Expand Down Expand Up @@ -29,6 +31,9 @@ public void ConfigureServices(IServiceCollection services)

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
#if MOESIF_INSTRUMENT
Console.WriteLine($"Begin: Configure");
#endif
MoesifOptions mo = new MoesifOptions(Configuration);
ensureValidConfig(mo);
app.UseMiddleware<MoesifMiddleware>(mo.getMoesifOptions());
Expand All @@ -37,20 +42,28 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseDeveloperExceptionPage();
}

#if MOESIF_INSTRUMENT
Console.WriteLine($"Before: Configure / UseRouting");
#endif
app.UseRouting();

app.UseEndpoints(endpoints =>
{
endpoints.MapGet("/", async context =>
{
await context.Response.WriteAsync("Hello World!");
var msg = "Hello World!";
Console.WriteLine($"Hit the home page: {msg}");
await context.Response.WriteAsync(msg);
});

endpoints.MapControllerRoute(
name: "api",
pattern: "{controller}/{id}");
});

#if MOESIF_INSTRUMENT
Console.WriteLine($"End: Configure");
#endif
}

private static void ensureValidConfig(MoesifOptions mo)
Expand Down

0 comments on commit 5682ea0

Please sign in to comment.