extraInfoExtractor in 2.0.0-RC2

Hi guys,

In case of a failed requests, I am trying to print http statuscode and request url to the console with extraInfoExtractor.

In earlier 2.0.0-SNAPSHOT versions (approximately two months ago) this code did work:

.extraInfoExtractor((String, Status, Session, Request, Response) => {
      if(Status == KO)
        println("httpCode: " + Response.statusCode + ", URL: "+ Request.getRawUrl())
        Nil
})

Then at some point in time this code failed to compile.

Currently I have migrated to version 2.0.0-RC2.

Based on http://gatling.io/docs/2.0.0-RC2/project/migration_guides/2.0.0-M3a-to-2.0.0-RC2.html?highlight=extrainfoextractor I refactored the code to

.extraInfoExtractor(ExtraInfo => {
    if(ExtraInfo.status == KO)
      println("httpCode: " + ExtraInfo.response.statusCode + ", URL: "+ ExtraInfo.request.getRawUrl())
    Nil
})

Unfortunately this results in the following compilation error:

value getRawUrl is not a member of com.ning.http.client.Request
15:04:16.427 [ERROR] i.g.a.ZincCompiler$ - println("httpCode: " + ExtraInfo.response.statusCode + ", URL: "+ ExtraInfo.request.getRawUrl())

When I google for "com.ning.http.client.Request" getRawUrl()) seems to be a valid method though: https://asynchttpclient.github.io/async-http-client/apidocs/com/ning/http/client/Request.html

Since my scala skills are limited, can somebody please help me out? Much appreciated!

Cheers

Daniel

Hi Daniel,

There has been a recent change on Async HTTP Client’s Request API, which does not appears AHC’s Javadoc since we use ATM a ‘custom’ AHC more recent that the latest published version.
getRawUrl() has been removed from the Request’s API and, if you want to have to back you can use the UriComponents exposed by the Request’s API and call toUrl() on it :

`
extraInfoExtractor(ExtraInfo => {
if(ExtraInfo.status == KO)
println("httpCode: " + ExtraInfo.response.statusCode + ", URL: "+ ExtraInfo.request.getURI().toUrl())
Nil
})

`

Hope this helps !

Cheers,

Pierre

Works like a charm, thanks!

Cheers

Daniel

You’re welcome :slight_smile:

Have fun with Gatling !

Pierre

Hi, I was tring to do the same thing. But it is confusing to me. I try to do exactly the same way, but its did not work.

My code:

