New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Couple of enhancements #374
Conversation
Codecov Report
@@ Coverage Diff @@
## master #374 +/- ##
=======================================
Coverage 96.19% 96.20%
=======================================
Files 10 10
Lines 1235 1238 +3
=======================================
+ Hits 1188 1191 +3
Misses 26 26
Partials 21 21
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have permission to push to your PR branch, so here's a patch to test the RemoteAddr feature:
diff --git a/request_test.go b/request_test.go
index b02e04c..1035d87 100644
--- a/request_test.go
+++ b/request_test.go
@@ -1644,6 +1644,8 @@ func TestTraceInfo(t *testing.T) {
ts := createGetServer(t)
defer ts.Close()
+ serverAddr := ts.URL[strings.LastIndex(ts.URL, "/")+1:]
+
client := dc()
client.SetHostURL(ts.URL).EnableTrace()
for _, u := range []string{"/", "/json", "/long-text", "/long-json"} {
@@ -1660,6 +1662,7 @@ func TestTraceInfo(t *testing.T) {
assertEqual(t, true, tr.TotalTime >= 0)
assertEqual(t, true, tr.TotalTime < time.Hour)
assertEqual(t, true, tr.TotalTime == resp.Time())
+ assertEqual(t, tr.RemoteAddr.String(), serverAddr)
}
client.DisableTrace()
Sure, I will add it to the test case.
Hmm, this is strange. You're a member of this repo, you should have write access. PR branch resides in this repo. Can you share the error message? |
ae3d649
to
038920c
Compare
@moorereason Test case updated |
I see that I'm a "member" of the project, but I appear to only have read access.
|
@moorereason It's my bad, I created @go-resty/core team but didn't assign it to the repo. I'm sorry. Can you try now? Also, please review this PR and approve it. |
First, I don't think Second, can you update the README.md to include Finally, wouldn't it be helpful to set the Given this test program: package main
import (
"fmt"
"net/http"
"github.com/go-resty/resty/v2"
)
func main() {
client := resty.New().
SetRetryCount(3).
AddRetryCondition(func(r *resty.Response, e error) bool {
return r.StatusCode() == http.StatusNotFound
}).
OnAfterResponse(func(c *resty.Client, resp *resty.Response) error {
fmt.Printf("OnAfterResponse:attempt = %d\n", resp.Request.RetryAttempt)
return nil
})
resp, _ := client.R().Get("https://httpbin.org/status/404")
fmt.Printf("%d\n", resp.Request.RetryAttempt)
} The current PR executes as:
With this change: diff --git a/request.go b/request.go
index 9e49fca..51f0520 100644
--- a/request.go
+++ b/request.go
@@ -699,6 +699,7 @@ func (r *Request) Execute(method, url string) (*Response, error) {
attempt++
r.URL = r.selectAddr(addrs, url, attempt)
+ r.RetryAttempt = attempt
resp, err = r.client.execute(r)
if err != nil { The results become:
|
It looks like the permissions are fixed now. Thanks 👍 |
@moorereason why do you feel Sure, I will update the code and readme for remaining. |
Because it's already exposed in the |
Typically, trace info or metric values are serialized as JSON sent to metric capture systems like influxdb, prometheus, datadog, newrelic, etc. Currently, resty users are doing this step at their end. I have been thinking for a long; still, I have not decided field name format snake case vs camel case or support both via function on |
…e on attempt Signed-off-by: Jeevanandam M <jeeva@myjeeva.com>
Thanks for the explanation. Makes sense. 👍 I have a couple more comments:
|
Thanks @moorereason
Sure, I will add details in the readme 👍.
Nice, good one. The
After your response, I will prepare this PR as final. |
Sounds good. 👍 |
6f161d3
to
7643bc9
Compare
@moorereason I have updated it. This PR is ready for final review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small rewording suggestion, but I won't hold up the PR for it. Nice work. 👍
* Create Multiple clients if you want to `resty.New()` | ||
* Supports `http.RoundTripper` implementation, see [SetTransport](https://godoc.org/github.com/go-resty/resty#Client.SetTransport) | ||
* goroutine concurrent safe | ||
* Resty Client trace, see [Client.EnableTrace](https://godoc.org/github.com/go-resty/resty#Client.EnableTrace) and [Request.EnableTrace](https://godoc.org/github.com/go-resty/resty#Request.EnableTrace) | ||
* Since v2.4.0, `RequestAttempt` value supported in trace info also Request instance contains `Attempt` attribute |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rewording suggestion:
Since v2.4.0, trace info contains a RequestAttempt
value, and the Request object contains an Attempt
attribute
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @moorereason, I will update the readme with suggestion on the next round. I have to do a few other things.
Resolves #352
Resolves #370