gatling 2 - Log response info only when error happens?

Hey Stéphane,

I want to do something like this but could not find out a complete solution.

I want to record or print response info (status, request, response content) only when an error happens, for example, 500 or 403, etc.

i know this one may work https://github.com/excilys/gatling/wiki/Gatling-2#wiki-http-misc, extraInfoExtractor(Status, Session, Request, Response) => List[Any]]

so i just add a global check in httpConf, and check status code? i dont think there is a doIf in check tho.

Any help will be appreciated.

Thanks,
Kan

how about this way:

.check(status.in(400 to 510).dontValidate.bodyString.print?)

i know i can get that by enable debug log, that will print too much other info that i dont want. and if i want both request body and response body, i guess i have to extraInfoExtractor?

在 2014年1月24日星期五UTC-8下午1时26分34秒,Kan Wu写道:

Yeah, you have to go with extraInfoExtractor

I just come back to this topic with Gatling 2.0.1

I saw there’s something like extraInfoExtractor available http://gatling.io/docs/2.0.1/http/http_protocol.html#dumping-custom-data. but I think that is only dump data to log file? What if I just want to print that in console.
I tried something like this in httpConf:

.extraInfoExtractor {
extraInfo =>
if(extraInfo.status != io.gatling.core.result.message.Status.valueOf(“OK”)) {
println(extraInfo.response)
}
}

but scala gave me error like “type mismatch; found : Unit required: List[Any]”. I think the reason is Gatling is looking for List[Any] to add to log. Any ideas how I can set the print at global level? I do not want to add this for every single request.

this is working but it prints to simulation.log:

.extraInfoExtractor {
extraInfo =>
extraInfo.status match {
case io.gatling.core.result.message.KO => List(extraInfo.response.body.string)
case _ => Nil
}
}

how can I make it print to console?

Thanks

.extraInfoExtractor {
extraInfo =>
extraInfo.status match {
case io.gatling.core.result.message.KO =>
println(extraInfo.response.body.string)
Nil
case _ => Nil
}

}

Good idea. This works fine. Sorry, I’m new to Scala. Thank you a lot!

here is some more code, this will only print out error response once if it’s the same request with the same error code.

var errorSet = scala.collection.immutable.HashSet("")

val httpConf = http
.baseURL(Properties.baseUrl)
.acceptEncodingHeader(“gzip,deflate,sdch”)
.connection(“keep-alive”)
.userAgentHeader(“Apache-HttpClient/4.2.3 (java 1.5)”)
.extraInfoExtractor {
extraInfo =>
extraInfo.status match {
case io.gatling.core.result.message.KO =>
{
var errorLabel = extraInfo.requestName+"-"+extraInfo.response.statusCode.getOrElse(“501”)
if(!errorSet.contains(errorLabel)){
errorSet += errorLabel
println("Error Label: "+errorLabel)
println(“Response Body”+extraInfo.response.body.string)
}
}
Nil
case _ => Nil
}
}

See conf/logback.xml, you can just uncomment a logger there to achieve this.

That’s not the same, it will print out much more than I need. And I just want it to be printed once. Print every time is too messy.

Hi all

I’m using the code that was posted here, but the message is only making it to the console for GET requests, not for POSTs.

The following http object is used for both POSTs and GETs:

val httpConf = http
.baseURL(Properties.baseUrl)
.userAgentHeader(“Apache-HttpClient/4.2.3 (java 1.5)”)
.extraInfoExtractor {
extraInfo =>
extraInfo.status match {
case io.gatling.core.result.message.KO =>

{
var errorLable = extraInfo.requestName + “-” + extraInfo.response.statusCode.getOrElse(“501”)
if (!errorSet.contains(errorLable)) {
errorSet += errorLable
println("Error → Label: " + errorLable)
println(“Response Body:” + extraInfo.response.body.string + “”)
}
}
Nil
case _ => Nil
}
}

I know the POSTs are getting errors, but nothing is being printed.

Thanks
Wayne

That probably means that your code is wrong and doesn’t contain errorLable

if it’s at http conf level, should that be applied to both post and get? I dont see any reason that it can only print get but not post. A possible bug in Gatling?

I suspect the chunks get discarded on your POST request.
http://gatling.io/docs/2.0.1/http/http_protocol.html?highlight=chunk%20discarding#response-chunks-discarding

Good idea. but will disableResponseChunksDiscarding affect overall performance?

Maybe, maybe not, it depends on your test case.

sounds good. even if it affects performance, we can just add more load generators. Thanks for the catch!