Skip to content

Commit

Permalink
Use config.json to enable Isolated gRPC proxy
Browse files Browse the repository at this point in the history
The values in config.json are not set yet and will be added in a future
change.

BUG=

Review-Url: https://codereview.chromium.org/2969463002
  • Loading branch information
adrianludwin authored and Commit Bot committed Jun 29, 2017
1 parent 18a465a commit 33233c3
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 24 deletions.
11 changes: 10 additions & 1 deletion appengine/swarming/swarming_bot/bot_code/bot_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,14 +575,23 @@ def _run_isolated_flags(botobj):
min_free = (
_min_free_disk({'size_mb': size}, partition) +
partition['wiggle'])
return [
args = [
'--cache', os.path.join(botobj.base_dir, 'isolated_cache'),
'--min-free-space', str(min_free),
'--named-cache-root', os.path.join(botobj.base_dir, 'c'),
'--max-cache-size', str(settings['caches']['isolated']['size']),
'--max-items', str(settings['caches']['isolated']['items']),
]

# Get the gRPC proxy from the config, but allow an environment variable to
# override.
grpc_proxy = get_config().get('isolate_grpc_proxy')
grpc_proxy = os.environ.get('ISOLATE_GRPC_PROXY', grpc_proxy)
if grpc_proxy is not None:
logging.info('Isolate will use gRPC proxy %s', grpc_proxy)
args.extend(['--grpc-proxy', grpc_proxy])
return args


def _clean_cache(botobj):
"""Asks run_isolated to clean its cache.
Expand Down
29 changes: 14 additions & 15 deletions client/isolate_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@
DOWNLOAD_READ_TIMEOUT = 60


# A class to use to communicate with the server by default. Can be changed by
# 'set_storage_api_class'. Default is IsolateServer.
_storage_api_cls = None
# Stores the gRPC proxy address. Must be set if the storage API class is
# IsolateServerGrpc (call 'set_grpc_proxy').
_grpc_proxy = None


class Item(object):
Expand Down Expand Up @@ -527,7 +527,7 @@ class IsolateServerGrpc(StorageApi):
while fetching.
"""

def __init__(self, server, namespace):
def __init__(self, server, namespace, proxy):
super(IsolateServerGrpc, self).__init__()
logging.info('Using gRPC for Isolate')
self._server = server
Expand All @@ -545,9 +545,8 @@ def __init__(self, server, namespace):
assert grpc
assert bytestream_pb2

proxy = os.environ.get('ISOLATED_GRPC_PROXY', '')
roots = os.environ.get('ISOLATED_GRPC_PROXY_TLS_ROOTS')
overd = os.environ.get('ISOLATED_GRPC_PROXY_TLS_OVERRIDE')
roots = os.environ.get('ISOLATE_GRPC_PROXY_TLS_ROOTS')
overd = os.environ.get('ISOLATE_GRPC_PROXY_TLS_OVERRIDE')

# The "proxy" envvar must be of the form:
# http[s]://<server>[:port][/prefix]
Expand Down Expand Up @@ -700,12 +699,11 @@ def contains(self, items):
return missing_items


def set_storage_api_class(cls):
"""Replaces StorageApi implementation used by default."""
global _storage_api_cls
assert _storage_api_cls is None
assert issubclass(cls, StorageApi)
_storage_api_cls = cls
def set_grpc_proxy(proxy):
"""Sets the StorageApi to use the specified proxy."""
global _grpc_proxy
assert _grpc_proxy is None
_grpc_proxy = proxy


def get_storage_api(url, namespace):
Expand All @@ -724,5 +722,6 @@ def get_storage_api(url, namespace):
Returns:
Instance of StorageApi subclass.
"""
cls = _storage_api_cls or IsolateServer
return cls(url, namespace)
if _grpc_proxy is not None:
return IsolateServerGrpc(url, namespace, _grpc_proxy)
return IsolateServer(url, namespace)
9 changes: 3 additions & 6 deletions client/isolateserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -1949,7 +1949,7 @@ def add_isolate_server_options(parser):
'variable ISOLATE_SERVER if set. No need to specify https://, this '
'is assumed.')
parser.add_option(
'--is-grpc', action='store_true', help='Communicate to Isolate via gRPC')
'--grpc-proxy', help='gRPC proxy by which to communicate to Isolate')
parser.add_option(
'--namespace', default='default-gzip',
help='The namespace to use on the Isolate Server, default: %default')
Expand All @@ -1966,11 +1966,8 @@ def process_isolate_server_options(
parser.error('--isolate-server is required.')
return

if 'ISOLATED_GRPC_PROXY' in os.environ:
options.is_grpc = True

if options.is_grpc:
isolate_storage.set_storage_api_class(isolate_storage.IsolateServerGrpc)
if options.grpc_proxy:
isolate_storage.set_grpc_proxy(options.grpc_proxy)
else:
try:
options.isolate_server = net.fix_url(options.isolate_server)
Expand Down
4 changes: 2 additions & 2 deletions client/tests/isolate_storage_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ def raiseError(code):

class IsolateStorageTest(auto_stub.TestCase):
def get_server(self):
os.environ['ISOLATED_GRPC_PROXY'] = 'https://luci.com/client/bob'
return isolate_storage.IsolateServerGrpc('https://luci.appspot.com',
'default-gzip')
'default-gzip',
'https://luci.com/client/bob')

def testFetchHappySimple(self):
"""Fetch: if we get a few chunks with the right offset, everything works"""
Expand Down

0 comments on commit 33233c3

Please sign in to comment.