... |
... |
@@ -71,7 +71,10 @@ class BuildGridServer: |
71
|
71
|
self.__logging_formatter = logging.Formatter(fmt=LOG_RECORD_FORMAT)
|
72
|
72
|
self.__print_log_records = True
|
73
|
73
|
|
|
74
|
+ self.__build_metadata_queues = None
|
|
75
|
+
|
74
|
76
|
self.__state_monitoring_task = None
|
|
77
|
+ self.__build_monitoring_tasks = None
|
75
|
78
|
self.__logging_task = None
|
76
|
79
|
|
77
|
80
|
# We always want a capabilities service
|
... |
... |
@@ -95,6 +98,8 @@ class BuildGridServer: |
95
|
98
|
self.__main_loop, endpoint_type=MonitoringOutputType.STDOUT,
|
96
|
99
|
serialisation_format=MonitoringOutputFormat.JSON)
|
97
|
100
|
|
|
101
|
+ self.__build_monitoring_tasks = []
|
|
102
|
+
|
98
|
103
|
# Setup the main logging handler:
|
99
|
104
|
root_logger = logging.getLogger()
|
100
|
105
|
|
... |
... |
@@ -119,6 +124,18 @@ class BuildGridServer: |
119
|
124
|
self._state_monitoring_worker(period=MONITORING_PERIOD),
|
120
|
125
|
loop=self.__main_loop)
|
121
|
126
|
|
|
127
|
+ self.__build_monitoring_tasks.clear()
|
|
128
|
+ for instance_name, scheduler in self._schedulers.items():
|
|
129
|
+ if not scheduler.is_instrumented:
|
|
130
|
+ continue
|
|
131
|
+
|
|
132
|
+ message_queue = janus.Queue(loop=self.__main_loop)
|
|
133
|
+ scheduler.register_build_metadata_watcher(message_queue.sync_q)
|
|
134
|
+
|
|
135
|
+ self.__build_monitoring_tasks.append(asyncio.ensure_future(
|
|
136
|
+ self._build_monitoring_worker(instance_name, message_queue),
|
|
137
|
+ loop=self.__main_loop))
|
|
138
|
+
|
122
|
139
|
self.__logging_task = asyncio.ensure_future(
|
123
|
140
|
self._logging_worker(), loop=self.__main_loop)
|
124
|
141
|
|
... |
... |
@@ -132,6 +149,10 @@ class BuildGridServer: |
132
|
149
|
if self.__state_monitoring_task is not None:
|
133
|
150
|
self.__state_monitoring_task.cancel()
|
134
|
151
|
|
|
152
|
+ for build_monitoring_task in self.__build_monitoring_tasks:
|
|
153
|
+ build_monitoring_task.cancel()
|
|
154
|
+ self.__build_monitoring_tasks.clear()
|
|
155
|
+
|
135
|
156
|
self.__monitoring_bus.stop()
|
136
|
157
|
|
137
|
158
|
if self.__logging_task is not None:
|
... |
... |
@@ -352,6 +373,58 @@ class BuildGridServer: |
352
|
373
|
|
353
|
374
|
return log_record
|
354
|
375
|
|
|
376
|
+ async def _build_monitoring_worker(self, instance_name, message_queue):
|
|
377
|
+ """Publishes builds metadata to the monitoring bus."""
|
|
378
|
+ async def __build_monitoring_worker():
|
|
379
|
+ metadata = await message_queue.async_q.get()
|
|
380
|
+
|
|
381
|
+ # Emit build inputs fetching time record:
|
|
382
|
+ fetch_start = metadata.input_fetch_start_timestamp.ToDatetime()
|
|
383
|
+ fetch_completed = metadata.input_fetch_completed_timestamp.ToDatetime()
|
|
384
|
+ input_fetch_time = fetch_completed - fetch_start
|
|
385
|
+ timer_record = self._forge_timer_metric_record(
|
|
386
|
+ MetricRecordDomain.BUILD, 'inputs-fetching-time', input_fetch_time,
|
|
387
|
+ metadata={'instance-name': instance_name or 'void'})
|
|
388
|
+
|
|
389
|
+ await self.__monitoring_bus.send_record(timer_record)
|
|
390
|
+
|
|
391
|
+ # Emit build execution time record:
|
|
392
|
+ execution_start = metadata.execution_start_timestamp.ToDatetime()
|
|
393
|
+ execution_completed = metadata.execution_completed_timestamp.ToDatetime()
|
|
394
|
+ execution_time = execution_completed - execution_start
|
|
395
|
+ timer_record = self._forge_timer_metric_record(
|
|
396
|
+ MetricRecordDomain.BUILD, 'execution-time', execution_time,
|
|
397
|
+ metadata={'instance-name': instance_name or 'void'})
|
|
398
|
+
|
|
399
|
+ await self.__monitoring_bus.send_record(timer_record)
|
|
400
|
+
|
|
401
|
+ # Emit build outputs uploading time record:
|
|
402
|
+ upload_start = metadata.output_upload_start_timestamp.ToDatetime()
|
|
403
|
+ upload_completed = metadata.output_upload_completed_timestamp.ToDatetime()
|
|
404
|
+ output_upload_time = upload_completed - upload_start
|
|
405
|
+ timer_record = self._forge_timer_metric_record(
|
|
406
|
+ MetricRecordDomain.BUILD, 'outputs-uploading-time', output_upload_time,
|
|
407
|
+ metadata={'instance-name': instance_name or 'void'})
|
|
408
|
+
|
|
409
|
+ await self.__monitoring_bus.send_record(timer_record)
|
|
410
|
+
|
|
411
|
+ # Emit total build handling time record:
|
|
412
|
+ queued = metadata.queued_timestamp.ToDatetime()
|
|
413
|
+ worker_completed = metadata.worker_completed_timestamp.ToDatetime()
|
|
414
|
+ total_handling_time = worker_completed - queued
|
|
415
|
+ timer_record = self._forge_timer_metric_record(
|
|
416
|
+ MetricRecordDomain.BUILD, 'total-handling-time', total_handling_time,
|
|
417
|
+ metadata={'instance-name': instance_name or 'void'})
|
|
418
|
+
|
|
419
|
+ await self.__monitoring_bus.send_record(timer_record)
|
|
420
|
+
|
|
421
|
+ try:
|
|
422
|
+ while True:
|
|
423
|
+ await __build_monitoring_worker()
|
|
424
|
+
|
|
425
|
+ except asyncio.CancelledError:
|
|
426
|
+ pass
|
|
427
|
+
|
355
|
428
|
async def _state_monitoring_worker(self, period=1.0):
|
356
|
429
|
"""Periodically publishes state metrics to the monitoring bus."""
|
357
|
430
|
async def __state_monitoring_worker():
|