val harpiaWisHTTPConf = http
.baseURL(“http://192.168.88.153:8282”)
.extraInfoExtractor(ExtraInfo => {
println("httpCode: " + ExtraInfo.response.statusCode + ", URL: "+ ExtraInfo.request.getURI().toUrl())
})
.acceptHeader(“application/json”)
.doNotTrackHeader(“1”)

The result:
ConcurrentUsers.scala:28: type mismatch;
found : Unit
required: List[Any]
15:18:11.800 [ERROR] i.g.a.ZincCompiler$ - println("httpCode: " + ExtraInfo.response.statusCode + ", URL: "+ ExtraInfo.request.getURI().toUrl())

What could be happen?? Should I import something? I am newby in Scala yet. But I am already start to study.

Since now, thanks.

Hi Everton,

extraInfoExtractor is initially meant to dump extra info the the simulation.log, produced when running Gatling, which holds the results of the simulation’s run.
So it expect a that you give it a list of “things” to dump to the simulation.log.

If the only thing you’re doing with it is a println, just add Nil after your println(…) just like Daniel did.
It means that you won’t dump any specific info to simulation.log, but your println will be executed nonetheless.

Cheers,

Pierre

Thanks Pierre. Its work now.
XD
But, in fact, what I realy need is that the “ExtraInfo.request.getURI().toUrl()” appear in the simulation.log file. The code I am using shows the url in the terminal, but did not appear in the log file.

Thanks

The list you return from extraInfoExtractor() is what gets printed (tab-delimited) in the log file. So instead of returning Nil, return List(ExtraInfo.request.getURI().toUrl())

Nice!

Thanks people! Its works.

This isn’t working for me; has it changed recently?

.extraInfoExtractor(extraInfo => List(extraInfo.request.getURI().toUrl()))

results in

value getURI is not a member of com.ning.http.client.Request

Thanks!

Do you have an IDE? With an IDE, you would get auto-completion, so you could figure out available methods.

.extraInfoExtractor(extraInfo => List(extraInfo.request.getUrl))

Well, getUrl() wasn’t actually putting the request URL in the simulation log, so I was trying getURLI.toUrl() to see if I got better results. But I just looked in the asynhttpclient code, and saw that the method is getUri, not getURI as it says here, so I think I’m all set. Thanks.

getUrl is just a shortcut method for getUri.toUrl :slight_smile:

I figured as much, but neither are putting the URL into the simulation log. :slight_smile: Do I need to update the logging config as well?

Any chance you forgot to pass your HttpProtocol to either the scenario or the setUp?

No. I’m migrating from 1.5.6 and everything else is working except that one log method. It compiles, but there is no URL in the simulation.log.

Simulation:

class GetSimulation extends Simulation {
val numUsers:Int = Integer.getInteger(“users”, 1)
val myRamp:Long = java.lang.Long.getLong(“ramp”, 0L)

val urlBase = “http://myServer.com
val httpConf = http
.warmUp(“http://myServer.com/target”)
.baseURL(urlBase)
.acceptHeader(“application/json”)
.extraInfoExtractor(extraInfo => List(extraInfo.request.getUrl))
.disableFollowRedirect

setUp(scn.inject(rampUsers(numUsers) over (myRamp seconds)).protocols(httpConf))
}

Scenario (in separate file):

val scn = scenario(“Test Scenario”)
.repeat(numIters) {
feed(file)
.exec {
http(“testing”)
.get("/target/${param}")
.headers(Map(“Keep-Alive” → “115”,“Content-Type” → “application/json”))
.check(status.is(200))}
.pause(testPause)
}

Honestly… I run this test and I properly get the url in the simulation.log:

import io.gatling.core.Predef._
import io.gatling.http.Predef._
import io.gatling.jdbc.Predef._
import scala.concurrent.duration._

class Test extends Simulation {

val httpProtocol = http
.baseURL(“http://gatling.io”)
.extraInfoExtractor(extraInfo => List(extraInfo.request.getUrl))

val scn = scenario(“Basic”)
.exec(http(“Home”).get("/"))

setUp(scn.inject(atOnceUsers(1)).protocols(httpProtocol))
}

I was only able to get this to work if I used a single extraInfoExtractor method. I actually want two - one for the request URL and one for the response payload size - so is there a way to do that successfully? It seems only to honor the last extraInfoExtractor listed.

If I have this:

val httpConf = http
.warmUp(“http://myServer.com/target”)
.baseURL(urlBase)
.acceptHeader(“application/json”)
.extraInfoExtractor(extraInfo => List(extraInfo.request.getUrl))
.disableFollowRedirect

I get the request URL in the simulation log. However, if I do this, I get only the response body length, and no request URL, in the simulation log:

val httpConf = http
.warmUp(“http://myServer.com/target”)
.baseURL(urlBase)
.acceptHeader(“application/json”)
.extraInfoExtractor(extraInfo => List(extraInfo.request.getUrl))
.extraInfoExtractor(extraInfo => List(extraInfo.response.bodyLength))
.disableFollowRedirect

Thanks.

All our DSL elements are immutable builders, so you’re just overriding the extraInfoExtractor you’ve just set.

What you want is:
.extraInfoExtractor(extraInfo => List(extraInfo.request.getUrl, extraInfo.response.bodyLength))

Perfect; thanks!