# tryMax logging

**URL:** https://community.gatling.io/t/trymax-logging/2906
**Category:** Gatling (Open-Source)
**Created:** [April 7, 2016, 12:44am UTC](https://community.gatling.io/t/trymax-logging/2906 "2016-04-07T00:44:16Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![TK1](https://avatars.discourse-cdn.com/v4/letter/t/96bed5/32.png) [@TK1](https://community.gatling.io/u/TK1)
#### Post date: [April 7, 2016, 12:44am UTC](https://community.gatling.io/t/trymax-logging/2906/1 "2016-04-07T00:44:16Z")

</div>

Just to cross check my understanding of tryMax functionality. Are we going to mark the request as failed only if all the attempts are failed under tryMax loop? Or Are we going to mark the request as failed for every attempt?

I am trying to implement tryMax function in my code and have been noticing that failure attempts are also being logged under “KO” section even if the request would have passed in different attempt. I mean if the request is passed in 4th attempt but all the previous 3 attempts are being logged under “KO” section which is misleading the overall error rate and creating unnecessary havoc.

Please correct me if i am missing anything here. Thanks a lot in advance for looking into this.

---

<div class="post-metadata">

### Author: ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)
#### Post date: [April 7, 2016, 6:21am UTC](https://community.gatling.io/t/trymax-logging/2906/2 "2016-04-07T06:21:27Z")

</div>

> Just to cross check my understanding of tryMax functionality. Are we going  
> to mark the request as failed only if all the attempts are failed under  
> tryMax loop? Or Are we going to mark the request as failed for every  
> attempt?

The former

> I am trying to implement tryMax function in my code and have been noticing  
> that failure attempts are also being logged under "KO" section even if the  
> request would have passed in different attempt. I mean if the request is  
> passed in 4th attempt but all the previous 3 attempts are being logged  
> under "KO" section which is misleading the overall error rate and creating  
> unnecessary havoc.

Please provide a reproducer

---

<div class="post-metadata">

### Author: ![TK1](https://avatars.discourse-cdn.com/v4/letter/t/96bed5/32.png) [@TK1](https://community.gatling.io/u/TK1)
#### Post date: [April 7, 2016, 8:40am UTC](https://community.gatling.io/t/trymax-logging/2906/3 "2016-04-07T08:40:41Z")

</div>

Hi Stephane,  
I have included “tryMax” function in my code to handle the reattempt logic of Business usecase. I was expecting that it will be logging the failure after all attempts but it is logging failure under “KO” section for each attempt which is misleading the error count.

Please find the below sample code and logsnippet:

tryMax(5) {  
.exec {  
http(“Usecase1\_Phone3”)  
.get( “”“[https://service3.test.com/phone/${id}](https://service3.test.com/phone/%24%7Bid%7D)”"")  
.header(“X-B3-TraceId”, “Phone3\_${getTime}”)  
.headers(headers\_common)  
.check(status.is(200))  
}

}

---

<div class="post-metadata">

### Author: ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)
#### Post date: [April 7, 2016, 8:55am UTC](https://community.gatling.io/t/trymax-logging/2906/4 "2016-04-07T08:55:46Z")

</div>

Which version do you use?

---

<div class="post-metadata">

### Author: ![TK1](https://avatars.discourse-cdn.com/v4/letter/t/96bed5/32.png) [@TK1](https://community.gatling.io/u/TK1)
#### Post date: [April 8, 2016, 8:15am UTC](https://community.gatling.io/t/trymax-logging/2906/5 "2016-04-08T08:15:53Z")

</div>

Version is 2.1.7.

---

<div class="post-metadata">

### Author: ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)
#### Post date: [April 8, 2016, 8:21am UTC](https://community.gatling.io/t/trymax-logging/2906/6 "2016-04-08T08:21:04Z")

</div>

Oh, right.

Yes, that’s the expected behavior.

If “failures” are expected, use a check with an optional criterion, and loop until the data could be saved.

---

<div class="post-metadata">

### Author: ![TK1](https://avatars.discourse-cdn.com/v4/letter/t/96bed5/32.png) [@TK1](https://community.gatling.io/u/TK1)
#### Post date: [April 8, 2016, 8:54am UTC](https://community.gatling.io/t/trymax-logging/2906/7 "2016-04-08T08:54:28Z")

</div>

Hi Stephane,  
Let me explain application flow… whenever the app didn’t receive success status for the request, it attempts for 5 times and then only it will return the request as “Failed”. So, I have included tryMax function to handle this usecase. We are expecting to log the request as failed only after all attempts are completed but it is logging for every attempt. We need to the log the request status after all attempts incase of failures.Hope it is clear.

Can you please let me know if we have any other function/approach to handle this usecase?

Regards  
TK

---

<div class="post-metadata">

### Author: ![TK1](https://avatars.discourse-cdn.com/v4/letter/t/96bed5/32.png) [@TK1](https://community.gatling.io/u/TK1)
#### Post date: [April 11, 2016, 10:43pm UTC](https://community.gatling.io/t/trymax-logging/2906/8 "2016-04-11T22:43:40Z")

</div>

Can you please let me know if we have any ways to handle this usecase?

---

<div class="post-metadata">

### Author: ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)
#### Post date: [April 12, 2016, 3:47am UTC](https://community.gatling.io/t/trymax-logging/2906/9 "2016-04-12T03:47:01Z")

</div>

More detailed answer:

- loop “asLongAs” some data “notExists()” + force the loop counter name to be able to determine if the iteration is the last attempt
- on last attempt, use a check with “exist”, otherwise “optional”

---

<div class="post-metadata">

### Author: ![Michael\_C](https://avatars.discourse-cdn.com/v4/letter/m/7cd45c/32.png) [@Michael\_C](https://community.gatling.io/u/Michael_C)
#### Post date: [January 24, 2018, 12:34am UTC](https://community.gatling.io/t/trymax-logging/2906/10 "2018-01-24T00:34:06Z")

</div>

Stephane

This is a lot of manual error handling. It would be really nice if TryMax had an option only log 1 KO if it was not able to be successful at all.

---

<div class="post-metadata">

### Author: ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)
#### Post date: [January 24, 2018, 6:36am UTC](https://community.gatling.io/t/trymax-logging/2906/11 "2018-01-24T06:36:34Z")

</div>

Contributions welcome!
