2

I'm trying to find a way to get response headers such as X-RateLimit-Limit, X-RateLimit-Remaining etc. from http call response. Not able to find from online resources or documentation, can someone help? I see these headers in console as I enabled logging but don't know how to retrieve these headers from response.

http("Get API")
      .get("https://hello.com/list")
      .header("Authorization", "${auth}")
      .check(status.is(200))
      .check(bodyString.saveAs("Auth_Response"))

Also is there a way to run this http call multiple times within a timeframe. What in-built methods should i use for looping as well running this specific http call within certain time limit? I tried below but unsuccessful. Ideally I would want to be able to verify this APIs rate limit hence tried this way. Although I'm getting to understand that I can't use repeat() duration() both at the same time however they serve 2 different purpose which I want to achieve. Even just calling http request builder type call in duration() is throwing error - "it doesn't conform to expected type ChainBuilder"

val scn1 =
during (60.seconds) {
  scenario("Setup scenario")
    .repeat(201){
      exec(
      http("Get API")
        .get("https://hello.com/list")
        .header("Authorization", "${auth}")
    )}
  setUp(
    scn1.inject(
      atOnceUsers(1)
    )
  )
}

Whether I put setup () inside during() or outside, its causing error. I am trying to evaluate if I even need during().When using just repeat(201) it causing the API to run 201 times and reducing the count of X-RateLimit-Remaining for api however not enough to reach it to 0 causing the error code response. Kindly provide any suggestions?

anonymous-explorer
  • 365
  • 1
  • 12
  • 26

1 Answers1

5

it's in the cheat sheet at https://gatling.io/docs/current/cheat-sheet/

.check(header(headerName)).is(...)

James Warr
  • 2,552
  • 2
  • 7
  • 20
  • thanks@James Warr I am able to retrieve the response header. Also, as per my post what in-built functions would u recommend to execute this API multiple times within a time(sec) ? – anonymous-explorer Aug 21 '19 at 19:09
  • is that exactly the code you've got? You're using '()' rather than '{}' around your repeat chain – James Warr Aug 22 '19 at 22:59
  • yes mainly that's the exact code I used and ran. Also , using '()' instead of '{}' in repeat chain works completely fine in compilation and doesn't fail in the syntax. – anonymous-explorer Aug 23 '19 at 20:17
  • In fact, using just repeat(201) and no duration() does execute the http API 201 times. But it isn't resulting in reaching the api rate limit exceeded error response code, hence I tried with using duration() – anonymous-explorer Aug 23 '19 at 20:26
  • You can always increase the number of users you inject to get to your desired taste – James Warr Aug 24 '19 at 02:52
  • Actually I didn't want to increase the no.of users as I desired to test rate limit of this api for only 1 user. Would increasing the traffic help ? – anonymous-explorer Aug 24 '19 at 03:42
  • When you have only one user in your simulation, you are only ever going to have one request at a time and so the rate you achieve will necessarily be limited by the request / response time of your API. Having multiple users and therefore more concurrent requests will enable you to see what rate your service can achieve – James Warr Aug 24 '19 at 09:50
  • thanks , I'll increase the no. of users but can you take a look at the above code I updated in description as its resulting in error when putting setup part in during () loop . Even though I keep setup() out of during() loop construct; it results in error - Setup scenario is empty I don't find gatling documentation helping enough with so less examples to follow. Kindly help! – anonymous-explorer Aug 24 '19 at 14:05