Collect errors with Gatling?
Asked Answered
S

2

6

In my long, but simple awesome Gatling simulation, I have few responses that ended with error 500. Is it possible to tell gatling to collect these error responses messages in a file during the simulation?

Silva answered 5/2, 2015 at 9:3 Comment(0)
D
2

No in production mode. You only have them when debug logging is enabled.

Dacca answered 5/2, 2015 at 18:23 Comment(0)
P
2

It is possible to collect what ever you want and save it into simulation.log file. Use extraInfoExtractor method when you define protocol:

val httpProtocol = http
    .baseURL(url)
    .check(status.is(successStatus))
    .extraInfoExtractor { extraInfo => List(getExtraInfo(extraInfo)) }

Then define in your getExtraInfo(extraInfo: ExtraInfo) method whatever criteria you want. Example bellow outputs request and response in case of debug is enables via Java System Property OR response code is not 200 OR status of request is KO (it can be KO if you have setup some max time and this max time gets increased)

private val successStatus: Int = 200
private val isDebug = System.getProperty("debug").toBoolean   
private def getExtraInfo(extraInfo: ExtraInfo): String = {
    if (isDebug
        || extraInfo.response.statusCode.get != successStatus
        || extraInfo.status.eq(Status.valueOf("KO"))) {
        ",URL:" + extraInfo.request.getUrl +
            " Request: " + extraInfo.request.getStringData +
            " Response: " + extraInfo.response.body.string
    } else {
        ""
    }
}
Plier answered 9/2, 2016 at 9:25 Comment(1)
It's good solution for version 2.x but it not supported in gatling 3.xMongoloid

© 2022 - 2024 — McMap. All rights reserved.