gatling 2 - Log response info only when error happens?

5,650 views
Skip to first unread message

Kan Wu

unread,
Jan 24, 2014, 4:26:34 PM1/24/14
to gat...@googlegroups.com
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

Kan Wu

unread,
Jan 24, 2014, 4:54:17 PM1/24/14
to gat...@googlegroups.com
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写道:

Stéphane Landelle

unread,
Jan 25, 2014, 4:07:53 AM1/25/14
to gat...@googlegroups.com
Yeah, you have to go with extraInfoExtractor


2014/1/24 Kan Wu <sea...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "Gatling User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gatling+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Kan Wu

unread,
Oct 23, 2014, 1:09:47 PM10/23/14
to gat...@googlegroups.com
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.

Kan Wu

unread,
Oct 23, 2014, 4:44:01 PM10/23/14
to gat...@googlegroups.com
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

Pierre DAL-PRA

unread,
Oct 23, 2014, 4:45:46 PM10/23/14
to gat...@googlegroups.com
.extraInfoExtractor {
extraInfo => 
extraInfo.status match {
case io.gatling.core.result.message.KO => 
println(extraInfo.response.body.string)
Nil
case _ => Nil
}
}

For more options, visit https://groups.google.com/d/optout.

Kan Wu

unread,
Oct 23, 2014, 4:51:33 PM10/23/14
to gat...@googlegroups.com
Good idea. This works fine. Sorry, I'm new to Scala. Thank you a lot!

Kan Wu

unread,
Oct 23, 2014, 7:32:32 PM10/23/14
to gat...@googlegroups.com
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)

Stéphane Landelle

unread,
Oct 24, 2014, 1:52:27 AM10/24/14
to gat...@googlegroups.com
See conf/logback.xml, you can just uncomment a logger there to achieve this.

Kan Wu

unread,
Oct 24, 2014, 2:01:06 AM10/24/14
to gat...@googlegroups.com
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. 

Wayne Izatt

unread,
Oct 30, 2014, 1:51:42 PM10/30/14
to gat...@googlegroups.com
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:<start>" + extraInfo.response.body.string + "</end>")
              }
            }
            Nil
          case _ => Nil
        }
    }

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

Thanks
Wayne

Stéphane Landelle

unread,
Oct 31, 2014, 5:14:50 AM10/31/14
to gat...@googlegroups.com
That probably means that your code is wrong and doesn't contain errorLable

--
You received this message because you are subscribed to the Google Groups "Gatling User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gatling+u...@googlegroups.com.

Kan Wu

unread,
Oct 31, 2014, 1:48:47 PM10/31/14
to gat...@googlegroups.com
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?

Stéphane Landelle

unread,
Nov 3, 2014, 4:34:34 PM11/3/14
to gat...@googlegroups.com

Kan Wu

unread,
Nov 3, 2014, 4:36:24 PM11/3/14
to gat...@googlegroups.com
Good idea. but will disableResponseChunksDiscarding affect overall performance?

Stéphane Landelle

unread,
Nov 3, 2014, 4:39:06 PM11/3/14
to gat...@googlegroups.com
Maybe, maybe not, it depends on your test case.

Kan Wu

unread,
Nov 3, 2014, 4:40:52 PM11/3/14
to gat...@googlegroups.com
sounds good. even if it affects performance, we can just add more load generators. Thanks for the catch!
Reply all
Reply to author
Forward
0 new messages