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

Explicit offline mode #1503

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions esrally/rally.py
Original file line number Diff line number Diff line change
Expand Up @@ -1057,10 +1057,9 @@ def main():
if not args.offline:
probing_url = cfg.opts("system", "probing.url", default_value="https://github.com", mandatory=False)
if not net.has_internet_connection(probing_url):
console.warn("No Internet connection detected. Automatic download of track data sets etc. is disabled.", logger=logger)
cfg.add(config.Scope.applicationOverride, "system", "offline.mode", True)
else:
logger.info("Detected a working Internet connection.")
console.warn("No Internet connection detected. Specify --offline to run without it.", logger=logger)
sys.exit(0)
logger.info("Detected a working Internet connection.")

result = dispatch_sub_command(arg_parser, args, cfg)

Expand Down
9 changes: 7 additions & 2 deletions esrally/utils/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,16 @@ def run_subprocess(command_line):
return os.system(command_line)


def run_subprocess_with_output(command_line):
def run_subprocess_with_output(command_line, env_vars=None):
logger = logging.getLogger(__name__)
logger.debug("Running subprocess [%s] with output.", command_line)
command_line_args = shlex.split(command_line)
with subprocess.Popen(command_line_args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) as command_line_process:
kwargs = {}
if env_vars:
cmd_env = os.environ.copy()
cmd_env.update(env_vars)
kwargs["env"] = cmd_env
with subprocess.Popen(command_line_args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, **kwargs) as command_line_process:
j-bennet marked this conversation as resolved.
Show resolved Hide resolved
has_output = True
lines = []
while has_output:
Expand Down
2 changes: 1 addition & 1 deletion it/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def __str__(self):


class EsMetricsStore:
VERSION = "7.6.0"
VERSION = os.getenv("it_es_version", "7.6.0")
j-bennet marked this conversation as resolved.
Show resolved Hide resolved

def __init__(self):
self.cluster = TestCluster("in-memory-it")
Expand Down
8 changes: 8 additions & 0 deletions it/basic_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,11 @@ def test_run_with_help(cfg):
output = process.run_subprocess_with_output(cmd)
expected = "usage: esrally [-h] [--version]"
assert expected in "\n".join(output)


@it.rally_in_mem
def test_run_without_http_connection(cfg):
cmd = it.esrally_command_line_for(cfg, "list races")
Copy link
Member

Choose a reason for hiding this comment

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

What the... I had no idea we sent a request to GitHub for every single invocation, even when just listing races. This makes esrally list races 1.4s slower for me!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would be a nice thing to fix, probably in a separate PR, don't you think? I'm sure lots of commands don't need Rally to be online.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Opened an issue so it's not forgotten: #1506.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for opening that issue!

output = process.run_subprocess_with_output(cmd, {"http_proxy": "http://non-existent-proxy-server.com"})
j-bennet marked this conversation as resolved.
Show resolved Hide resolved
expected = "No Internet connection detected. Specify --offline"
assert expected in "\n".join(output)
2 changes: 1 addition & 1 deletion it/proxy_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def test_anonymous_proxy_no_connection(cfg, http_proxy, fresh_log_file):
assert process.run_subprocess_with_logging(it.esrally_command_line_for(cfg, "list tracks"), env=env) == 0
assert_log_line_present(fresh_log_file, f"Connecting via proxy URL [{http_proxy.anonymous_url}] to the Internet")
# unauthenticated proxy access is prevented
assert_log_line_present(fresh_log_file, "No Internet connection detected")
assert_log_line_present(fresh_log_file, "No Internet connection detected. Specify --offline")


@it.rally_in_mem
Expand Down