Emit per-branch queue stats separately

We currently emit 4 statsd metrics for each shared queue, but in
the case that a queue is configured as per-branch, we disregard
the branch and emit the stats under the same hierarchy for any
branch of that queue.  This means that if we have a queue for
integrated-master and a queue for integrated-stable at the same
time, we would emit the stats for the master queue, then
immediately emit the same stats for the stable queue, overwriting
the master stats.

To correct this, move the metrics down a level in the case that
the queue is configured per-branch, and include the branch name
in the key.

Change-Id: I2f4b22394bc3774410a02ae76281eddf080e5c7f
This commit is contained in:
James E. Blair
2024-02-28 13:51:04 -08:00
parent 617bbb229c
commit 794545fc64
4 changed files with 66 additions and 2 deletions

View File

@@ -2269,7 +2269,23 @@ class PipelineManager(metaclass=ABCMeta):
# 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)
queuekey = f'{key}.queue.{queuename}'
# Handle per-branch queues
layout = self.pipeline.tenant.layout
queue_config = layout.queues.get(item.queue.name)
per_branch = queue_config and queue_config.per_branch
if per_branch and item.queue.project_branches:
# Get the first project-branch of this queue,
# which is a tuple of project, branch, and get
# second item of that tuple, the branch name. In
# a per-branch queue, we expect the branch name to
# be the same for every project.
branch = item.queue.project_branches[0][1]
if branch:
branch = branch.replace('.', '_').replace('/', '.')
queuekey = f'{queuekey}.branch.{branch}'
queue_changes = sum(len(i.changes) for i in item.queue.queue)
self.sched.statsd.gauge(queuekey + '.current_changes',
queue_changes)