Page MenuHomeSoftware Heritage
Paste P1260

(An Untitled Masterwork)
ActivePublic

Authored by douardda on Jan 20 2022, 1:46 PM.
class Statsd:
# ...
@contextmanager
def status_gauge(self, metric_name: str, statuses: Collection[str], common_tags: Optional[Dict[str, str]] = None):
current_status = Optional[str] = None
for status in statuses:
self.gauge(metric_name, 0, {**common_tags, "status": status})
def set(new_status: str):
if new_status not in statuses:
raise ValueError(f'{new_status} not in {statuses}')
if current_status:
self.gauge(metric_name, 0, {**common_tags, "status": current_status})
current_status = new_status
self.gauge(metric_name, 1, {**common_tags, "status": current_status})
yield set
for status in statuses:
self.gauge(metric_name, 0, {**common_tags, "status": status})