-
Notifications
You must be signed in to change notification settings - Fork 17
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
http.Agent: Add Group
variants for parallel fetching
#107
Conversation
@@ -74,6 +77,7 @@ var defaultAgentOptions = &agentOptions{ | |||
Timeout: 3 * time.Second, | |||
MaxWaitTime: 60 * time.Second, | |||
PostContentType: defaultPostContentType, | |||
MaxParallel: 5, |
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.
As a follow-up, can we make this configurable somehow?
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.
You can configure it with the config functions. I added one for MaxParallel, for example:
a := http.NewAgent().WithMaxParallel(10)
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.
looks cool, just a few nit/questions
"sigs.k8s.io/release-utils/http" | ||
) | ||
|
||
func Example() { |
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.
can we have a better test name?
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.
Mmh any suggestions? It is supposed to be a general example, no tied to a function so I was following the "Whole file example" convention (see the go examples documentation)
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'm not sure I'm a huge fan of having examples in the same package as the code in general. What about having a dedicated package at the repo root (e.g. examples
) where we can put code examples for various different packages in this repo?
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.
Ah ok, I can remove it. This is so that it shows on the go documentation, such as this:
https://pkg.go.dev/strings#example-Builder
agent := http.NewAgent() | ||
w := []io.Writer{} | ||
urls := []string{ | ||
"https://live.staticflickr.com/65535/53863838503_3490725fab.jpg", |
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.
Should we use other links, or is this okay, and will it not disappear?
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.
They could dissapear, but since it's just an example (for the documentation) I'm not too concerned.
8d37564
to
1cc97f7
Compare
OK, I've replaced the external dependency with the new throttle package and repushed. PTAL! |
1 similar comment
OK, I've replaced the external dependency with the new throttle package and repushed. PTAL! |
http/agent.go
Outdated
// The list of URLs and postData byte arrays are expected to be of equal length. | ||
// If postData has less elements than the url list, those urls without a corresponding | ||
// postData array will return an error. |
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.
What's the reason for not failing as early as possible, given that the function will eventually fail anyways?
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.
What I was trying to do was to do all requests that were plausible but that introduced an inconsistent behavior. I took your advice here and now the function will fail early if URLs and postdata don't line up. I also updated the test to check for it.
This commit addds Group Variants to the agent functions to fetch files in parallel. Signed-off-by: Adolfo García Veytia (Puerco) <adolfo.garcia@uservers.net>
Signed-off-by: Adolfo García Veytia (Puerco) <adolfo.garcia@uservers.net>
This commit adds a doc.go with documentation about the module and an example showing how to do parallel feching with the agent. Signed-off-by: Adolfo García Veytia (Puerco) <adolfo.garcia@uservers.net>
Signed-off-by: Adolfo García Veytia (Puerco) <adolfo.garcia@uservers.net>
Signed-off-by: Adolfo García Veytia (Puerco) <adolfo.garcia@uservers.net>
This xommit updates the http tests to avoid retries to speed them up. Signed-off-by: Adolfo García Veytia (Puerco) <adolfo.garcia@uservers.net>
OK, I pushed another commit optimizing some of the tests, should be ready to go now.
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: cpanato, puerco The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What type of PR is this?
/kind feature
/kind documentation
What this PR does / why we need it:
This pull request adds
*Group
variants of the existinghttp.Agent
methods to support parallel fetching of multiple URLs. The new included docs explain it better:Which issue(s) this PR fixes:
None
Special notes for your reviewer:
Most of the line changes in the PR is documentation, the real code is in 482d365
I added a doc.go to document the module better and an example to illustrate the new functions.
The functions rely on the existing fetch logic, I added a test to check that the parallel logic returns values in the expected order.
Finally I marked as deprecated the http.GetURLResponse() function to encourage developers to use the agent directly.
Does this PR introduce a user-facing change?