Skip to content

Refactor monitoring bus into a singleton

Rohit Kothur requested to merge rkothur/monitoring-singleton into master

Description

Move the monitoring bus into a singleton object. This should make adding metrics to other parts of the code much easier (no longer need to pass the bus object around).

Submitting a metric is now as simple as:

from buildgrid.server.monitoring import get_monitoring_bus

record = <make a monitoring bus record>
monitoring_bus = get_monitoring_bus()
monitoring_bus.send_record_nowait(record)

and it can be called from anywhere. You can call the send_record and send_record_nowait methods whether monitoring is enabled or not, and the bus handles the decision of whether to publish or not on its own. This also adds an is_enabled property to the monitoring bus so you can manually test before publishing if you want to.

Note that this will conflict with !384 (merged) and any other changes that add metrics.

Issues addressed

Closes #264 (closed)

Edited by Rohit Kothur

Merge request reports