Skip to content
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

#1289: Error will be displayed that only 1 array is allowed in batch #2585

Merged
merged 9 commits into from
Jul 6, 2022

Conversation

vanshaj
Copy link
Contributor

@vanshaj vanshaj commented Jul 4, 2022

Updated Batch method to contain array of goja.Value and if the size is greater than 1 then return and error. Else continue with the data.

@CLAassistant
Copy link

CLAassistant commented Jul 4, 2022

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions bot requested review from codebien and olegbespalov July 4, 2022 12:10
@na-- na-- added this to the v0.40.0 milestone Jul 4, 2022
@na-- na-- linked an issue Jul 4, 2022 that may be closed by this pull request
Copy link
Contributor

@codebien codebien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @vanshaj, LGTM. Can you sign the CLA so we can accept your contribution, please?

js/modules/k6/http/request.go Outdated Show resolved Hide resolved
@vanshaj vanshaj requested a review from codebien July 5, 2022 05:15
@olegbespalov
Copy link
Contributor

Hi @vanshaj !

Thanks for your contribution! It seems like the changes affected other tests. Could you please have a look?

Cheers!

@vanshaj
Copy link
Contributor Author

vanshaj commented Jul 5, 2022

Hi @vanshaj !

Thanks for your contribution! It seems like the changes affected other tests. Could you please have a look?

Cheers!

Sorry for the failures. I have added the validation for init context above my new validation.

Pushed the changes

Regards
Vanshaj

@codecov-commenter
Copy link

codecov-commenter commented Jul 5, 2022

Codecov Report

Merging #2585 (0c8de0c) into master (7f823f0) will decrease coverage by 0.55%.
The diff coverage is 65.50%.

❗ Current head 0c8de0c differs from pull request most recent head 88b64f7. Consider uploading reports for the commit 88b64f7 to get more accurate results

@@            Coverage Diff             @@
##           master    #2585      +/-   ##
==========================================
- Coverage   75.59%   75.03%   -0.56%     
==========================================
  Files         202      203       +1     
  Lines       15992    16274     +282     
==========================================
+ Hits        12089    12212     +123     
- Misses       3151     3296     +145     
- Partials      752      766      +14     
Flag Coverage Δ
ubuntu 75.03% <65.50%> (-0.36%) ⬇️
windows ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
errext/exit_code.go 100.00% <ø> (ø)
js/common/interrupt_error.go 100.00% <ø> (+18.18%) ⬆️
js/compiler/compiler.go 64.15% <ø> (ø)
js/modules/k6/grpc/client.go 78.39% <0.00%> (ø)
js/timeout_error.go 56.25% <ø> (ø)
lib/consts/consts.go 78.57% <ø> (ø)
metrics/metric.go 92.40% <0.00%> (+3.38%) ⬆️
output/csv/time_format_gen.go 20.00% <20.00%> (ø)
metrics/thresholds.go 88.54% <33.33%> (-0.18%) ⬇️
...utils/httpmultibin/grpc_any_testing/any_test.pb.go 37.97% <37.97%> (ø)
... and 42 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e7c2aee...88b64f7. Read the comment docs.

js/modules/k6/http/request_test.go Outdated Show resolved Hide resolved
js/modules/k6/http/request.go Outdated Show resolved Hide resolved
if len(reqsValues) == 0 {
return nil, fmt.Errorf("no argument was provided to http.batch()")
} else if len(reqsValues) > 1 { // Validation for http.batch(["https://validurl"],["https://validurl"])
return nil, fmt.Errorf("http.batch() must have only one single array as an argument")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return nil, fmt.Errorf("http.batch() must have only one single array as an argument")
return nil, fmt.Errorf("http.batch() must have only one single array as a root argument. Define the requests as nested items.")

@olegbespalov WDYT? Do you have better suggestions? I would be very clear here because I think it's easy to waste time making the error to forget the root array.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return nil, fmt.Errorf("http.batch() must have only one single array as an argument")
return nil, fmt.Errorf("http.batch() accepts only an object/array of requests.")

Maybe something like this?

@codebien @vanshaj WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return nil, fmt.Errorf("http.batch() must have only one single array as an argument")
return nil, fmt.Errorf("http.batch() accepts only an array or an object of requests.")

@olegbespalov your version sounds better, I would just avoid the slash.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done updated to "http.batch() accepts only an array or an object of requests." in file and test case also .

@vanshaj vanshaj requested a review from codebien July 5, 2022 10:17
Copy link
Contributor

@codebien codebien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just some minors improvements

@@ -437,21 +437,25 @@ func (c *Client) prepareBatchObject(requests map[string]interface{}) (

// Batch makes multiple simultaneous HTTP requests. The provideds reqsV should be an array of request
// objects. Batch returns an array of responses and/or error
func (c *Client) Batch(reqsV goja.Value) (interface{}, error) {
func (c *Client) Batch(reqsValues ...goja.Value) (interface{}, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func (c *Client) Batch(reqsValues ...goja.Value) (interface{}, error) {
func (c *Client) Batch(reqsV ...goja.Value) (interface{}, error) {

Removing the line after we can restore the name so we don't need to update the comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for your valuable feedback. Implemented the change.

return nil, fmt.Errorf("http.batch() accepts only an array or an object of requests")
}

reqsV := reqsValues[0]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
reqsV := reqsValues[0]

This change doesn't seem required, so we can avoid one more allocation, you can use directly reqsV[0].Export()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for your valuable feedback. Implemented the change.

@vanshaj vanshaj requested a review from codebien July 6, 2022 05:37
Copy link
Contributor

@olegbespalov olegbespalov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for your contribution! 👍

Copy link
Contributor

@codebien codebien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Hey @vanshaj, we are going to merge this, thanks for your contribution. 👏 🎉

@codebien codebien merged commit 8cf459f into grafana:master Jul 6, 2022
@vanshaj
Copy link
Contributor Author

vanshaj commented Jul 6, 2022

LGTM! Hey @vanshaj, we are going to merge this, thanks for your contribution. 👏 🎉

Thanks a lot, very glad for your review and valuable feedback. Will keep on contributing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

http.batch() should not accept more than one argument
6 participants