PragmaticFlow / NBomber

Modern and flexible load testing framework for Pull and Push scenarios, designed to test any system regardless a protocol (HTTP/WebSockets/AMQP etc) or a semantic model (Pull/Push).
https://nbomber.com
Other
2.07k stars 131 forks source link

Logging API response and custom messages to reports and log files #698

Open priyankamohile opened 2 months ago

priyankamohile commented 2 months ago

Hello,

I'm currently using NBomber version 4.1.2 to load test my web application. I wish to load test APIs, with the below parameters logged -

The code I am using is as follows, with the string 'apiResponse' being the message that I wish to include in my NBomber logs. Is there any way of achieving this requirement?

static void Main(string[] args)
{
    var httpClient = new HttpClient();
    var apiResponse = "";

    var scenario = Scenario.Create("hello_world_scenario", async context =>
    {            
        var request =
            Http.CreateRequest("GET", "http://localhost/myapp/performance");

        var response = await Http.Send(httpClient, request);
        apiResponse = response.Payload.Value.Content.ReadAsStringAsync().Result;
        return response;
    })
    .WithoutWarmUp()
    .WithLoadSimulations(
        //Adjust the rate depending on the number of requests you wish to fire.
        Simulation.Inject(rate: 100,
                          interval: TimeSpan.FromSeconds(1),
                          during: TimeSpan.FromSeconds(30))
    );

    NBomberRunner
        .RegisterScenarios(scenario)
        .WithLoggerConfig(() =>
new LoggerConfiguration()
    .MinimumLevel.Debug()
    .WriteTo.File(
        path: "E:\\NBomber\\my-log-file.txt",
        outputTemplate:
        "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] [ThreadId:{ThreadId}] {Message:lj}{NewLine}{Exception}",
        rollingInterval: RollingInterval.Day)
        // buffered: true)

) .Run(); }

AntyaDev commented 2 months ago

Hi @priyankamohile Is it something like tracing? https://nbomber.com/docs/protocols/http#tracing-http-requests

priyankamohile commented 2 months ago

Hi @priyankamohile Is it something like tracing? https://nbomber.com/docs/protocols/http#tracing-http-requests

Hi @AntyaDev , Yes, my requirement is similar to the above ask. Basically, we are load balancing our API calls and have multiple servers set up, the requests can flow to any of these servers. I'm looking at monitoring how many requests went to each of these servers.

AntyaDev commented 2 months ago

@priyankamohile If it's about calculating how many requests each server handled, would it be possible to use a status code? For example:

return Response.Ok(statusCode: "OK server 1")

or if the response from server 2

return Response.Ok(statusCode: "OK server 2")