scheduler: add statsd metric for enqueue time

This change adds a new metric to measure trigger event enqueue time.

Change-Id: I453ff6dfe479a48a32f4f581f5d07f4ee6b4d804
This commit is contained in:
Tristan Cacqueray 2021-02-17 22:33:02 +00:00
parent f87da65a88
commit a9545a49dd
3 changed files with 13 additions and 2 deletions

View File

@ -113,6 +113,12 @@ These metrics are emitted by the Zuul :ref:`scheduler`:
The number of changes for this project processed by the
pipeline since Zuul started.
.. stat:: euqueue_time
:type: timer
A timer metric reporting how long a trigger event takes
to be enqueued in a pipeline.
.. stat:: resident_time
:type: timer

View File

@ -12,6 +12,7 @@
import logging
import textwrap
import time
import urllib
from abc import ABCMeta
@ -371,7 +372,7 @@ class PipelineManager(metaclass=ABCMeta):
if enqueue_time:
item.enqueue_time = enqueue_time
item.live = live
self.reportStats(item)
self.reportStats(item, added=True)
item.quiet = quiet
if item.live and not item.reported_enqueue:
self.reportEnqueue(item)
@ -1205,7 +1206,7 @@ class PipelineManager(metaclass=ABCMeta):
log.error("Reporting item %s received: %s", item, ret)
return ret
def reportStats(self, item):
def reportStats(self, item, added=False):
if not self.sched.statsd:
return
try:
@ -1244,5 +1245,8 @@ class PipelineManager(metaclass=ABCMeta):
if dt:
self.sched.statsd.timing(key + '.resident_time', dt)
self.sched.statsd.incr(key + '.total_changes')
if added and hasattr(item.event, 'trigger_timestamp'):
elapsed = time.monotonic() - item.event.trigger_timestamp
self.sched.statsd.timing(key + '.enqueue_time', elapsed)
except Exception:
self.log.exception("Exception reporting pipeline stats")

View File

@ -486,6 +486,7 @@ class Scheduler(threading.Thread):
)
def _addTriggerEvent(self, event):
event.trigger_timestamp = time.monotonic()
self.trigger_event_queue.put(event)
self.wake_event.set()