Skip to main content

JSON Config

NBomber configuration system provides a way to configure NBomber load tests via JSON files. It's quite helpful when you want to run NBomber tests under different environments or workload profiles. NBomber supports two types of JSON config:

  • JSON Config - This configuration file is used to override some of the Scenario settings related to execution. For example: LoadSimulations, WarmUpDuration, TargetScenarios, etc.
  • JSON Infrastracture Config - This configuration file allows the overriding settings related only to infrastructure: Logger(s), ReportingSink(s) and WorkerPlugin(s).

JSON Config

JSON Config file is used to override some of the Scenario settings.

info

JSON Config file has higher priority over code configuration. For example, if you specified WarmUpDuration in both: code and the config file, NBomber will take the value from the config file.

To load JSON Config, you can use:

  • Local file path to your JSON Config.
NBomberRunner
.RegisterScenarios(scenario)
.LoadConfig("config.json")
.Run();
  • HTTP URL
NBomberRunner
.RegisterScenarios(scenario)
.LoadConfig("https://my-test-host.com/config.json")
.Run();
  • CLI argument "--config" or "-c"
MyLoadTest.dll --config="config.json"

Overriding settings via JSON

This is a complete JSON Config example that you can use to override the settings you wish. In addition to JSON Config, you will find a corresponding C#(on the C# tab) code example that shows all settings that JSON Config will override. Also, consider how CustomSettings and GlobalCustomSettings will be passed and loaded inside the C# example.

config.json
{
"TestSuite": "gitter.io",
"TestName": "test_http_api",

"TargetScenarios": ["test_youtube"],

"GlobalSettings": {

"ScenariosSettings": [
{
"ScenarioName": "test_youtube",
"WarmUpDuration": "00:00:02",

"LoadSimulationsSettings": [
{ "RampingConstant": [2, "00:00:02"] },
{ "KeepConstant": [2, "00:00:02"] },
{ "RampingInject": [2, "00:00:01", "00:00:02"] },
{ "Inject": [2, "00:00:01", "00:00:02"] }
],

"CustomSettings": {
"MyTestField": "localhost",
"MyPauseMs": 100
},

"MaxFailCount": 500
}
],

"GlobalCustomSettings": {
"ConnectionString": "my_db_connection_string"
},

"ReportFileName": "custom_report_name",
"ReportFolder": "./my_reports",
"ReportFormats": ["Html", "Txt"],
"ReportingInterval": "00:00:30"
}
}

You can find the complete example by this link.

JSON Infrastracture Config

This configuration file allows the overriding settings related only to infrastructure: Logger(s), ReportingSink(s) and WorkerPlugin(s).

info

JSON Infrastracture Config file has higher priority over code configuration.

To load JSON Infrastracture Config, you can use:

  • Local file path to your JSON Infrastracture Config.
NBomberRunner
.RegisterScenarios(scenario)
.LoadInfraConfig("infra-config.json")
.Run();
  • HTTP URL
NBomberRunner
.RegisterScenarios(scenario)
.LoadInfraConfig("https://my-test-host.com/infra-config.json")
.Run();
  • CLI argument "--infra" or "-i"
MyLoadTest.dll --infra="infra-config.json"

This is an example of JSON Infrastracture Config.

infra-config.json
{
"Serilog": {
"WriteTo": [{
"Name": "Elasticsearch",
"Args": {
"nodeUris": "http://localhost:9200",
"indexFormat": "nbomber-index-{0:yyyy.MM}"
}
}]
},

"PingPlugin": {
"Hosts": ["jsonplaceholder.typicode.com"],
"BufferSizeBytes": 32,
"Ttl": 128,
"DontFragment": false,
"Timeout": 1000
},

"InfluxDBSink": {
"Url": "http://localhost:8086",
"Database": "nbomber",
"UserName": "",
"Password": "",
"Token": "",
"CustomTags": [{"Key": "environment", "Value": "linux"}]
}
}

You can find the complete example by this link.