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

Rally improve artifact download headers #1159

Merged
merged 3 commits into from
Jan 26, 2021
Merged

Conversation

ebadyano
Copy link
Contributor

To prevent Rally artifact downloads from being counted in statistics add parameter to download url: x-elastic-no-kpi=true

To prevent Rally artifact downloads from being counted in statistics add
parameter to download url: x-elastic-no-kpi=true
@ebadyano ebadyano added enhancement Improves the status quo :misc Changes that don't affect users directly: linter fixes, test improvements, etc. labels Jan 26, 2021
@ebadyano ebadyano added this to the 2.0.4 milestone Jan 26, 2021
@ebadyano ebadyano requested a review from dliappis January 26, 2021 01:35
@ebadyano ebadyano self-assigned this Jan 26, 2021
Copy link
Contributor

@dliappis dliappis left a comment

Choose a reason for hiding this comment

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

Thank you for the quick turnaround!

Left a few comments, main one is about the no kpi parameter in supplier.py.

@@ -182,6 +182,13 @@ def download_http(url, local_path, expected_size_in_bytes=None, progress_indicat
return expected_size_in_bytes


def add_url_param(url, params):
url_parsed = urlparse(url)
query = dict(parse_qsl(url_parsed.query))
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we want to get a dict back and update it with params, should we use parse_qs instead since it actually returns a dict rather an dictify the list that parse_qsl returns? According the above docs, if we do that, we should use urlencode(query, doseq=True) two lines below.

@@ -509,7 +509,7 @@ def __init__(self, repo, version, distributions_root):

def fetch(self):
io.ensure_dir(self.distributions_root)
download_url = self.repo.download_url
download_url = net.add_url_param(self.repo.download_url, {"x-elastic-no-kpi": "true"})
Copy link
Contributor

Choose a reason for hiding this comment

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

Having URL parameter specifics in this file (which deals with matter in a higher layer of abstraction) feels a bit out of place to me.

I wonder, would it make sense to just have an additional convenience function in net.py like net.url_elastic_no_kpi() where this param is added by invoking net.add_url_param()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

makes sense, i will add that

@@ -60,6 +60,12 @@ def test_gcs_object_url(self, seed):
assert net._build_gcs_object_url(bucket_name, bucket_path) == \
"https://storage.googleapis.com/storage/v1/b/unittest-bucket.test.me/o/path%2Fto%2Fobject?alt=media"

def test_add_url_param(self):
url = "https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.2.0.tar.gz?flag1=true"
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we add a second test to check if a flag value contains something that needs special quoting e.g. a whitespace? Reason I am saying this is because I noticed that urlencode by default uses quote_plus which e.g. will encode a param like flag=test me to flat=test+me. The plus is OK for queries according to http://en.wikipedia.org/wiki/URL_encoding and http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.1 but perhaps having this test helps us figure out some edge case in the future?

@ebadyano
Copy link
Contributor Author

@dliappis Thank you for the review, I addressed your comments.

@ebadyano ebadyano requested a review from dliappis January 26, 2021 15:28
Copy link
Contributor

@dliappis dliappis left a comment

Choose a reason for hiding this comment

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

LGTM

@ebadyano ebadyano merged commit 6ada969 into elastic:master Jan 26, 2021
@ebadyano
Copy link
Contributor Author

Thank you for the quick review! @dliappis

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improves the status quo :misc Changes that don't affect users directly: linter fixes, test improvements, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants