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

Remove the check for internet connection #1517

Merged

Conversation

j-bennet
Copy link
Contributor

@j-bennet j-bennet commented Jun 13, 2022

Remove the check for Rally being online. Let it fail when trying to update the repositories instead.

Closes #1506.

Alternative to #1514.

@j-bennet j-bennet marked this pull request as draft June 13, 2022 23:59
@pquentin
Copy link
Member

For context, passing --offline is now mandatory anyway since #1503 closed #1468. I agree with @j-bennet here that connecting to github.com with each Rally invocation does more harm than good, I think it's obvious when your don't have Internet and it delays all my Rally invocations by one second! (We did try being selective in #1514 but many commands have a way to connect to the Internet one way or another.)

@dliappis @danielmitterdorfer What do you think?

@dliappis
Copy link
Contributor

@pquentin I am good with the direction highlighted here, however, I have a comment. In this PR we are removing the informative message that we had so far, "Could not detect a working Internet connection". If internet is down, when using e.g. list races we get:

$ esrally list tracks

[WARNING] Could not update tracks. Continuing with your locally available state.

I think it's a shame if we aren't helpful here to at least point to the user that there is an offline mode. We know from experience that not everyone spends the time to read the docs and IMHO we are missing a chance to be more user friendly here.

On another note, if we are to run with the reproduction mentioned in #1506 (comment) i.e. using an invalid http_proxy all works fine even if the system has a working internet connection; I find this confusing, if an invalid proxy is provided, then commands relying on working internet should fail.

@j-bennet j-bennet force-pushed the j-bennet/1506-remove-check-connection branch from 8f3fcf0 to 39a2715 Compare June 14, 2022 20:41
@j-bennet
Copy link
Contributor Author

j-bennet commented Jun 14, 2022

@dliappis

In this PR we are removing the informative message that we had so far, "Could not detect a working Internet connection".

Goog catch! I digged into it. The reason the message disappeared is because apparently, git doesn't respect http_proxy or HTTP_PROXY:

irinatruong at eli in ~/.rally/benchmarks/tracks/default on master
> HTTP_PROXY=http://invalid git fetch origin master
From https://github.com/elastic/rally-tracks
 * branch            master     -> FETCH_HEAD
irinatruong at eli in ~/.rally/benchmarks/tracks/default on master
> http_proxy=http://invalid git fetch origin master
From https://github.com/elastic/rally-tracks
 * branch            master     -> FETCH_HEAD
irinatruong at eli in ~/.rally/benchmarks/tracks/default on master
> git -c 'http.proxy=http://invalid' fetch origin master
fatal: unable to access 'https://github.com/elastic/rally-tracks/': Could not resolve proxy: invalid

I addressed it, and the warning is back now:

> http_proxy=http://invalid esrally list tracks

    ____        ____
   / __ \____ _/ / /_  __
  / /_/ / __ `/ / / / / /
 / _, _/ /_/ / / / /_/ /
/_/ |_|\__,_/_/_/\__, /
                /____/

[WARNING] Could not update tracks. Continuing with your locally available state.

There doesn't seem to be an issue tracker for git, even though there's a source code repo (read-only). It accepts patches via mailing list:

https://github.com/git/git

Because of this, I was unable to find out if not respecting HTTP_PROXY is a known issue / recent bug.

@j-bennet j-bennet force-pushed the j-bennet/1506-remove-check-connection branch from 39a2715 to de0d818 Compare June 14, 2022 22:04
@j-bennet j-bennet force-pushed the j-bennet/1506-remove-check-connection branch from de0d818 to 33cdee5 Compare June 14, 2022 22:06
@j-bennet
Copy link
Contributor Author

The reason the message disappeared is because apparently, git doesn't respect http_proxy or HTTP_PROXY.

So, I was completely wrong there. Git does the right thing, I wasn't! I should have set https_proxy, since we have https github urls. 🤦

Going to revert the --c http.proxy change.

@j-bennet
Copy link
Contributor Author

j-bennet commented Jun 15, 2022

Also, rally should really support http_proxy, https_proxy, HTTPS_PROXY, all_proxy and ALL_PROXY, just like curl and git do. I'm going to add that to this PR.

@dliappis
Copy link
Contributor

@j-bennet

Thanks for iterating!

I am not sure that the latest commits have changed the behavior when specifying a proxy; I checked out the latest state of this PR and tried setting all proxy vars (for completeness sake):

$ export | grep -i proxy
declare -x ALL_PROXY="https://invalid"
declare -x HTTPS_PROXY="https://invalid"
declare -x HTTP_PROXY="http://invalid"
declare -x all_proxy="https://invalid"
declare -x http_proxy="http://invalid"
declare -x https_proxy="https://invalid"

and all Rally commands still seem to bypass the invalid proxy:

$ git log -2
commit acdacbcc7b628fcad13a0f7e1ddbd035c4601fb5 (HEAD -> pr/1517)
Author: Irina Truong <[email protected]>
Date:   Tue Jun 14 17:42:29 2022 -0700

    Don't uppercase http_proxy.

commit a30d455829b9be00f760d9348dc6d653a71f6f88
Author: Irina Truong <[email protected]>
Date:   Tue Jun 14 17:37:26 2022 -0700

    Rally should differentiate between http and https proxy.

$ esrally --version
esrally 2.5.0.dev0 (git revision: acdacbc)

$ esrally list races

    ____        ____
   / __ \____ _/ / /_  __
  / /_/ / __ `/ / / / / /
 / _, _/ /_/ / / / /_/ /
/_/ |_|\__,_/_/_/\__, /
                /____/


Recent races:

Race ID                               Race Timestamp    Track     Track Parameters    Challenge                       Car              User Tags    Track Revision    Team Revision
------------------------------------  ----------------  --------  ------------------  ------------------------------  ---------------  -----------  ----------------  ---------------
7962d2dc-e65c-4481-b045-3515f3904484  20220603T123105Z  geonames                      append-no-conflicts-index-only  defaults+4gheap               6554ab0           d52caa5
60f81bb2-25cd-4915-ae07-24422cf1d1ed  20220603T122910Z  geonames                      append-no-conflicts-index-only  defaults+4gheap               6554ab0           d52caa5
c51159fd-ce09-4d65-8f29-31e955dda2e7  20220603T122818Z  geonames                      append-no-conflicts-index-only  defaults+4gheap               6554ab0           d52caa5
6812eb5f-aac3-49c0-8536-73ee7dc40a54  20220603T122731Z  geonames                      append-no-conflicts-index-only  defaults+4gheap               6554ab0           d52caa5
aded4d0b-b470-423e-b456-89f1415902c6  20220603T122537Z  geonames                      append-no-conflicts-index-only  defaults+4gheap               6622623           d52caa5
ef010d46-0654-4784-8c73-2a8e86610740  20220603T122145Z  geonames                      append-no-conflicts-index-only  defaults+4gheap               6554ab0           d38ad85
630d3e25-6cee-4c8f-a4d6-cf2093015005  20220603T121602Z  geonames                      append-no-conflicts-index-only  defaults+4gheap               18b1cc6           d38ad85
801a1e51-2f3e-415b-b32c-b372d13da3d2  20220603T121357Z  geonames                      append-no-conflicts-index-only  defaults+4gheap               18b1cc6           d38ad85
b70c0dc8-40d5-4da2-9e0b-75b6f0c2b2f2  20220603T121132Z  geonames                      append-no-conflicts-index-only  defaults+4gheap               6554ab0           d52caa5
9112fd37-8427-49e2-a6e6-f0e7e89d3735  20220530T114508Z  noaa                          append-no-conflicts-index-only  defaults                      ebd1ab6           c56ad04

Should things fail? e.g. curl does:

$ curl www.google.com
curl: (5) Could not resolve proxy: invalid

@pquentin
Copy link
Member

@dliappis Did you intend to run esrally list tracks instead of esrally list races? The proxy settings are only used for git and HTTP downloads; the Elasticsearch Python client does not honor them. So even if you configured a metrics store it's expected that the proxy isn't used.

@dliappis
Copy link
Contributor

@dliappis Did you intend to run esrally list tracks instead of esrally list races? The proxy settings are only used for git and HTTP downloads; the Elasticsearch Python client does not honor them. So even if you configured a metrics store it's expected that the proxy isn't used.

@pquentin good point. I checked again and it seems to provide the right output, sorry for the noise here.

$ curl www.google.com
curl: (5) Could not resolve proxy: invalid

$ esrally list tracks


[WARNING] Could not update tracks. Continuing with your locally available state.
Available tracks:

Name           Description                                                              Documents    Compressed Size    Uncompressed Size    Default Challenge        All Challenges
-------------  -----------------------------------------------------------------------  -----------  -----------------  -------------------  -----------------------  ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
geonames       POIs from Geonames                                                       11,396,503   252.9 MB           3.3 GB               append-no-conflicts      append-no-conflicts,append-no-conflicts-index-only,append-fast-with-conflicts,significant-text

$ esrally list cars

[WARNING] Could not update teams. Continuing with your locally available state.
Available cars:

Name                     Type    Description
-----------------------  ------  --------------------------------------
16gheap                  car     Sets the Java heap to 16GB

I have one final concern, which I raised in my first comment whether we could provide a breadcrumb to our docs about the offline mode when internet access has failed. I realize that this can happen due to a genuinely offline scenario, but also due to a bad proxy setting, but e.g. in a situation where there is no internet right now we don't mention anything about the existence of an offline mode -- which we used to prior to this PR:

$ curl www.google.com
curl: (6) Could not resolve host: www.google.com

$ esrally list cars

[WARNING] Could not update teams. Continuing with your locally available state.
Available cars:

Name                     Type    Description
-----------------------  ------  --------------------------------------
16gheap                  car     Sets the Java heap to 16GB

The out of the box experience (when there is no state) shows:

$ esrally list cars


[ERROR] Cannot list. Could not clone from [https://github.com/elastic/rally-teams] to [/home/dl/.rally/benchmarks/teams/default]

Would it make sense to mention the offline mode: https://esrally.readthedocs.io/en/stable/offline.html?highlight=offline#offline-usage when the latter (could not clone) occurs? It's not a huge issue, but it could help users find their way to the docs about how to run offline.

@pquentin
Copy link
Member

Yes, I agree that we need to provide more informative messages in those common cases. It could be enough to report the actual error from git/urllib3 instead of burying that in the logs.

@j-bennet
Copy link
Contributor Author

Adding --offine to messages when we're unable to download somethings makes sense. Before, we had this "gatekeeper" method net.has_internet_connection that would tell you about the --offline flag. Now, it should be up to the methods down the line that are raising errors / warnings when they can't access the network. I'll add that bit.

@j-bennet j-bennet marked this pull request as ready for review June 22, 2022 19:27
@j-bennet
Copy link
Contributor Author

j-bennet commented Jun 22, 2022

This is now ready for review. One integration test is still failing:

it/basic_test.py::test_run_without_http_connection

Not sure what's up with that, as it passes locally. Looking into.

@j-bennet
Copy link
Contributor Author

Tests are now passing.

Copy link
Member

@pquentin pquentin left a comment

Choose a reason for hiding this comment

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

Thanks! This looks good and works well. I left a few questions.

The experience when listing tracks is great, but it's a bit less so when there's missing track data that can't be downloaded:

 esrally race --track=http_logs --test-mode --distribution-version=8.2.0

    ____        ____
   / __ \____ _/ / /_  __
  / /_/ / __ `/ / / / / /
 / _, _/ /_/ / / / /_/ /
/_/ |_|\__,_/_/_/\__, /
                /____/

[WARNING] Could not determine a socket address. Are you running without any network? Switching to degraded mode.
[INFO] Race id is [2d09ad2c-c738-497e-9436-296a4da0ae06]
[WARNING] Could not update tracks. Continuing with your locally available state. Original error: Could not fetch source tree from [origin] You may need to specify --offline if running without Internet connection.

[WARNING] Could not update teams. Continuing with your locally available state. Original error: Could not fetch source tree from [origin] You may need to specify --offline if running without Internet connection.

[INFO] Preparing for race ...
[WARNING] Could not update teams. Continuing with your locally available state. Original error: Could not fetch source tree from [origin] You may need to specify --offline if running without Internet connection.

[WARNING] Could not update tracks. Continuing with your locally available state. Original error: Could not fetch source tree from [origin] You may need to specify --offline if running without Internet connection.

[WARNING] Could not update tracks. Continuing with your locally available state. Original error: Could not fetch source tree from [origin] You may need to specify --offline if running without Internet connection.

[WARNING] Could not update tracks. Continuing with your locally available state. Original error: Could not fetch source tree from [origin] You may need to specify --offline if running without Internet connection.


[ERROR] Cannot race. Error in task executor
        HTTPSConnectionPool(host='rally-tracks.elastic.co', port=443): Max retries exceeded with url: /http_logs/documents-181998-1k.json.bz2 (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7ff7f3aceb50>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution'))

Getting further help:
*********************
* Check the log files in /home/q/.rally/logs for errors.
* Read the documentation at https://esrally.readthedocs.io/en/latest/.
* Ask a question on the forum at https://discuss.elastic.co/tags/c/elastic-stack/elasticsearch/rally.
* Raise an issue at https://github.com/elastic/rally/issues and include the log files in /home/q/.rally/logs.

--------------------------------
[INFO] FAILURE (took 23 seconds)
--------------------------------

I think it's still acceptable, but I'm surprised by all the apparent retries and wonder if we want to attach MSG_NO_CONNECTION for the actual error.

@@ -158,7 +157,7 @@ If the configuration is correct, git will clone this repository. You can delete

To verify that Rally will connect via the proxy server you can check the log file. If the proxy server is configured successfully, Rally will log the following line on startup::

Rally connects via proxy URL [http://proxy.acme.org:3128/] to the Internet (picked up from the environment variable [http_proxy]).
Connecting via proxy URL [http://proxy.acme.org:3128/] to the Internet (picked up from the env variable [http_proxy]).
Copy link
Member

Choose a reason for hiding this comment

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

nit: I'd prefer if we used "environment" actually in the logs instead of env

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hah. I updated the doc to match the actual message, but I guess I can update the message!

@@ -250,31 +263,16 @@ def download(url, local_path, expected_size_in_bytes=None, progress_indicator=No


def retrieve_content_as_string(url):
with __http().request("GET", url, timeout=urllib3.Timeout(connect=45, read=240)) as response:
with __http(url).request("GET", url, timeout=urllib3.Timeout(connect=45, read=240)) as response:
Copy link
Member

Choose a reason for hiding this comment

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

Passing the url twice is weird, can we maybe change __http to _request(method, url, **kwargs)? Can be a follow-up

(I don't think there's any reason to have name mangling here: we should probably switch all double underscores to single underscores.)

Comment on lines 36 to 39
if not env_var == "http_proxy":
# http_proxy can only be lowercase
# see https://curl.se/mail/archive-2001-12/0034.html
proxy_url = os.getenv(env_var.upper())
Copy link
Member

@pquentin pquentin Jun 24, 2022

Choose a reason for hiding this comment

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

I understand why curl decided to forbid HTTP_PROXY 20 years ago, but I don't understand why this applies to us? It's not like running Rally in a CGI script makes any sense.

I think allowing any case for all proxy variables is fine.

it/proxy_test.py Outdated
Comment on lines 93 to 95
# authenticated proxy access is allowed
assert_log_line_present(fresh_log_file, "Detected a working Internet connection")
env["https_proxy"] = http_proxy.authenticated_url
lines = process.run_subprocess_with_output(it.esrally_command_line_for(cfg, "list tracks"), env=env)
output = "\n".join(lines)
assert "[WARNING] Could not update tracks." not in output
Copy link
Member

Choose a reason for hiding this comment

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

Isn't the authenticated URL supposed to allow updating tracks?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm asserting that there's no warning.

Copy link
Member

Choose a reason for hiding this comment

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

Wow, I totally missed that. Would it be more obvious with pytest.mark.parametrize?

Copy link
Contributor Author

@j-bennet j-bennet Jun 27, 2022

Choose a reason for hiding this comment

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

Do you mean having one test to test both authenticated and anonymous url? Or which variable would be parametrized? I added some comments to clarify what's going on.

it/basic_test.py Outdated
assert expected in "\n".join(output)
cmd = it.esrally_command_line_for(cfg, "list tracks")
with tempfile.TemporaryDirectory() as tmpdir:
env = dict(os.environ)
Copy link
Member

Choose a reason for hiding this comment

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

nit: I found os.environ.copy() more explicit.

Out of curiosity, is there any reason to have moved the logic from run_subprocess_with_output to those integration tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, the env_vars was something that I added in one of the previous PRs, and it did NOT represent the full env. It was like "I have these additional variables, please add/update them in the environment". I decided that passing in a complete env is more explicit, less confusing, and consistent with other subprocess api.

Copy link
Member

Choose a reason for hiding this comment

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

You're right, it's better! Leaving unresolved for dict(os.environ)

@j-bennet
Copy link
Contributor Author

@pquentin

The experience when listing tracks is great, but it's a bit less so when there's missing track data that can't be downloaded

How did you simulate that?

@pquentin
Copy link
Member

How did you simulate that?

I removed my ~/.rally/benchmarks/data/http_logs directory.

@j-bennet
Copy link
Contributor Author

Yes, the multiple calls to fetch the git repo is not pretty. This happens because we call git.fetch every time when a RallyRepository is initialized, and that happens when calling bootstrap_actor_system, and this is called multiple times:

  • first call
    actors = actor.bootstrap_actor_system(try_join=already_running, prefer_local_only=not already_running)
  • if failed, fallback to offline actor system
    actors = actor.bootstrap_actor_system(try_join=True)

Not sure where the 3rd call comes from though, and TBH, I don't completely understand the logic with actors. Do you know what is going on there? Seems complicated to me.

Copy link
Member

@pquentin pquentin left a comment

Choose a reason for hiding this comment

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

LGTM! This is great, thanks for iterating. Can you please make sure merging will close the relevant issues? "address" is not a supported verb: https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword

Comment on lines 28 to 37
super().__init__(message, cause)
super().__init__(message)
self.message = message
self.cause = cause

def __repr__(self):
return self.message

def __str__(self):
return self.message

Copy link
Member

@pquentin pquentin Jun 29, 2022

Choose a reason for hiding this comment

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

Wow, this is really cool! This will solve a LOT of issues we had with unprintable exceptions that I never figured out. (I wonder why we're not using cause by the way)

@pquentin
Copy link
Member

(To be clear, I don't think the various git calls are an issue.)

@pquentin pquentin merged commit 8e2f733 into elastic:master Jul 26, 2022
@pquentin pquentin added enhancement Improves the status quo :Usability Makes Rally easier to use labels Jul 26, 2022
@pquentin pquentin added this to the 2.6.1 milestone Jul 26, 2022
@pquentin pquentin added the highlight A substantial improvement that is worth mentioning separately in release notes label Nov 2, 2022
@pquentin pquentin changed the title Remove the check for internet connection. Remove the check for internet connection Nov 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improves the status quo highlight A substantial improvement that is worth mentioning separately in release notes :Usability Makes Rally easier to use
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rally checks for internet connection even when it's not needed
3 participants