Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added TimescaleDBReportingExample.cs #688

Merged
merged 1 commit into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions examples/Demo/Demo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
<None Update="MQTT\ClientPool\config.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Features\RealtimeReporting\TimescaleDB\infra-config.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
Expand All @@ -54,6 +57,7 @@
<PackageReference Include="NBomber.Data" Version="5.0.0" />
<PackageReference Include="NBomber.Http" Version="5.1.0" />
<PackageReference Include="NBomber.MQTT" Version="0.1.0" />
<PackageReference Include="NBomber.Sinks.Timescale" Version="0.1.0" />
<PackageReference Include="NBomber.WebSockets" Version="0.1.0" />
<PackageReference Include="NBomber.Sinks.InfluxDB" Version="5.0.2" />

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using NBomber.CSharp;
using NBomber.Sinks.Timescale;

public class TimescaleDBReportingExample
{
// 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("Features/RealtimeReporting/TimescaleDB/infra-config.json")
.WithReportingInterval(TimeSpan.FromSeconds(5))
.WithReportingSinks(_timescaleDbSink)
.WithTestSuite("reporting")
.WithTestName("timescale_db_demo")
.Run();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
services:

timescaledb:
image: timescale/timescaledb:2.14.2-pg16
restart: always
command: postgres -c 'max_connections=500'
environment:
POSTGRES_DB: timescaledb
POSTGRES_USER: timescaledb
POSTGRES_PASSWORD: timescaledb
ports:
- 5432:5432
volumes:
- metrics-data:/var/lib/postgresql/data

# grafana:
# image: grafana/grafana:10.4.2
# ports:
# - 3000:3000
# volumes:
# - grafana-data:/var/lib/grafana

pgadmin:
image: dpage/pgadmin4
restart: always
environment:
PGADMIN_DEFAULT_EMAIL: admin@admin.com
PGADMIN_DEFAULT_PASSWORD: admin
ports:
- 5051:80
volumes:
- pgadmin-data:/var/lib/pgadmin

volumes:
metrics-data:
driver: local

grafana-data:
driver: local

pgadmin-data:
driver: local
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"TimescaleDbSink":{
"ConnectionString": "Host=localhost;Port=5432;Database=timescaledb;Username=timescaledb;Password=timescaledb;Pooling=true;Maximum Pool Size=300;"
}
}
1 change: 1 addition & 0 deletions examples/Demo/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@

// ---- Real-time reporting ----
// new InfluxDBReportingExample().Run();
// new TimescaleDBReportingExample().Run();
// new CustomReportingExample().Run();

// ---- Logs ----
Expand Down
Loading