Merge "Add pipeline queue stats"

This commit is contained in:
Zuul 2023-08-30 01:28:50 +00:00 committed by Gerrit Code Review
commit 90dce8ed12
4 changed files with 87 additions and 3 deletions

View File

@ -192,6 +192,14 @@ These metrics are emitted by the Zuul :ref:`scheduler`:
The number of items currently being processed by this
pipeline.
.. stat:: window
:type: gauge
The configured window size for the pipeline. Note that this
will not change during operation. This value is used to
initialize each :term:`project queue`, and as changes in that
queue succeed or fail, that queue's window will adjust.
.. stat:: handling
:type: timer
@ -224,6 +232,40 @@ These metrics are emitted by the Zuul :ref:`scheduler`:
state of the pipeline (the decompressed value of
``data_size_compressed``).
.. stat:: queue
This hierarchy holds more specific metrics for each
:term:`project queue` in the pipeline.
.. stat:: <queue name>
The name of the queue. If the queue is automatically
generated for a single project, the name of the project is
used by default. Embedded ``.`` characters will be
translated to ``_``, and ``/`` to ``.``.
.. stat:: current_changes
:type: gauge
The number of items currently in this queue.
.. stat:: window
:type: gauge
The window size for the queue. This will change as
individual changes in the queue succeed or fail.
.. stat:: resident_time
:type: timer
A timer metric reporting how long each item has been in
the queue.
.. stat:: total_changes
:type: counter
The number of changes processed by the queue.
.. stat:: project
This hierarchy holds more specific metrics for each project
@ -283,7 +325,7 @@ These metrics are emitted by the Zuul :ref:`scheduler`:
:type: counter
The number of changes for this project processed by the
pipeline since Zuul started.
pipeline.
.. stat:: read_time
:type: timer
@ -323,8 +365,7 @@ These metrics are emitted by the Zuul :ref:`scheduler`:
.. stat:: total_changes
:type: counter
The number of changes processed by the pipeline since Zuul
started.
The number of changes processed by the pipeline.
.. stat:: trigger_events
:type: gauge

View File

@ -0,0 +1,6 @@
---
features:
- |
Additional pipeline stats for individual project queues are
available at
:stat:`zuul.tenant.<tenant>.pipeline.<pipeline>.queue`.

View File

@ -403,6 +403,19 @@ class TestScheduler(ZuulTestCase):
self.assertReportedStat(
'zuul.tenant.tenant-one.pipeline.gate.current_changes',
value='1', kind='g')
self.assertReportedStat(
'zuul.tenant.tenant-one.pipeline.gate.window',
value='20', kind='g')
self.assertReportedStat(
'zuul.tenant.tenant-one.pipeline.gate.queue.'
'org.project.current_changes',
value='1', kind='g')
self.assertReportedStat(
'zuul.tenant.tenant-one.pipeline.gate.queue.org.project.window',
value='20', kind='g')
self.assertReportedStat(
'zuul.tenant.tenant-one.pipeline.gate.queue.org.project.window',
value='21', kind='g')
self.assertReportedStat(
'zuul.tenant.tenant-one.pipeline.gate.project.review_example_com.'
'org_project.master.job.project-merge.SUCCESS', kind='ms')
@ -415,6 +428,13 @@ class TestScheduler(ZuulTestCase):
self.assertReportedStat(
'zuul.tenant.tenant-one.pipeline.gate.total_changes', value='1',
kind='c')
self.assertReportedStat(
'zuul.tenant.tenant-one.pipeline.gate.queue.'
'org.project.resident_time', kind='ms')
self.assertReportedStat(
'zuul.tenant.tenant-one.pipeline.gate.queue.'
'org.project.total_changes', value='1',
kind='c')
self.assertReportedStat(
'zuul.tenant.tenant-one.pipeline.gate.trigger_events',
value='0', kind='g')

View File

@ -2272,10 +2272,27 @@ class PipelineManager(metaclass=ABCMeta):
# stats.timers.zuul.tenant.<tenant>.pipeline.<pipeline>.resident_time
# stats_counts.zuul.tenant.<tenant>.pipeline.<pipeline>.total_changes
# stats.gauges.zuul.tenant.<tenant>.pipeline.<pipeline>.current_changes
# stats.gauges.zuul.tenant.<tenant>.pipeline.<pipeline>.window
self.sched.statsd.gauge(key + '.current_changes', items)
self.sched.statsd.gauge(key + '.window', item.pipeline.window)
if dt:
self.sched.statsd.timing(key + '.resident_time', dt)
self.sched.statsd.incr(key + '.total_changes')
if item.queue and item.queue.name:
queuename = (item.queue.name.
replace('.', '_').replace('/', '.'))
# stats.gauges.zuul.tenant.<tenant>.pipeline.<pipeline>.queue.<queue>.resident_time
# stats.gauges.zuul.tenant.<tenant>.pipeline.<pipeline>.queue.<queue>.total_changes
# stats.gauges.zuul.tenant.<tenant>.pipeline.<pipeline>.queue.<queue>.current_changes
# stats.gauges.zuul.tenant.<tenant>.pipeline.<pipeline>.queue.<queue>.window
queuekey = '%s.queue.%s' % (key, queuename)
self.sched.statsd.gauge(queuekey + '.current_changes',
len(item.queue.queue))
self.sched.statsd.gauge(queuekey + '.window',
item.queue.window)
if dt:
self.sched.statsd.timing(queuekey + '.resident_time', dt)
self.sched.statsd.incr(queuekey + '.total_changes')
if hasattr(item.change, 'branch'):
hostname = (item.change.project.canonical_hostname.
replace('.', '_'))