Skip to content

Commit

Permalink
Added NBomber_Studio reporting example
Browse files Browse the repository at this point in the history
  • Loading branch information
AntyaDev committed Nov 11, 2024
1 parent 940943d commit 9c7daca
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 1 deletion.
8 changes: 7 additions & 1 deletion examples/Demo/Demo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@
<None Update="Features\Thresholds\nbomber-config.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="NBomber Studio\infra-config.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="NBomber_Studio\infra-config.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
Expand All @@ -65,7 +71,7 @@
<PackageReference Include="NBomber.Data" Version="5.0.0" />
<PackageReference Include="NBomber.Http" Version="5.2.0" />
<PackageReference Include="NBomber.MQTT" Version="0.2.0" />
<PackageReference Include="NBomber.Sinks.Timescale" Version="0.6.0" />
<PackageReference Include="NBomber.Sinks.Timescale" Version="0.6.1" />
<PackageReference Include="NBomber.WebBrowser" Version="0.1.0" />
<PackageReference Include="NBomber.WebSockets" Version="0.1.0" />
<PackageReference Include="NBomber.Sinks.InfluxDB" Version="5.1.0" />
Expand Down
50 changes: 50 additions & 0 deletions examples/Demo/NBomber_Studio/ReportingExample.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using NBomber.CSharp;
using NBomber.Sinks.Timescale;

namespace Demo.NBomber_Studio;

public class NBomberStudioReportingExample
{
// this reporting sink will save stats data into TimescaleDB.
private readonly TimescaleDbSink _timescaleDbSink = new();

public void Run()
{
var scenario = Scenario.Create("user_flow_scenario", async context =>
{
var step1 = await Step.Run("login", context, async () =>
{
await Task.Delay(500);
return Response.Ok(sizeBytes: 10, statusCode: "200");
});
var step2 = await Step.Run("get_product", context, async () =>
{
await Task.Delay(1000);
return Response.Ok(sizeBytes: 20, statusCode: "200");
});
var step3 = await Step.Run("buy_product", context, async () =>
{
await Task.Delay(2000);
return Response.Ok(sizeBytes: 30, statusCode: "200");
});
return Response.Ok(statusCode: "201");
})
.WithWarmUpDuration(TimeSpan.FromSeconds(3))
.WithLoadSimulations(
Simulation.RampingInject(rate: 200, interval: TimeSpan.FromSeconds(1), during: TimeSpan.FromMinutes(1)), // rump-up to rate 200
Simulation.Inject(rate: 200, interval: TimeSpan.FromSeconds(1), during: TimeSpan.FromSeconds(30)), // keep injecting with rate 200
Simulation.RampingInject(rate: 0, interval: TimeSpan.FromSeconds(1), during: TimeSpan.FromMinutes(1)) // rump-down to rate 0
);

NBomberRunner
.RegisterScenarios(scenario)
.LoadInfraConfig("NBomber_Studio/infra-config.json")
.WithReportingSinks(_timescaleDbSink)
.WithTestSuite("reporting")
.WithTestName("timescale_db_demo")
.Run();
}
}
34 changes: 34 additions & 0 deletions examples/Demo/NBomber_Studio/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
services:

timescaledb:
image: timescale/timescaledb:2.14.2-pg16
command: postgres -c 'max_connections=500'
restart: always
ports:
- "5432:5432"
volumes:
- nb_studio_data:/var/lib/postgresql/data
environment:
POSTGRES_DB: nb_studio_db
POSTGRES_USER: timescaledb
POSTGRES_PASSWORD: timescaledb
healthcheck:
test: [ "CMD-SHELL", "pg_isready -d 'user=timescaledb dbname=nb_studio_db'" ]
interval: 5s
timeout: 10s
retries: 5
start_period: 5s

nbomber-studio:
image: nbomberdocker/nbomber-studio:latest
ports:
- "80:8080"
depends_on:
timescaledb:
condition: service_healthy
environment:
DBSETTINGS:CONNECTIONSTRING: "Host=timescaledb;Port=5432;Username=timescaledb;Password=timescaledb;Database=nb_studio_db;Pooling=true;"

volumes:
nb_studio_data:
driver: local
5 changes: 5 additions & 0 deletions examples/Demo/NBomber_Studio/infra-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"TimescaleDbSink":{
"ConnectionString": "Host=localhost;Port=5432;Database=nb_studio_db;Username=timescaledb;Password=timescaledb;Pooling=true;Maximum Pool Size=300;"
}
}
2 changes: 2 additions & 0 deletions examples/Demo/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using Demo.HTTP.WebAppSimulator;
using Demo.HTTP.SimpleBookstore;
using Demo.MQTT.ClientPool;
using Demo.NBomber_Studio;
using Demo.WebBrowsers.Playwright;
using Demo.WebBrowsers.Puppeteer;
using Demo.WebSockets;
Expand Down Expand Up @@ -64,6 +65,7 @@
// new InfluxDBReportingExample().Run();
// new TimescaleDBReportingExample().Run();
// new CustomReportingExample().Run();
// new NBomberStudioReportingExample().Run();

// ---- Logs ----
// new TextFileLogger().Run();
Expand Down

0 comments on commit 9c7daca

Please sign in to comment.