Skip to content

Commit d1f4750

Browse files
committed
Added NBomber_Studio reporting example
1 parent 940943d commit d1f4750

File tree

5 files changed

+98
-1
lines changed

5 files changed

+98
-1
lines changed

examples/Demo/Demo.csproj

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@
4141
<None Update="Features\Thresholds\nbomber-config.json">
4242
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
4343
</None>
44+
<None Update="NBomber Studio\infra-config.json">
45+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
46+
</None>
47+
<None Update="NBomber_Studio\infra-config.json">
48+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
49+
</None>
4450
</ItemGroup>
4551

4652
<ItemGroup>
@@ -65,7 +71,7 @@
6571
<PackageReference Include="NBomber.Data" Version="5.0.0" />
6672
<PackageReference Include="NBomber.Http" Version="5.2.0" />
6773
<PackageReference Include="NBomber.MQTT" Version="0.2.0" />
68-
<PackageReference Include="NBomber.Sinks.Timescale" Version="0.6.0" />
74+
<PackageReference Include="NBomber.Sinks.Timescale" Version="0.6.1" />
6975
<PackageReference Include="NBomber.WebBrowser" Version="0.1.0" />
7076
<PackageReference Include="NBomber.WebSockets" Version="0.1.0" />
7177
<PackageReference Include="NBomber.Sinks.InfluxDB" Version="5.1.0" />
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using NBomber.CSharp;
2+
using NBomber.Sinks.Timescale;
3+
4+
namespace Demo.NBomber_Studio;
5+
6+
public class NBomberStudioReportingExample
7+
{
8+
// this reporting sink will save stats data into TimescaleDB.
9+
private readonly TimescaleDbSink _timescaleDbSink = new();
10+
11+
public void Run()
12+
{
13+
var scenario = Scenario.Create("user_flow_scenario", async context =>
14+
{
15+
var step1 = await Step.Run("login", context, async () =>
16+
{
17+
await Task.Delay(500);
18+
return Response.Ok(sizeBytes: 10, statusCode: "200");
19+
});
20+
21+
var step2 = await Step.Run("get_product", context, async () =>
22+
{
23+
await Task.Delay(1000);
24+
return Response.Ok(sizeBytes: 20, statusCode: "200");
25+
});
26+
27+
var step3 = await Step.Run("buy_product", context, async () =>
28+
{
29+
await Task.Delay(2000);
30+
return Response.Ok(sizeBytes: 30, statusCode: "200");
31+
});
32+
33+
return Response.Ok(statusCode: "201");
34+
})
35+
.WithWarmUpDuration(TimeSpan.FromSeconds(3))
36+
.WithLoadSimulations(
37+
Simulation.RampingInject(rate: 200, interval: TimeSpan.FromSeconds(1), during: TimeSpan.FromMinutes(1)), // rump-up to rate 200
38+
Simulation.Inject(rate: 200, interval: TimeSpan.FromSeconds(1), during: TimeSpan.FromSeconds(30)), // keep injecting with rate 200
39+
Simulation.RampingInject(rate: 0, interval: TimeSpan.FromSeconds(1), during: TimeSpan.FromMinutes(1)) // rump-down to rate 0
40+
);
41+
42+
NBomberRunner
43+
.RegisterScenarios(scenario)
44+
.LoadInfraConfig("NBomber_Studio/infra-config.json")
45+
.WithReportingSinks(_timescaleDbSink)
46+
.WithTestSuite("reporting")
47+
.WithTestName("timescale_db_demo")
48+
.Run();
49+
}
50+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
services:
2+
3+
timescaledb:
4+
image: timescale/timescaledb:2.14.2-pg16
5+
command: postgres -c 'max_connections=500'
6+
restart: always
7+
ports:
8+
- "5432:5432"
9+
volumes:
10+
- nb_studio_data:/var/lib/postgresql/data
11+
environment:
12+
POSTGRES_DB: nb_studio_db
13+
POSTGRES_USER: timescaledb
14+
POSTGRES_PASSWORD: timescaledb
15+
healthcheck:
16+
test: [ "CMD-SHELL", "pg_isready -d 'user=timescaledb dbname=nb_studio_db'" ]
17+
interval: 5s
18+
timeout: 10s
19+
retries: 5
20+
start_period: 5s
21+
22+
nbomber-studio:
23+
image: nbomberdocker/nbomber-studio:latest
24+
ports:
25+
- "5333:8080"
26+
depends_on:
27+
timescaledb:
28+
condition: service_healthy
29+
environment:
30+
DBSETTINGS:CONNECTIONSTRING: "Host=timescaledb;Port=5432;Username=timescaledb;Password=timescaledb;Database=nb_studio_db;Pooling=true;"
31+
32+
volumes:
33+
nb_studio_data:
34+
driver: local
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"TimescaleDbSink":{
3+
"ConnectionString": "Host=localhost;Port=5432;Database=nb_studio_db;Username=timescaledb;Password=timescaledb;Pooling=true;Maximum Pool Size=300;"
4+
}
5+
}

examples/Demo/Program.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
using Demo.HTTP.WebAppSimulator;
2323
using Demo.HTTP.SimpleBookstore;
2424
using Demo.MQTT.ClientPool;
25+
using Demo.NBomber_Studio;
2526
using Demo.WebBrowsers.Playwright;
2627
using Demo.WebBrowsers.Puppeteer;
2728
using Demo.WebSockets;
@@ -64,6 +65,7 @@
6465
// new InfluxDBReportingExample().Run();
6566
// new TimescaleDBReportingExample().Run();
6667
// new CustomReportingExample().Run();
68+
// new NBomberStudioReportingExample().Run();
6769

6870
// ---- Logs ----
6971
// new TextFileLogger().Run();

0 commit comments

Comments
 (0)