summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Schubert <contact@benschubert.me>2019-10-04 14:12:58 +0100
committerBenjamin Schubert <contact@benschubert.me>2019-10-07 09:28:38 +0100
commit5a24e25f5639a192b699632e8f3782daf29a5e67 (patch)
treeb26a6888fa60874b652824f5609fe2f2b6b4386b
parenta57f27e396f9c19bd553687e8ae85b3b0d01e6e0 (diff)
downloadbuildstream-bschubert/propagate-log-level-to-casd.tar.gz
cascache.py: add a 'log_level' parameter and use it to run buildbox-casdbschubert/propagate-log-level-to-casd
This changes how we instantiate the CASCache by reusing the log level parameters from BuildStream and forward them to buildbox-casd. By default, buildbox-casd will now have '--log-level warning', and --verbose will enable 'info' and --debug will enable 'trace'. This way, we can easily tweak buildbox-casd's verbosity
-rw-r--r--src/buildstream/_cas/__init__.py2
-rw-r--r--src/buildstream/_cas/cascache.py13
-rw-r--r--src/buildstream/_context.py12
3 files changed, 23 insertions, 4 deletions
diff --git a/src/buildstream/_cas/__init__.py b/src/buildstream/_cas/__init__.py
index 17e3a3fd9..3661543cf 100644
--- a/src/buildstream/_cas/__init__.py
+++ b/src/buildstream/_cas/__init__.py
@@ -17,5 +17,5 @@
# Authors:
# Tristan Van Berkom <tristan.vanberkom@codethink.co.uk>
-from .cascache import CASCache
+from .cascache import CASCache, LogLevel
from .casremote import CASRemote
diff --git a/src/buildstream/_cas/cascache.py b/src/buildstream/_cas/cascache.py
index a62bc3d44..db77521f7 100644
--- a/src/buildstream/_cas/cascache.py
+++ b/src/buildstream/_cas/cascache.py
@@ -38,6 +38,7 @@ from .._protos.build.bazel.remote.execution.v2 import remote_execution_pb2, remo
from .._protos.build.buildgrid import local_cas_pb2, local_cas_pb2_grpc
from .. import _signals, utils
+from ..types import FastEnum
from .._exceptions import CASCacheError
from .._message import Message, MessageType
@@ -52,6 +53,12 @@ _CACHE_USAGE_REFRESH = 5
_CASD_MAX_LOGFILES = 10
+class LogLevel(FastEnum):
+ WARNING = "warning"
+ INFO = "info"
+ TRACE = "trace"
+
+
# A CASCache manages a CAS repository as specified in the Remote Execution API.
#
# Args:
@@ -59,10 +66,13 @@ _CASD_MAX_LOGFILES = 10
# casd (bool): True to spawn buildbox-casd (default) or False (testing only)
# cache_quota (int): User configured cache quota
# protect_session_blobs (bool): Disable expiry for blobs used in the current session
+# log_level (LogLevel): Log level to give to buildbox-casd for logging
#
class CASCache():
- def __init__(self, path, *, casd=True, cache_quota=None, protect_session_blobs=True):
+ def __init__(
+ self, path, *, casd=True, cache_quota=None, protect_session_blobs=True, log_level=LogLevel.WARNING
+ ):
self.casdir = os.path.join(path, 'cas')
self.tmpdir = os.path.join(path, 'tmp')
os.makedirs(os.path.join(self.casdir, 'refs', 'heads'), exist_ok=True)
@@ -77,6 +87,7 @@ class CASCache():
casd_args = [utils.get_host_tool('buildbox-casd')]
casd_args.append('--bind=unix:' + self._casd_socket_path)
+ casd_args.append('--log-level=' + log_level.value)
if cache_quota is not None:
casd_args.append('--quota-high={}'.format(int(cache_quota)))
diff --git a/src/buildstream/_context.py b/src/buildstream/_context.py
index 52dcfbdcd..179c9ad9c 100644
--- a/src/buildstream/_context.py
+++ b/src/buildstream/_context.py
@@ -28,7 +28,7 @@ from ._profile import Topics, PROFILER
from ._platform import Platform
from ._artifactcache import ArtifactCache
from ._sourcecache import SourceCache
-from ._cas import CASCache
+from ._cas import CASCache, LogLevel
from .types import _CacheBuildTrees, _SchedulerErrorAction
from ._workspaces import Workspaces, WorkspaceProjectCache
from .node import Node
@@ -513,9 +513,17 @@ class Context():
def get_cascache(self):
if self._cascache is None:
+ if self.log_debug:
+ log_level = LogLevel.TRACE
+ elif self.log_verbose:
+ log_level = LogLevel.INFO
+ else:
+ log_level = LogLevel.WARNING
+
self._cascache = CASCache(self.cachedir,
casd=self.use_casd,
- cache_quota=self.config_cache_quota)
+ cache_quota=self.config_cache_quota,
+ log_level=log_level)
return self._cascache
# is_fork_allowed():