[Gatling-2.0.0-M3a] Problem logging request data.

I’ve tried several different things now and I’m stumped.

The simulation I’m running is cobbling together data from quite a few feeders to generate the request body. Some of those items vary in size quite a bit, so I wanted to log the request size in the simulation.log file. Naturally, I found that that there is a method for doing just this: extraInfoExtractor. Looks good to me. I throw together the following method to retrieve the data:

.extraInfoExtractor((status: Status, session: Session, req: Request, resp: Response) => {
List(req.getContentLength())
})

But alas, this just returns -1. I’m a little surprised here, since my request is a POST, so I expected this to be calculated. Hmmm, well this length method is deprecated, but maybe it will work for now:

.extraInfoExtractor((status: Status, session: Session, req: Request, resp: Response) => {
List(req.getLength())
})

Nope, same result. Maybe I can just grab the raw request data and get the length from that:

.extraInfoExtractor((status: Status, session: Session, req: Request, resp: Response) => {
List(req.getByteData().length)
})

Ah, found my good friend NullPointerException.

At this point, I’m a little stumped about the proper way to retrieve this information. I can probably get this working by storing the size in the session as part of my request and then retrieving it from the session in the extractor, but I don’t understand why this information doesn’t seem to be available from the request object. Am I missing something?

Sorry, that’s not possible at the moment. Gatling is built on top of async-http-client, and it doesn’t signal the actual request size.

The only way I see is to build the bodies ahead, store it into the session along with an additional attribute containing its size.

Yeah, that is what I ended up doing. It just threw me off that the methods were available, but didn’t provide any meaningful data. That caused me to think I was using the info extractor incorrectly or something.

Thanks for the clarification and quick response.

extraInfoExtractor is a kind of low level back door that let you access AHC API. But AHC is an abstraction layer, on top of Netty or Grizzly, and you don’t get full access there. For example, Content-Length is indeed computed but passed to the Netty/Grizzly request object, and the AHC one isn’t modified.

Regarding byteData, that’s just a way to pass a body in the form of a byte array, so it’s only non null when you pass a body this way, which Gatling doesn’t.