... |
... |
@@ -25,6 +25,7 @@ from buildgrid.server.actioncache.service import ActionCacheService |
25
|
25
|
from buildgrid.server.bots.service import BotsService
|
26
|
26
|
from buildgrid.server.cas.service import ByteStreamService, ContentAddressableStorageService
|
27
|
27
|
from buildgrid.server.execution.service import ExecutionService
|
|
28
|
+from buildgrid.server._monitoring import MonitoringBus
|
28
|
29
|
from buildgrid.server.operations.service import OperationsService
|
29
|
30
|
from buildgrid.server.referencestorage.service import ReferenceStorageService
|
30
|
31
|
|
... |
... |
@@ -36,7 +37,7 @@ class BuildGridServer: |
36
|
37
|
requisite services.
|
37
|
38
|
"""
|
38
|
39
|
|
39
|
|
- def __init__(self, max_workers=None):
|
|
40
|
+ def __init__(self, max_workers=None, monitor=True):
|
40
|
41
|
"""Initializes a new :class:`BuildGridServer` instance.
|
41
|
42
|
|
42
|
43
|
Args:
|
... |
... |
@@ -52,6 +53,7 @@ class BuildGridServer: |
52
|
53
|
self.__grpc_server = grpc.server(self.__grpc_executor)
|
53
|
54
|
|
54
|
55
|
self.__main_loop = asyncio.get_event_loop()
|
|
56
|
+ self.__monitoring_bus = None
|
55
|
57
|
|
56
|
58
|
self._execution_service = None
|
57
|
59
|
self._bots_service = None
|
... |
... |
@@ -61,10 +63,20 @@ class BuildGridServer: |
61
|
63
|
self._cas_service = None
|
62
|
64
|
self._bytestream_service = None
|
63
|
65
|
|
|
66
|
+ self._is_instrumented = monitor
|
|
67
|
+
|
|
68
|
+ if self._is_instrumented:
|
|
69
|
+ self.__monitoring_bus = MonitoringBus(self.__main_loop)
|
|
70
|
+
|
|
71
|
+ # --- Public API ---
|
|
72
|
+
|
64
|
73
|
def start(self):
|
65
|
74
|
"""Starts the BuildGrid server.
|
66
|
75
|
"""
|
67
|
76
|
self.__grpc_server.start()
|
|
77
|
+
|
|
78
|
+ if self._is_instrumented:
|
|
79
|
+ self.__monitoring_bus.start()
|
68
|
80
|
self.__main_loop.run_forever()
|
69
|
81
|
|
70
|
82
|
def stop(self, grace=0):
|
... |
... |
@@ -73,7 +85,8 @@ class BuildGridServer: |
73
|
85
|
Args:
|
74
|
86
|
grace (int, optional): A duration of time in seconds. Defaults to 0.
|
75
|
87
|
"""
|
76
|
|
- self.__main_loop.close()
|
|
88
|
+ if self._is_instrumented:
|
|
89
|
+ self.__monitoring_bus.stop()
|
77
|
90
|
|
78
|
91
|
self.__grpc_server.stop(grace)
|
79
|
92
|
|
... |
... |
@@ -195,3 +208,9 @@ class BuildGridServer: |
195
|
208
|
self._bytestream_service = ByteStreamService(self.__grpc_server)
|
196
|
209
|
|
197
|
210
|
self._bytestream_service.add_instance(instance_name, instance)
|
|
211
|
+
|
|
212
|
+ # --- Public API: Monitoring ---
|
|
213
|
+
|
|
214
|
+ @property
|
|
215
|
+ def is_instrumented(self):
|
|
216
|
+ return self._is_instrumented
|